led walker
This commit is contained in:
@@ -16,6 +16,7 @@ module top(i_clk, o_led, lcol1);
|
|||||||
|
|
||||||
reg [WIDTH-1:0] counter;
|
reg [WIDTH-1:0] counter;
|
||||||
reg [7:0] obuf; // output buffer, take into account the icefun use active low LED
|
reg [7:0] obuf; // output buffer, take into account the icefun use active low LED
|
||||||
|
reg [3:0] led_index;
|
||||||
reg strobe;
|
reg strobe;
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
@@ -26,11 +27,43 @@ module top(i_clk, o_led, lcol1);
|
|||||||
always @(posedge clk_12MHz)
|
always @(posedge clk_12MHz)
|
||||||
{strobe, counter} <= counter + 1'b1;
|
{strobe, counter} <= counter + 1'b1;
|
||||||
|
|
||||||
|
// fsm
|
||||||
|
always @(posedge clk_12MHz) begin
|
||||||
|
if (strobe) // led_index change only when strobe is 1
|
||||||
|
if (led_index >= 4'hd)
|
||||||
|
led_index <= 0;
|
||||||
|
else
|
||||||
|
led_index <= led_index + 1'b1;
|
||||||
|
|
||||||
|
case (led_index)
|
||||||
|
4'h0: obuf <= 8'h01;
|
||||||
|
4'h1: obuf <= 8'h02;
|
||||||
|
4'h2: obuf <= 8'h04;
|
||||||
|
4'h3: obuf <= 8'h08;
|
||||||
|
4'h4: obuf <= 8'h10;
|
||||||
|
4'h5: obuf <= 8'h20;
|
||||||
|
4'h6: obuf <= 8'h40;
|
||||||
|
4'h7: obuf <= 8'h80;
|
||||||
|
4'h8: obuf <= 8'h40;
|
||||||
|
4'h9: obuf <= 8'h20;
|
||||||
|
4'ha: obuf <= 8'h10;
|
||||||
|
4'hb: obuf <= 8'h08;
|
||||||
|
4'hc: obuf <= 8'h04;
|
||||||
|
4'hd: obuf <= 8'h02;
|
||||||
|
default : begin
|
||||||
|
obuf <= 8'h01;
|
||||||
|
end
|
||||||
|
endcase
|
||||||
|
end
|
||||||
|
|
||||||
|
/* shift reg
|
||||||
// shifting bit
|
// shifting bit
|
||||||
always @(posedge clk_12MHz)
|
always @(posedge clk_12MHz)
|
||||||
if (strobe)
|
if (strobe)
|
||||||
obuf <= {obuf[6:0], obuf[7]}; // left shift
|
obuf <= {obuf[6:0], obuf[7]}; // left shift
|
||||||
// obuf <= {obuf[0], obuf[7:1]}; // right shift
|
// obuf <= {obuf[0], obuf[7:1]}; // right shift
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
always @(posedge clk_12MHz)
|
always @(posedge clk_12MHz)
|
||||||
o_led <= ~obuf;
|
o_led <= ~obuf;
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ int main(int argc, char **argv) {
|
|||||||
unsigned tickcount = 0;
|
unsigned tickcount = 0;
|
||||||
int last_led = tb->o_led;
|
int last_led = tb->o_led;
|
||||||
|
|
||||||
for(int k=0; k<(1 << 14); k++) {
|
for(int k=0; k<(1 << 16); k++) {
|
||||||
tick(++tickcount, tb, tfp);
|
tick(++tickcount, tb, tfp);
|
||||||
|
|
||||||
if (last_led != tb->o_led) {
|
// if (last_led != tb->o_led) {
|
||||||
printf("k = %7d, led = %d\n", k, tb->o_led);
|
// printf("k = %7d, led = %d\n", k, tb->o_led);
|
||||||
}
|
// }
|
||||||
|
|
||||||
last_led = tb->o_led;
|
last_led = tb->o_led;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user