techy5025
Newbie level 4
- Joined
- Mar 3, 2020
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Location
- Orlando, Fla
- Activity points
- 62
Hello. I am new to verilog and to this forum, and have been trying to get an alarm clock working on the BASYS 3 FPGA board using Vivado 2019. All the code is working correctly except for the part that advances the time. The problem is that both the seconds and minutes advance together .. so essentially the seconds display as minutes and the minutes as hours. I have included a code snippet below.
The input clock is at a .1 sec rate. The first part of the code is used to set the min and sec and works correctly. The second part causes the decimal point of the 7-segment display and an LED to blink at a one second rate and also works correctly. The third part steps the second and minutes together. I have tried using blocking and non-blocking code (as here) with the same results. The problem has been verified both on the Vivado simulator and on the BASYS board.
I'll be happy to be embarrassed by what is obviously a newly mistake!
Thanks for the help. Jim
The input clock is at a .1 sec rate. The first part of the code is used to set the min and sec and works correctly. The second part causes the decimal point of the 7-segment display and an LED to blink at a one second rate and also works correctly. The third part steps the second and minutes together. I have tried using blocking and non-blocking code (as here) with the same results. The problem has been verified both on the Vivado simulator and on the BASYS board.
I'll be happy to be embarrassed by what is obviously a newly mistake!
Thanks for the help. Jim
Code:
/************* Clock operation**************/
always @(posedge first_toggle) //toggle every .1 sec
begin
if (reset)
begin // reset counters
tmp_chour = 4'b0000;
tmp_cmin = 4'b0000;
tmp_csec = 4'b0000;
end
//set alarm/clock min
if (set_min) // set minutes
begin
if ((min_del == 0) || (min_del >= 15 )) // first toggle on key press or 1.5 sec delay
begin
if (set_alarm) // Set alarm ?
if(tmp_amin >= 59) // Min >= 59 ?
tmp_amin = 0; // Yes - Zero alarm min
else
tmp_amin = tmp_amin + 1; //No - bump alarm min
else if(tmp_cmin >= 59) // Min >= 59 ?
tmp_cmin = 0; // Yes - Zero clock min
else
tmp_cmin = tmp_cmin + 1; //No - bump clock min
if (min_del <= 14) // 1.5 sec delay for fast speed
min_del <= min_del +1; // Bump delay tenths of a sec
end
else if (min_del <= 14) // 1.5 sec delay for fast speed
min_del <= min_del +1; // Bump delay tenths of a sec
end
else
min_del = 0; // Clear min delay
//set alarm/clock hours
if (set_hour) // set hour
begin
if ((hour_del == 0) || (hour_del >= 15 )) // first toggle on key press or 1.5 sec delay
begin
if (set_alarm && mode == 1) // Set alarm and 24 hour ?
if(tmp_ahour >= 23) // 24 hour mode?
tmp_ahour = 0; // Yes - Zero ahour
else
tmp_ahour = tmp_ahour + 1; // No - bump ahour
else if (set_alarm && mode == 0) // Set alarm and 12 hour ?
if(tmp_ahour >= 12) // 12 hour mode?
tmp_ahour = 0; // Yes - Zero ahour
else
tmp_ahour = tmp_ahour + 1; // No - bump ahour
else if (!set_alarm && mode == 1) // Set clock and 24 hour ?
if(tmp_chour >= 23) // 24 hour mode?
tmp_chour = 0; // Yes - Zero clock hour
else
tmp_chour = tmp_chour + 1; // No - bump clock hour
else if (!set_alarm && mode == 0) // Set clock and 12 hour ?
if(tmp_chour >= 12) // 12 hour mode?
tmp_chour = 0; // Yes - Zero clock hour
else
tmp_chour = tmp_chour + 1; // No - bump clock hour
if (hour_del <= 14) // Fast delay up?
hour_del <= hour_del +1; // No - Bump fast delay
end
else if (hour_del <= 14) // 1.5 sec delay for fast speed
hour_del <= hour_del +1; // Bump delay tenths of a sec
end
else
hour_del = 0; // Clear hour delay
//Normal clock operation
// This code is entered once every tenth second
// Turn decimal point and LED #1 on for approx .5 sec
if (tenth_counter >= 5)
begin
dp_tmp <= 1; // Turn decimal point off
LED16 <= 0; // Turn LED off
end
else
begin
dp_tmp <= 0; // Turn decimal point on
LED16 <= 1; // Turn LED on
end
// Advance count on ninth of ten "tenth counts"
// tmp_csec, cmin, chour > clock second, minuter, hours
if (tenth_counter >= 9) //advance time if tenth count is 9
begin
tenth_counter <= 0; // Reset tenth counter
if(tmp_csec >= 59) // second > 59 then minute increases
begin
tmp_csec <= 0; // clear second count
tmp_cmin <= tmp_cmin + 1; // bump the minute count
end
else
begin
tmp_csec <= tmp_csec + 1; //bump the second count
end
if(tmp_cmin >= 59) // minute > 59 then hour increases
begin
tmp_cmin <= 0; // clear the minute count
tmp_chour <= tmp_chour + 1;// bump the hour count
end
else
begin
tmp_cmin <= tmp_cmin + 1; // bump the minute count
end
if(mode == 1 && tmp_chour >= 24) // 24 hour mode = 1 12 hour = 0
tmp_chour <= 0; // 24 hours 0-23
else if (mode == 0 && tmp_chour >= 13)
tmp_chour <= 1; // 12 hour mode 1-12
end
else
tenth_counter <= tenth_counter + 1; // Bump tenth counter
end