- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello this is my code
module count_moda
# (parameter modulus = 100)
(
input clk, aclr_n, updown,
output reg q
);
initial q = 0;
always @(posedge clk, negedge aclr_n)
begin
if (!aclr_n)
q <= 0;
else begin
q <= q + (updown? 1'b1 : -1'b1);
if (q == modulus-1)
q <= 8'd0;
// if (q == 0)
// q <= modulus -1;
end
end
endmodule
The way it is right now it restarts when 99 is reached, then it starts to count up untill 10 when my updown signal goes to 0 and it starts decremetating to 9, 8 etc.. untill it goes to a negative value! But i want to go back to 99 when i reach 0 in the decrematating mode, don't know how to solve it If i uncomment the second if my result is always 0 or 99. Thanks
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't perform the overflow/underflow operation correctly without using the updown input, it seems so obvious...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> if (q == modulus-1) > q <= 8'd0;
this script should be if( updoun ) begin if( q == (modulus-1) ) q <= 8'h0; end else begin if( q == 8'h0 ) q <= (modulus-1) ; end I think this is obvious too. you haven't written reset logic for negative direction.
Reply
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