I am trying to turn on one LED for x amount of time before cycling to the next LED and so on, but I have been unable to do so. Can someone help?
In terms of the code, I am trying to power br_pin[0] for x time, then turn it off and power br_pin[1] and so on, until I reach br_pin[3], from where I will cycle back to turn on br_pin[0]
Here is my code; all help is appreciated!!
module au_top (
input clk, // 100MHz clock
input rst_n, // reset button (active low)
input usb_rx, // USB->Serial input
output usb_tx,
output br_pin[8]
) {
sig rst;
.clk(clk) {
// The reset conditioner is used to synchronize the reset signal to the FPGA
// clock. This ensures the entire FPGA comes out of reset at the same time.
reset_conditioner reset_cond;
.rst(rst) {
counter myCounter;
dff tmr[28];
}
}
always {
tmr.d = tmr.q + 1;
reset_cond.in = ~rst_n; // input raw inverted reset signal
rst = reset_cond.out; // conditioned reset
usb_tx = usb_rx; // loop serial port
br_pin = 8x{8h00};
if(tmr.q[27] == 1){
br_pin[myCounter.value] = 8hFF;
}
}
}
module counter (
input clk, // clock
input rst, // reset
//output on_status,
output value // current value
) {
.clk(clk), .rst(rst) {
dff val; // value storage
}
always {
val.d = 0;
if (val.q == 4) // if max value
val.d = 0; // reset to 0
else // otherwise
val.d = val.q + 1; // add one
value = val.q;
}
}
I know I have initiated the Br pins correctly because I have tested them!
You should generally not use non-clock signals as clocks. This will almost certainly lead to issues at some point due to timing.
Instead you should clock counter off the main clock but only increment it when the conditions are right. In this case you could use if (&tmr.q) which would only be valid when tmr.q is maxed out.
If you’re using a power of 2 prescaler, you can do this even cleaner but just using a bigger dff. See the built in counter module as an example