Advertisement
Sidsh

LED Documented (sec*) 2.0

Mar 3rd, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /*
  2.  
  3. *Team Id: SM#2349
  4. *Author List: (Premraj,Siddesh,Viraj,Siddharth)
  5. *Filename: LED
  6. *Theme: Soil Monitoring Bot
  7. *Input: (clk_50, id, reset)
  8. *Output: (R1, G1, B1, R2, G2, B2, R3, G3, B3)
  9.  
  10. */
  11.  
  12.  
  13. module LED(
  14. input clk_50,
  15. input [6:0]id, //id of the color received
  16. input [1:0]reset, //reset so that one color doesn't get detected multiple times
  17. output R1, //Output variables for each LED
  18. output G1,
  19. output B1,
  20. output R2,
  21. output G2,
  22. output B2,
  23. output R3,
  24. output G3,
  25. output B3
  26. );reg [8:0]rgb = 9'b000000000; //rgb value is stored together in this variable(3 bits each)
  27. reg clk_1=0; //for 2.5 MHz cll
  28. reg [1:0]count=0; //Count for color case
  29. reg [20:0]sec=0;
  30. reg [4:0]C_COUNT=0;
  31. reg flag = 0; //Is enabled when to detect color
  32.  
  33. always @(posedge clk_50)begin //Converts 50 MHz clk to 1 MHz
  34. if(reset==2'b01)
  35. begin
  36. clk_1<=0;
  37. C_COUNT<=0;
  38. end
  39. if(C_COUNT == 49)begin
  40. C_COUNT <= 1;
  41. end else begin
  42. C_COUNT <= C_COUNT + 1;
  43. end
  44. clk_1 <= (C_COUNT > 10);
  45. end
  46.  
  47.  
  48. always @(posedge clk_1)
  49. begin
  50. if(reset==2'b01)
  51. begin
  52. rgb <= 9'b000000000; //Variable storing rgb vlaue is reset
  53. count <= 0;
  54. flag <= 0;
  55. end
  56. if(id == 0)
  57. begin
  58. flag <= 1; //flag resets to 1, to detect color only once
  59. end
  60. if((id == 1) && (flag == 1)) //if id 1, red color is stored in rgb variable
  61. begin
  62. rgb[3*count+2] <= 1;
  63. rgb[3*count+1] <= 0;
  64. rgb[3*count+0] <= 0;
  65. count <= count + 1;
  66. flag <= 0;
  67. end
  68. else if((id == 2) && (flag == 1)) //if id 2, green color is stored in rgb variable
  69. begin
  70. rgb[3*count+2] <= 0;
  71. rgb[3*count+1] <= 1;
  72. rgb[3*count+0] <= 0;
  73. count <= count + 1;
  74. flag <= 0;
  75. end
  76. else if((id == 3) && (flag == 1)) //if id 3, blue color is stored in rgb variable
  77. begin
  78. rgb[3*count+2] <= 0;
  79. rgb[3*count+1] <= 0;
  80. rgb[3*count+0] <= 1;
  81. count <= count + 1;
  82. flag <= 0;
  83. end
  84.  
  85. if(reset == 2'b11)
  86. begin
  87. sec <= sec+1;
  88.  
  89. if(sec < 1000000)
  90. begin
  91. rgb <= 9'b111111111;
  92. end else begin
  93. rgb <= 9'b0;
  94. end
  95. end
  96. end
  97.  
  98. assign R3 = rgb[8]; //Assigning Output Variables
  99. assign G3 = rgb[7];
  100. assign B3 = rgb[6];
  101. assign R2 = rgb[5];
  102. assign G2 = rgb[4];
  103. assign B2 = rgb[3];
  104. assign R1 = rgb[2];
  105. assign G1 = rgb[1];
  106. assign B1 = rgb[0];
  107.  
  108.  
  109. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement