Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. /*
  2. All required functionality for Lab 1 except some of the oscilloscope (in main file)
  3.  
  4. */
  5.  
  6.  
  7. //Frequency dividor
  8. module Generate_Custom_Clock (clk, divid, out_clk);
  9.  
  10. input clk;
  11. input [31:0] divid;
  12. output reg out_clk;
  13. reg [49:0] counter; //to make sure there is enough space for any clock division, 50 may be an overkill lel
  14.  
  15. always_ff @(posedge clk) begin
  16.  
  17. if(counter >= divid) begin //if we just have == condition then if divid switches from higher value to low, we get stuck
  18. out_clk <= ~out_clk;
  19. counter <= 1;
  20. end
  21. else begin
  22. counter <= counter + 1;
  23. end
  24. end
  25. endmodule
  26.  
  27.  
  28.  
  29.  
  30.  
  31. //LED cycling
  32. //We toggle LED cycling mode when we SW4 is hot and SW3,2,1 are off
  33. //To reset we press and release KEY3
  34. module LED_cycle(clk, switches, LED, rst);
  35. input clk;
  36. input [3:0] switches;
  37. input rst;
  38. output reg [7:0] LED = 8'b000_000_01;
  39.  
  40. always_ff @(posedge clk) begin
  41.  
  42. if (switches == 4'b1000) begin
  43. LED = LED *2; end
  44. else if (switches == 4'b1000 && LED == 8'b100_000_00) begin
  45. LED = LED / 2;
  46. end
  47. //if (LED == 8'b000_000_00) begin //when we reach the end of the line, we overflow LED vector and it turns to 0
  48. //then we get stuck because 0*2 = 0, so we need to change 0 to 1
  49. //LED = 8'b000_000_01;
  50. //end
  51.  
  52. if (!rst) begin
  53. LED = 8'b000_000_01;
  54. end
  55. end
  56.  
  57. endmodule
  58.  
  59.  
  60.  
  61. //Toggle audio ON/OFF with switch 0
  62. module audio_output (switch, audio_data, data);
  63. input switch;
  64. input data;
  65. output reg [7:0] audio_data;
  66.  
  67. always_comb
  68. case(switch)
  69. 1'b0: audio_data = 0;
  70. default: audio_data = {(~data),{7{data}}};
  71. endcase
  72. endmodule
  73.  
  74.  
  75. //Logic for dividing clock to produce specified notes based on switch positions
  76.  
  77. module organ(switches, divid);
  78. input [3:0] switches;
  79. output reg [31:0] divid;
  80. always_comb
  81. case(switches)
  82. 4'b0000: divid = `Do;
  83. 4'b0001: divid = `Re;
  84. 4'b0010: divid = `Mi;
  85. 4'b0011: divid = `Fa;
  86. 4'b0100: divid = `So;
  87. 4'b0101: divid = `La;
  88. 4'b0110: divid = `Si;
  89. 4'b0111: divid = `Do2;
  90. 4'b1000: divid = `OneHz;
  91. default: divid = `OnekHZ;
  92. endcase
  93. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement