Line 47... |
Line 47... |
o_sseg, o_led, o_interrupt,
|
o_sseg, o_led, o_interrupt,
|
// A once-per-day strobe on the last clock of the day
|
// A once-per-day strobe on the last clock of the day
|
o_ppd,
|
o_ppd,
|
// Time setting hack(s)
|
// Time setting hack(s)
|
i_hack);
|
i_hack);
|
|
parameter DEFAULT_SPEED = 32'd2814750; //2af31e = 2^48 / 100e6 MHz
|
input i_clk;
|
input i_clk;
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
input [2:0] i_wb_addr;
|
input [2:0] i_wb_addr;
|
input [31:0] i_wb_data;
|
input [31:0] i_wb_data;
|
// input i_btn;
|
// input i_btn;
|
Line 58... |
Line 59... |
output reg [31:0] o_sseg;
|
output reg [31:0] o_sseg;
|
output wire [15:0] o_led;
|
output wire [15:0] o_led;
|
output wire o_interrupt, o_ppd;
|
output wire o_interrupt, o_ppd;
|
input i_hack;
|
input i_hack;
|
|
|
reg [31:0] clock, stopwatch, ckspeed;
|
reg [31:0] stopwatch, ckspeed;
|
reg [25:0] timer;
|
reg [25:0] clock, timer;
|
|
|
wire ck_sel, tm_sel, sw_sel, sp_sel, al_sel;
|
wire ck_sel, tm_sel, sw_sel, sp_sel, al_sel;
|
assign ck_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b000));
|
assign ck_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b000));
|
assign tm_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b001));
|
assign tm_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b001));
|
assign sw_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b010));
|
assign sw_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b010));
|
Line 76... |
Line 77... |
{ ck_carry, ck_counter } <= ck_counter + { 8'h00, ckspeed };
|
{ ck_carry, ck_counter } <= ck_counter + { 8'h00, ckspeed };
|
|
|
wire ck_pps;
|
wire ck_pps;
|
reg ck_prepps, ck_ppm, ck_pph, ck_ppd;
|
reg ck_prepps, ck_ppm, ck_pph, ck_ppd;
|
reg [7:0] ck_sub;
|
reg [7:0] ck_sub;
|
initial clock = 32'h00000000;
|
initial clock = 26'h000000;
|
assign ck_pps = (ck_carry)&&(ck_prepps);
|
assign ck_pps = (ck_carry)&&(ck_prepps);
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin
|
begin
|
if (ck_carry)
|
if (ck_carry)
|
ck_sub <= ck_sub + 1;
|
ck_sub <= ck_sub + 8'h1;
|
ck_prepps <= (ck_sub == 8'hff);
|
ck_prepps <= (ck_sub == 8'hff);
|
|
|
if (ck_pps)
|
if (ck_pps)
|
begin // advance the seconds
|
begin // advance the seconds
|
if (clock[3:0] >= 4'h9)
|
if (clock[3:0] >= 4'h9)
|
Line 141... |
Line 142... |
clock[15:8] <= i_wb_data[15:8];
|
clock[15:8] <= i_wb_data[15:8];
|
ck_pph <= (i_wb_data[15:8] == 8'h59);
|
ck_pph <= (i_wb_data[15:8] == 8'h59);
|
end
|
end
|
if (6'h3f != i_wb_data[21:16])
|
if (6'h3f != i_wb_data[21:16])
|
clock[21:16] <= i_wb_data[21:16];
|
clock[21:16] <= i_wb_data[21:16];
|
clock[31:22] <= i_wb_data[31:22];
|
clock[25:22] <= i_wb_data[25:22];
|
if (8'h00 == i_wb_data[7:0])
|
if (8'h00 == i_wb_data[7:0])
|
ck_sub <= 8'h00;
|
ck_sub <= 8'h00;
|
end
|
end
|
end
|
end
|
|
|
Line 169... |
Line 170... |
initial tm_pps = 1'b0;
|
initial tm_pps = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin
|
begin
|
if (ck_carry)
|
if (ck_carry)
|
begin
|
begin
|
tm_sub <= tm_sub + 1;
|
tm_sub <= tm_sub + 8'h1;
|
tm_pps <= (tm_sub == 8'hff);
|
tm_pps <= (tm_sub == 8'hff);
|
end else
|
end else
|
tm_pps <= 1'b0;
|
tm_pps <= 1'b0;
|
|
|
if ((~tm_alarm)&&(tm_running)&&(tm_pps))
|
if ((~tm_alarm)&&(tm_running)&&(tm_pps))
|
Line 260... |
Line 261... |
sw_pps <= 1'b0;
|
sw_pps <= 1'b0;
|
if (sw_running)
|
if (sw_running)
|
begin
|
begin
|
if (ck_carry)
|
if (ck_carry)
|
begin
|
begin
|
sw_sub <= sw_sub + 1;
|
sw_sub <= sw_sub + 8'h1;
|
sw_pps <= (sw_sub == 8'hff);
|
sw_pps <= (sw_sub == 8'hff);
|
end
|
end
|
end
|
end
|
|
|
stopwatch[7:1] <= sw_sub[7:1];
|
stopwatch[7:1] <= sw_sub[7:1];
|
Line 378... |
Line 379... |
// real time clock RTL file can handle tracking the clock in any
|
// real time clock RTL file can handle tracking the clock in any
|
// device. Further, because this is only the lower 32 bits of a
|
// device. Further, because this is only the lower 32 bits of a
|
// 48 bit counter per seconds, the clock jitter is kept below
|
// 48 bit counter per seconds, the clock jitter is kept below
|
// 1 part in 65 thousand.
|
// 1 part in 65 thousand.
|
//
|
//
|
initial ckspeed = 32'd2814750; // 2af31e = 2^48 / 100e6 MHz
|
initial ckspeed = DEFAULT_SPEED;
|
// In the case of verilator, comment the above and uncomment the line
|
// In the case of verilator, comment the above and uncomment the line
|
// below. The clock constant below is "close" to simulation time,
|
// below. The clock constant below is "close" to simulation time,
|
// meaning that my verilator simulation is running about 300x slower
|
// meaning that my verilator simulation is running about 300x slower
|
// than board time.
|
// than board time.
|
// initial ckspeed = 32'd786432000;
|
// initial ckspeed = 32'd786432000;
|
Line 423... |
Line 424... |
end
|
end
|
|
|
reg [15:0] h_sseg;
|
reg [15:0] h_sseg;
|
reg [3:1] dmask;
|
reg [3:1] dmask;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(clock[27:24])
|
case(clock[25:24])
|
4'h1: begin h_sseg <= timer[15:0];
|
2'h1: begin h_sseg <= timer[15:0];
|
if (tm_alarm) dmask <= 3'h7;
|
if (tm_alarm) dmask <= 3'h7;
|
else begin
|
else begin
|
dmask[3] <= (12'h000 != timer[23:12]); // timer[15:12]
|
dmask[3] <= (12'h000 != timer[23:12]); // timer[15:12]
|
dmask[2] <= (16'h000 != timer[23: 8]); // timer[11: 8]
|
dmask[2] <= (16'h000 != timer[23: 8]); // timer[11: 8]
|
dmask[1] <= (20'h000 != timer[23: 4]); // timer[ 7: 4]
|
dmask[1] <= (20'h000 != timer[23: 4]); // timer[ 7: 4]
|
// dmask[0] <= 1'b1; // Always on
|
// dmask[0] <= 1'b1; // Always on
|
end end
|
end end
|
4'h2: begin h_sseg <= stopwatch[19:4];
|
2'h2: begin h_sseg <= stopwatch[19:4];
|
dmask[3] <= (12'h00 != stopwatch[27:16]);
|
dmask[3] <= (12'h00 != stopwatch[27:16]);
|
dmask[2] <= (16'h000 != stopwatch[27:12]);
|
dmask[2] <= (16'h000 != stopwatch[27:12]);
|
dmask[1] <= 1'b1; // Always on, stopwatch[11:8]
|
dmask[1] <= 1'b1; // Always on, stopwatch[11:8]
|
// dmask[0] <= 1'b1; // Always on, stopwatch[7:4]
|
// dmask[0] <= 1'b1; // Always on, stopwatch[7:4]
|
end
|
end
|
4'h3: begin h_sseg <= ck_last_clock[15:0];
|
2'h3: begin h_sseg <= ck_last_clock[15:0];
|
dmask[3:1] <= 3'h7;
|
dmask[3:1] <= 3'h7;
|
end
|
end
|
default: begin // 4'h0
|
default: begin // 4'h0
|
h_sseg <= { 2'b00, ck_last_clock[21:8] };
|
h_sseg <= { 2'b00, ck_last_clock[21:8] };
|
dmask[2:1] <= 2'b11;
|
dmask[2:1] <= 2'b11;
|
Line 450... |
Line 451... |
end
|
end
|
endcase
|
endcase
|
|
|
wire [31:0] w_sseg;
|
wire [31:0] w_sseg;
|
assign w_sseg[ 0] = (~ck_sub[7]);
|
assign w_sseg[ 0] = (~ck_sub[7]);
|
assign w_sseg[ 8] = (clock[27:24] == 4'h2);
|
assign w_sseg[ 8] = (clock[25:24] == 2'h2);
|
assign w_sseg[16] = ((clock[27:24] == 4'h0)&&(~ck_sub[7]))||(clock[27:24] == 4'h3);
|
assign w_sseg[16] = ((clock[25:24] == 2'h0)&&(~ck_sub[7]))||(clock[25:24] == 2'h3);
|
assign w_sseg[24] = 1'b0;
|
assign w_sseg[24] = 1'b0;
|
hexmap ha(i_clk, h_sseg[ 3: 0], w_sseg[ 7: 1]);
|
hexmap ha(i_clk, h_sseg[ 3: 0], w_sseg[ 7: 1]);
|
hexmap hb(i_clk, h_sseg[ 7: 4], w_sseg[15: 9]);
|
hexmap hb(i_clk, h_sseg[ 7: 4], w_sseg[15: 9]);
|
hexmap hc(i_clk, h_sseg[11: 8], w_sseg[23:17]);
|
hexmap hc(i_clk, h_sseg[11: 8], w_sseg[23:17]);
|
hexmap hd(i_clk, h_sseg[15:12], w_sseg[31:25]);
|
hexmap hd(i_clk, h_sseg[15:12], w_sseg[31:25]);
|
Line 488... |
Line 489... |
// connecting this module to a year/month/date date/calendar module.
|
// connecting this module to a year/month/date date/calendar module.
|
assign o_ppd = (ck_ppd)&&(ck_pps);
|
assign o_ppd = (ck_ppd)&&(ck_pps);
|
|
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(i_wb_addr[2:0])
|
case(i_wb_addr[2:0])
|
3'b000: o_data <= { clock[31:22], ck_last_clock };
|
3'b000: o_data <= { 6'h00, clock[25:22], ck_last_clock };
|
3'b001: o_data <= { 6'h00, timer };
|
3'b001: o_data <= { 6'h00, timer };
|
3'b010: o_data <= stopwatch;
|
3'b010: o_data <= stopwatch;
|
3'b011: o_data <= { 6'h00, al_tripped, al_enabled, 2'b00, alarm_time };
|
3'b011: o_data <= { 6'h00, al_tripped, al_enabled, 2'b00, alarm_time };
|
3'b100: o_data <= ckspeed;
|
3'b100: o_data <= ckspeed;
|
3'b101: o_data <= { 2'b00, hack_time };
|
3'b101: o_data <= { 2'b00, hack_time };
|