Skip to content

Commit

Permalink
added timer, added buzzer, added blink for timer, refined timings and…
Browse files Browse the repository at this point in the history
… FSM conditions
  • Loading branch information
LimSean committed Dec 1, 2018
1 parent 41cd715 commit a264e43
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/blinker.luc
Original file line number Diff line number Diff line change
@@ -0,0 1,15 @@
module blinker (
input clk, // clock
input rst, // reset
output blink_fast,
output blink_med,
output blink_slow
) {
dff counter[27] (.clk(clk),.rst(rst));
always {
blink_fast = counter.q[23];
blink_med = counter.q[24];
blink_slow = counter.q[25];

}
}
186 changes: 186 additions & 0 deletions source/timer.luc
Original file line number Diff line number Diff line change
@@ -0,0 1,186 @@
module timer (
input clk, // clock
input rst, // reset
input state[2],
output led[10],
output timeout
) {

dff twenty[35](.clk(clk), .rst(rst));
dff fourty[35](.clk(clk), .rst(rst));

fsm timer(.clk(clk), .rst(rst)) = {IDLE, TEN, NINE, EIGHT, SEVEN, SIX, FIVE, FOUR, THREE, TWO, ONE, TIMEOUT};

blinker blink(.clk(clk), .rst(rst));

always {
led = 0;
timeout = 0;

case(timer.q){
timer.IDLE:
led = 10h2FF;
if(state == 1){
timer.d = timer.TEN;
}else if(state == 2){
timer.d = timer.EIGHT;
}else if(state == 3){
timer.d = timer.SIX;
}

timer.TEN:
led = 10b111111111X;
led[9] = blink.blink_slow;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.NINE;
}
}

timer.NINE:
led = 10b11111111XZ;
led[8] = blink.blink_slow;
fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.EIGHT;
}
}

timer.EIGHT:
led = 10b1111111XZZ;
led[7] = blink.blink_slow;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.SEVEN;
}
}
timer.SEVEN:
led = 10b111111XZZZ;
led[6] = blink.blink_med;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.SIX;
}
}
timer.SIX:
led = 10b11111XZZZZ;
led[5] = blink.blink_med;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.FIVE;
}
}
timer.FIVE:
led = 10b1111XZZZZZ;
led[4] = blink.blink_med;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.FOUR;
}
}
timer.FOUR:
led = 10b111XZZZZZZ;
led[3] = blink.blink_med;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.THREE;
}
}
timer.THREE:
led = 10b11XZZZZZZZ;
led[2] = blink.blink_med;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.TWO;
}
}
timer.TWO:
led = 10b1X00000000;
led[1] = blink.blink_slow;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.ONE;
}
}
timer.ONE:
led = 10bXZZZZZZZZZ;
led[1] = blink.blink_slow;

fourty.d = fourty.q 1;
if(fourty.q[31] == 1){
fourty.d[30:0] = 0;

twenty.d = twenty.q 1;
if(twenty.q[30] == 1){

twenty.d[29:0] = 0;
timer.d = timer.TIMEOUT;
}
}
timer.TIMEOUT:
timeout = 1;
}
}
}

0 comments on commit a264e43

Please sign in to comment.