Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module LED(
- input clk_50,
- input [6:0]id, //id of the color received
- input [1:0]reset,
- output R1,
- output G1,
- output B1,
- output R2,
- output G2,
- output B2,
- output R3,
- output G3,
- output B3
- );reg [8:0]rgb = 9'b000000000; //rgb value is stored together in this variable(3 bits each)
- reg clk_1=0; //for 2.5 MHz cll
- reg [1:0]count=0; //Count for color case
- reg [20:0]sec=0;
- reg [4:0]C_COUNT=0;
- reg flag = 0; //Is enabled when to detect color
- always @(posedge clk_50)begin //Converts 50 MHz clk to 1 MHz
- if(reset==2'b01)
- begin
- clk_1<=0;
- C_COUNT<=0;
- end
- if(C_COUNT == 49)begin
- C_COUNT <= 1;
- end else begin
- C_COUNT <= C_COUNT + 1;
- end
- clk_1 <= (C_COUNT > 10);
- end
- always @(posedge clk_1)
- begin
- if(reset==2'b01)
- begin
- rgb <= 9'b000000000; //Variable storing rgb vlaue is reset
- count <= 0;
- flag <= 0;
- end
- if(id == 0)
- begin
- flag <= 1; //flag resets to 1, to detect color only once
- end
- if((id == 1) && (flag == 1)) //if id 1, red color is stored in rgb variable
- begin
- rgb[3*count+2] <= 1;
- rgb[3*count+1] <= 0;
- rgb[3*count+0] <= 0;
- count <= count + 1;
- flag <= 0;
- end
- else if((id == 2) && (flag == 1)) //if id 2, green color is stored in rgb variable
- begin
- rgb[3*count+2] <= 0;
- rgb[3*count+1] <= 1;
- rgb[3*count+0] <= 0;
- count <= count + 1;
- flag <= 0;
- end
- else if((id == 3) && (flag == 1)) //if id 3, blue color is stored in rgb variable
- begin
- rgb[3*count+2] <= 0;
- rgb[3*count+1] <= 0;
- rgb[3*count+0] <= 1;
- count <= count + 1;
- flag <= 0;
- end
- if(reset == 2'b11)
- begin
- sec <= sec+1;
- if(sec < 1000000)
- begin
- rgb <= 9'b111111111;
- end else begin
- rgb <= 9'b0;
- end
- end
- end
- assign R3 = rgb[8];
- assign G3 = rgb[7];
- assign B3 = rgb[6];
- assign R2 = rgb[5];
- assign G2 = rgb[4];
- assign B2 = rgb[3];
- assign R1 = rgb[2];
- assign G1 = rgb[1];
- assign B1 = rgb[0];
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement