- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I am trying to create an alarm clock using a Terasic CycloneV fpga. I need to be able to set the time and an alarm. Right now I'm unable to get the clock to reset at 24 hours. I have attached the modulo counter module as a .txt. Can anyone help with the statement to reset at 24 hours?

```
module testFiveBitCounter(input logic CLOCK_50,
input logic KEY,
input logic SW,
output logic LEDR,
output regHEX0,
output regHEX1,
output regHEX2,
output regHEX3,
output regHEX4,
output regHEX5);
logic oneSecondEnable, tenSecondEnable, oneMinuteEnable,
tenMinuteEnable, oneHourEnable, tenHourEnable, temp = 1'b0;
logic countSecOnes;
logic countSecTens;
logic countMinOnes;
logic countMinTens;
logic countHourOnes;
logic countHourTens;
always_ff @(posedge oneSecondEnable) begin
temp = ~temp;
LEDR = temp;
end
sevenSeg digit0(.H(HEX0), .B(countSecOnes));
defparam oneSecond.n = 26;
defparam oneSecond.k = (50000000)/75; //5000000
moduloCounter oneSecond(.clk(CLOCK_50),
.enable(1'b1),
.resetN(KEY),
.rollover(oneSecondEnable));
logic rollOnes;
defparam ones.n = 4;
defparam ones.k = 9;
moduloCounter ones(.clk(CLOCK_50), //oneSecondEnable
.resetN(KEY),
.enable(oneSecondEnable), //1'b1
.count(countSecOnes),
.rollover(rollOnes));
sevenSeg digit1(.H(HEX1), .B(countSecTens));
logic rollTens;
defparam tens.n = 3;
defparam tens.k = 5;
moduloCounter tens(.clk(CLOCK_50), //tenSecondEnable
.resetN(KEY),
.enable(oneSecondEnable & rollOnes), //1'b1
.count(countSecTens),
.rollover(rollTens));
sevenSeg digit2(.H(HEX2), .B(countMinOnes));
logic rollMinsOnes;
defparam onesMin.n = 4;
defparam onesMin.k = 9;
moduloCounter onesMin(.clk(CLOCK_50), //oneMinuteEnable
.resetN(KEY),
.enable(oneSecondEnable & rollOnes & rollTens), //1'b1
.count(countMinOnes),
.rollover(rollMinsOnes));
sevenSeg digit3(.H(HEX3), .B(countMinTens));
logic rollMinTens;
defparam tensMin.n = 3;
defparam tensMin.k = 5;
moduloCounter tensMin(.clk(CLOCK_50), //tenMinuteEnable
.resetN(KEY),
.enable(oneSecondEnable & rollOnes & rollTens & rollMinsOnes), //1'b1
.count(countMinTens),
.rollover(rollMinTens));
sevenSeg digit4(.H(HEX4), .B(countHourOnes));
logic rollHourOnes;
defparam onesHour.n = 4;//4
defparam onesHour.k = 9;//9
moduloCounter onesHour(.clk(CLOCK_50), //oneHourEnable
.resetN(KEY),
.enable(oneSecondEnable & rollOnes & rollTens & rollMinsOnes & rollMinTens), //1'b1
.count(countHourOnes),
.rollover(rollHourOnes));
sevenSeg digit5(.H(HEX5), .B(countHourTens));
logic rollHourTens;
defparam tensHour.n = 3;//4
defparam tensHour.k = 5;//5
moduloCounter tensHour(.clk(CLOCK_50), //tenHourEnable
.resetN(KEY),
.enable(oneSecondEnable & rollOnes & rollTens & rollMinsOnes & rollMinTens & rollHourOnes), //1'b1
.count(countHourTens),
.rollover(rollHourTens));
/*this is the part that doesn't work
always_ff @(posedge oneSecondEnable) begin
if (rollHourTens ==2 & rollHourOnes==4) begin
reset;
end
end
*/
endmodule
```

Link Copied

5 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

What problems are you having? What have you tried so far?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

The reason for the always_ff block not working is because you'v used the bit-wise AND (&) operator and not the logical AND (&&). Change the '&' to '&&' and try. It will trigger this time.

```
/*this is the part that doesn't work
always_ff @(posedge oneSecondEnable) begin
if (rollHourTens ==2 & rollHourOnes==4) begin <------ Change this to logical && from the bitwise &
reset;
end
end
*/
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

--- Quote Start --- The reason for the always_ff block not working is because you'v used the bit-wise AND (&) operator and not the logical AND (&&). Change the '&' to '&&' and try. It will trigger this time.

```
/*this is the part that doesn't work
always_ff @(posedge oneSecondEnable) begin
if (rollHourTens ==2 & rollHourOnes==4) begin <------ Change this to logical && from the bitwise &
reset;
end
end
*/
```

--- Quote End --- Altho the answer is technically correct (you should syntactically be using **&&**here instead of

**&**) it won't change the result ... the result of

**x==y**will be '0' or '1', and

**&**ing two of these together will still produce a single bit result '0' or '1' that can be tested by the

**if**. What does the line '

**reset;**' refer to? There is no other code (like a function or task or block) with this name in your code listing.

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page