- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi i have tried to flash a led with 1Hz frequency but could not be able to do it. Can you pls see my code below and advise?
The project compiles fine. I have connected the 50MHz clk to a pll 1/10000 which equals 5KHz. That frequency goes into the module "pwm". The led output is connected to the first led of the DE0-nano (bit 0). module pwm(clock, led);input clock; // wire
output led; reg led;
reg [31:0] ctr=0;
parameter max = 31'd5000;
// when ctr equals max save the value 0 to next_ctr, else increment ctr by one
assign next_ctr = (ctr == max) ? 31'd0 : ctr + 31'd1;
// when ctr equals max save the opposite of led_status to led_status, else save the same value
assign led_status = (ctr == max) ? led_status^1 : led_status;
// execute the assign expressions on every rising edge of the clock
always @ (posedge clock) begin
led <= led_status; // change the led status or let it as is
ctr <= next_ctr; // increment by one or reset to zero when ctr reaches 50m
end
endmodule I googled it and found more or less similar information. Can you help? Regards Manos
- Tags:
- Cyclone® IV FPGAs
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I solved the issue. module test(clock, led); input clock; // wire output led; reg led; reg [31:0] ctr=0; parameter max = 5000; // Execute the assign expressions on every rising edge of the clock always @ (posedge clock) begin ctr <= (ctr == max) ? 0 : ctr + 1; led <= (ctr == max) ? led^1 : led; end endmodule Regards Manos
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