Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns/10ps
- module TrabalhoEletronicaDigital(a,b); //
- input a;
- output b;
- assign b = a;
- endmodule
- //---------------------------------------------------------------------
- module fibonnaci(clk, serie); //Questão 1
- input clk;
- output serie;
- reg anterior = 'd0;
- reg atual = 'd1;
- reg serie = {anterior, atual};
- always@(posedge clk)
- begin
- atual = anterior + atual;
- anterior = atual;
- serie = {serie, atual};
- end
- endmodule
- //---------------------------------------------------------------------
- module clockcheck(clkin, refclk, freq); //Questão 2
- input refclk;
- input clkin;
- output [31:0] freq;
- reg [31:0] freq;
- reg [31:0] count;
- always @(posedge refclk)
- begin
- if (clkin)
- begin
- count = count + 1;
- end
- else
- begin
- freq = ('d50000/count); //Clock de controle de 50kHz
- count = 0;
- end
- end
- endmodule
- //---------------------------------------------------------------------
- module divideclock(clkin, clkout); //Questão 3
- input clkin;
- output clkout;
- reg count = 'd0;
- reg n = 'd3; //Determinar valor pelo qual o clock será dividido, n = 3 como exemplo
- reg clkout = 0;
- always@(posedge clkin)
- begin
- if (count == n)
- begin
- clkout = 1;
- count = 'd0;
- end
- else
- begin
- count = count + 'd1;
- clkout = 0;
- end
- end
- endmodule
- //---------------------------------------------------------------------
- module contador(clk, state); //Questão 5
- input clk;
- output state;
- reg state = 4'b0000;
- always@(posedge clk)
- begin
- case(state)
- 4'b1001 : state = 4'b0000;
- default : state = state + 1;
- endcase
- end
- endmodule
- //---------------------------------------------------------------------
- module checkmp3(stringinbinary, clk, alert); //Questão 9
- input [7:0] stringinbinary;
- input clk;
- output reg alert;
- parameter nada = 2'b00,
- esperando m = 2'b01,
- esperando p = 2'b10;
- esperando 3 = 2'b10;
- reg nstate; //proximo estado
- reg cstate; //estado atual
- always@(stringinbinary, cstate)
- begin
- nstate = nada //estado default
- case(cstate)
- nada : case(stringinbinary)
- 00101110 : cstate = esperando m; //00101110 '.' em binario
- default : cstate = nada; //01101101 'm' em binario
- endcase //01110000 'p' em binario
- esperando m : case(stringinbinary) //00110011 '3' em binario
- 01101101 : cstate = esperando p;
- 00101110 : cstate = esperando m;
- default : cstate = nada;
- endcase
- esperando p : case(stringinbinary)
- 00101110 : cstate = esperando m;
- 01110000 : cstate = esperando 3;
- default : cstate = nada;
- endcase
- esperando 3 : case(stringinbinary)
- 00101110 : cstate = esperando m;
- 00110011 : alert = 1
- cstate = nada;
- default : cstate = nada;
- endcase
- endcase
- end
- always@(clk)
- begin
- cstate <= nstate;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement