-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiwali_lights.v
More file actions
97 lines (89 loc) · 3.77 KB
/
Copy pathdiwali_lights.v
File metadata and controls
97 lines (89 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* hi there i want to create a light display
its diwali time and i want to make some nice code and diwali lights
so here we are, making a FSM Diwali chain lights
its just my imagination, compromise with the faults
im trying it for the first time
*/
/*
pattern1= on on on on on on on on
pattern2= on off on off on off on off
pattern3= on on off off on on off off
*/
`timescale 1ns/1ps
module diwali_lights(
input [1:0] number,
input reset,
output reg [9:0]led
);
//there are 10leds
reg [3:0]i;
reg [5:0]count;
always @ (number, reset)
begin
if (reset)
begin
for(i=0;i<=4'b1001;i=i+1'b1)
led[i]=1'b0;
$display("-----------------resetting----------------------------------------------------------");
$display($time,"\t%0d %0d %0d %0d %0d %0d %0d %0d %0d %0d",led[4'b0],led[4'b0001],led[4'b0010],led[4'b0011],led[4'b0100],led[4'b0101],led[4'b0110],led[4'b0111],led[4'b1000],led[4'b1001]);
end
else
begin
case (number)
2'b00: //pattern1
begin
$display("-----------------pattern1----------------------------------------------------------");
count=6'b0;
while(count<20)
begin
for(i=0;i<=4'b1001;i=i+1)
led[i]=0; //0 suggest off state
$display($time,"\t%0d %0d %0d %0d %0d %0d %0d %0d %0d %0d",led[4'b0],led[4'b0001],led[4'b0010],led[4'b0011],led[4'b0100],led[4'b0101],led[4'b0110],led[4'b0111],led[4'b1000],led[4'b1001]);
#2;
for(i=0;i<=4'b1001;i=i+1'b1)
led[i]=1'b1; //1 suggest on state
$display($time,"\t%0d %0d %0d %0d %0d %0d %0d %0d %0d %0d",led[4'b0],led[4'b0001],led[4'b0010],led[4'b0011],led[4'b0100],led[4'b0101],led[4'b0110],led[4'b0111],led[4'b1000],led[4'b1001]);
count=count+2'b10;
end
/* by default if no number is set
then the patterns will rotate after 20 time units*/
end
2'b01: //pattern2
begin
$display("-----------------pattern2----------------------------------------------------------");
count=6'b0;
led[4'b0]=1'b1; //first led is set to 1 at the begining
while(count<20)
begin
for(i=1;i<=4'b1001;i=i+1'b1)
led[i]=~(led[i-1]);
$display($time,"\t%0d %0d %0d %0d %0d %0d %0d %0d %0d %0d",led[4'b0],led[4'b0001],led[4'b0010],led[4'b0011],led[4'b0100],led[4'b0101],led[4'b0110],led[4'b0111],led[4'b1000],led[4'b1001]);
#1;
led[0]=led[9];
count=count+1;
end
end
2'b10: //pattern3
begin
$display("-----------------pattern3----------------------------------------------------------");
count=6'b0;
led[4'b0]=1; //first led is set to 1 at the begining
led[4'b0001]=1;
while(count<20)
begin
for(i=4'b0010;i<=4'b1001;i=i+2'b10)
begin
led[i] =!(led[i-1]);
led[i+1]=!(led[i-1]);
end
$display($time,"\t%0d %0d %0d %0d %0d %0d %0d %0d %0d %0d",led[4'b0],led[4'b0001],led[4'b0010],led[4'b0011],led[4'b0100],led[4'b0101],led[4'b0110],led[4'b0111],led[4'b1000],led[4'b1001]);
#1;
led[0]=!led[9];
led[1]=!led[9];
count=count+1;
end
end
endcase
end
end
endmodule