Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. `timescale 1ns/10ps
  2.  
  3. module TrabalhoEletronicaDigital(a,b); //
  4. input a;
  5. output b;
  6. assign b = a;
  7. endmodule
  8.  
  9. //---------------------------------------------------------------------
  10.  
  11. module fibonnaci(clk, serie); //Questão 1
  12. input clk;
  13. output serie;
  14.  
  15. reg anterior = 'd0;
  16. reg atual = 'd1;
  17. reg serie = {anterior, atual};
  18.  
  19.  
  20. always@(posedge clk)
  21. begin
  22. atual = anterior + atual;
  23. anterior = atual;
  24. serie = {serie, atual};
  25. end
  26. endmodule
  27.  
  28. //---------------------------------------------------------------------
  29.  
  30. module clockcheck(clkin, refclk, freq); //Questão 2
  31. input refclk;
  32. input clkin;
  33. output [31:0] freq;
  34.  
  35. reg [31:0] freq;
  36. reg [31:0] count;
  37.  
  38. always @(posedge refclk)
  39. begin
  40. if (clkin)
  41. begin
  42. count = count + 1;
  43. end
  44. else
  45. begin
  46. freq = ('d50000/count); //Clock de controle de 50kHz
  47. count = 0;
  48. end
  49. end
  50.  
  51. endmodule
  52.  
  53. //---------------------------------------------------------------------
  54.  
  55. module divideclock(clkin, clkout); //Questão 3
  56. input clkin;
  57. output clkout;
  58.  
  59. reg count = 'd0;
  60. reg n = 'd3; //Determinar valor pelo qual o clock será dividido, n = 3 como exemplo
  61. reg clkout = 0;
  62.  
  63. always@(posedge clkin)
  64. begin
  65. if (count == n)
  66. begin
  67. clkout = 1;
  68. count = 'd0;
  69. end
  70. else
  71. begin
  72. count = count + 'd1;
  73. clkout = 0;
  74. end
  75. end
  76. endmodule
  77.  
  78. //---------------------------------------------------------------------
  79. module contador(clk, state); //Questão 5
  80. input clk;
  81. output state;
  82.  
  83. reg state = 4'b0000;
  84.  
  85. always@(posedge clk)
  86. begin
  87. case(state)
  88. 4'b1001 : state = 4'b0000;
  89. default : state = state + 1;
  90. endcase
  91. end
  92. endmodule
  93.  
  94. //---------------------------------------------------------------------
  95.  
  96. module checkmp3(stringinbinary, clk, alert); //Questão 9
  97. input [7:0] stringinbinary;
  98. input clk;
  99. output reg alert;
  100.  
  101. parameter nada = 2'b00,
  102. esperando m = 2'b01,
  103. esperando p = 2'b10;
  104. esperando 3 = 2'b10;
  105.  
  106. reg nstate; //proximo estado
  107. reg cstate; //estado atual
  108.  
  109. always@(stringinbinary, cstate)
  110. begin
  111. nstate = nada //estado default
  112.  
  113. case(cstate)
  114. nada : case(stringinbinary)
  115. 00101110 : cstate = esperando m; //00101110 '.' em binario
  116. default : cstate = nada; //01101101 'm' em binario
  117. endcase //01110000 'p' em binario
  118. esperando m : case(stringinbinary) //00110011 '3' em binario
  119. 01101101 : cstate = esperando p;
  120. 00101110 : cstate = esperando m;
  121. default : cstate = nada;
  122. endcase
  123. esperando p : case(stringinbinary)
  124. 00101110 : cstate = esperando m;
  125. 01110000 : cstate = esperando 3;
  126. default : cstate = nada;
  127. endcase
  128. esperando 3 : case(stringinbinary)
  129. 00101110 : cstate = esperando m;
  130. 00110011 : alert = 1
  131. cstate = nada;
  132. default : cstate = nada;
  133. endcase
  134. endcase
  135. end
  136.  
  137. always@(clk)
  138. begin
  139. cstate <= nstate;
  140. end
  141. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement