Si tiene un DE0-CV, hay una herramienta de terrasic que genera una aplicación de esqueleto. Puede abrir esta aplicación de esqueleto en quartus.
Una vez que tenga esto, puede agregar el siguiente código al archivo .v verilog dentro de quartus. Compile y descargue el programa en su pizarra y debe ver un reloj digital en la pantalla. Para pasar de 50MHz a 1Hz puede usar un contador o una serie de contadores. Los PLL son mucho más complejos que los contadores. El código de ejemplo a continuación genera una cantidad de relojes de baja frecuencia basados en el reloj del sistema de 50 MHz.
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
module Project5(
//////////// CLOCK //////////
input CLOCK_50,
input CLOCK2_50,
input CLOCK3_50,
inout CLOCK4_50,
//////////// SEG7 //////////
output [6:0] HEX0,
output [6:0] HEX1,
output [6:0] HEX2,
output [6:0] HEX3,
output [6:0] HEX4,
output [6:0] HEX5,
//////////// KEY //////////
input [3:0] KEY,
input RESET_N,
//////////// LED //////////
output [9:0] LEDR,
//////////// microSD Card //////////
output SD_CLK,
inout SD_CMD,
inout [3:0] SD_DATA,
//////////// SW //////////
input [9:0] SW
);
//=======================================================
// Main
//=======================================================
wire w1Sec,w1Min,w1Hour,w100mSec;
wire[7:0 ] sec, min, hr;
wire incSec;
wire incMin;
wire incHr;
// invert keys (input 1 == not pressed, pull up resistor)
assign incSec=~KEY[0];
assign incMin=~KEY[1];
assign incHr=~KEY[2];
// make 100ms 500ms and 1 second pulses (square wave)
PULSE puls100msec(CLOCK_50,5000000,w100mSec);
PULSE puls500msec(CLOCK_50,25000000,w500mSec);
PULSE pulssec(CLOCK_50, 50000000,w1Sec);
// count pulses + cascade counters
CTR clocksec(w1Sec,w500mSec,w100mSec,incSec,~RESET_N,59,sec,w1Min);
CTR clockmin(w1Min,w500mSec,w100mSec,incMin,~RESET_N,59,min,w1Hour);
CTR clockhr(w1Hour,w500mSec,w100mSec,incHr,~RESET_N,23,hr);
// show display
BYTETO7SEG digit0000XX(sec,HEX1,HEX0);
BYTETO7SEG digit00xx00(min,HEX3,HEX2);
BYTETO7SEG digitxx0000(hr,HEX5,HEX4);
// control leds:
assign LEDR[0]=w100mSec;
assign LEDR[1]=w500mSec;
assign LEDR[2]=w1Sec;
assign LEDR[3]=w1Min;
assign LEDR[4]=w1Hour;
endmodule
//=======================================================
// counter sec/min of clock:
//=======================================================
module CTR(w1,w2,w3,inc,fast,valRef,val,w);
input wire w1,w2,w3,inc,fast;
input wire [7:0] valRef;
output reg [7:0] val;
output reg w;
wire trig = (w1 & ~inc) || ((inc & w2 & ~fast) || (inc & w3 & fast));
always @(posedge trig)
begin
if (val>=valRef)
begin
val <= 0;
if (~inc)
w <= 1;
end
else
begin
val <= val + 1;
w <= 0;
end
end
endmodule
//=======================================================
// Pulse x hz from 50 mhz clock:
//=======================================================
module PULSE(clk,qRef,w);
input wire clk;
input wire [63:0] qRef;
output reg w;
reg [63:0] q;
always @(posedge clk)
begin
if (q>=qRef)
begin
q <= 0;
w <= 1;
end
else
begin
q <= q + 1;
w <= 0;
end
end
endmodule
//=======================================================
// hex to 7 seg control:
//=======================================================
module BYTETO7SEG(bt,seg1,seg2);
input wire [7:0] bt;
output reg [6:0] seg1;
output reg [6:0] seg2;
wire [3:0] x;
wire [3:0] y;
assign x = bt / 10;
assign y = bt % 10;
always @(bt)
begin
case (x)
4'b0000 : seg1 = 7'b1000000; //Hexadecimal 0
4'b0001 : seg1 = 7'b1111001; //Hexadecimal 1
4'b0010 : seg1 = 7'b0100100; //Hexadecimal 2
4'b0011 : seg1 = 7'b0110000; //Hexadecimal 3
4'b0100 : seg1 = 7'b0011001; //Hexadecimal 4
4'b0101 : seg1 = 7'b0010010; //Hexadecimal 5
4'b0110 : seg1 = 7'b0000010; //Hexadecimal 6
4'b0111 : seg1 = 7'b1111000; //Hexadecimal 7
4'b1000 : seg1 = 7'b0000000; //Hexadecimal 8
4'b1001 : seg1 = 7'b0010000; //Hexadecimal 9
4'b1010 : seg1 = 7'b0001000; //Hexadecimal A
4'b1011 : seg1 = 7'b0000011; //Hexadecimal B
4'b1100 : seg1 = 7'b1000110; //Hexadecimal C
4'b1101 : seg1 = 7'b0100001; //Hexadecimal D
4'b1110 : seg1 = 7'b0000110; //Hexadecimal E
4'b1111 : seg1 = 7'b0001110; //Hexadecimal F // low logic = burning led
endcase
case (y)
4'b0000 : seg2 = 7'b1000000; //Hexadecimal 0
4'b0001 : seg2 = 7'b1111001; //Hexadecimal 1
4'b0010 : seg2 = 7'b0100100; //Hexadecimal 2
4'b0011 : seg2 = 7'b0110000; //Hexadecimal 3
4'b0100 : seg2 = 7'b0011001; //Hexadecimal 4
4'b0101 : seg2 = 7'b0010010; //Hexadecimal 5
4'b0110 : seg2 = 7'b0000010; //Hexadecimal 6
4'b0111 : seg2 = 7'b1111000; //Hexadecimal 7
4'b1000 : seg2 = 7'b0000000; //Hexadecimal 8
4'b1001 : seg2 = 7'b0010000; //Hexadecimal 9
4'b1010 : seg2 = 7'b0001000; //Hexadecimal A
4'b1011 : seg2 = 7'b0000011; //Hexadecimal B
4'b1100 : seg2 = 7'b1000110; //Hexadecimal C
4'b1101 : seg2 = 7'b0100001; //Hexadecimal D
4'b1110 : seg2 = 7'b0000110; //Hexadecimal E
4'b1111 : seg2 = 7'b0001110; //Hexadecimal F // low logic = burning led
endcase
end
endmodule