- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
module test (clk,led);
input clk;
output led;
reg [7:0] counter;
always@(posedge clk) begin
if (counter < 100) counter <= counter +1;
else counter <= 0;
end
always @ (counter) begin
if (counter>0) led = 1;
else if (counter<20) led = 1;
else led = 0;
end
endmodule
trying to make sure that the value of led turns 1 only when the value of counter varies from 1 to 20. I want led to be zero when counter is zero. any workaround this or am i doing something wrong?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to declare 'led' as a reg, in the same way you've declared counter. Declaring it as an output to the module isn't enough (as it is in other languages).
You can either add:
reg led;
or change the output declaration to:
output reg led;
Cheers,
Alex
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