Introduction: FPGA Alarm System
For the final project for the course ECE 2220 Digital Logic at the University of Manitoba, Team Caffeine has decided to implement a security system. This security system will utilize an Altera FPGA board, an IR break beam sensor, and a LilyPad Buzzer. The FPGA board will indicate if the alarm is armed and if the light from the sensor is interrupted with a LED. If both cases are true (ie, the alarm is armed and the light is interrupted), the alarm will give off a sound through the buzzer.. The FPGA board will also display the status of the alarm ('off' or 'on') on the seven segment display.
Step 1: Equipment/Programs Required
- A computer that is able to handle the processing
- Quartus II web edition
- Altera FPGA Board DEs-115 Cyclone IV series (first picture of this section)
- IR Beam Break Sensor (second picture of this section)
- Arduino LilyPad Buzzer (third picture of this section)
- User Manual (a link is provided in the references section)
- Breadboard
- Wires
- One pull up resistor; 10K ohms
- Patience; the Verilog code is not always easy to do
Step 2: Block Diagram and Module Break Down
See the attached PDF at the bottom of this section for the block diagram.
The alarm system is comprised of three modules; the main module, the display module, and the sound module. There are three states the system can be in: armed, disarmed and triggered.
The main module watches the inputs and changes the values of the state variables. The inputs for the armed and disarmed states are switches. The input for the triggered state is the break beam sensor. If the light beam is hitting the sensor, the input will be 1. In contrast, if the light beam is interrupted and no light hits the sensor, than the input will be 0 and the triggered state is changed to 1.
The display module will be given the values of the armed and disarmed states from the main module. If the armed input goes high (1) then the armed state will be changed to 1, and the word 'on' which will be shown in the seven segment display (SSD), which is located above the slide switches on the FPGA board. If the input goes low (0), the disarmed state will be changed to 1 and the SSD will show the word 'off'.
The sound module will also be given the values of the armed, disarmed and triggered states from the main module. If the armed state is 1 and the triggered state is 1, the alarm will sound. The sound will only turn off if the disarm state is changed to 1.
Step 3: Display Module
The display module will use the SSD to display if the alarm is 'ON' or 'OFF'. This used the values of the armed and disarmed state variables. Depending on the input, the module will light up certain segments of the display. Refer to the second picture of this section to know which segments will be lit. Refer to the first picture of this section to see what the SSDs look like when the segments are lit.
When the armed state is on (input is 1), two displays will be used, one for each letter of the word 'on'. The first display, all segments but number 6 will be lit. The second display will have segments 0, 1, 2, 4, and 5 lit (could also use segments 2, 4, and 6).
When the disarmed state is on (input is 1), three displays will be used; one for each letter of the word 'off'. The first display will be the same as the first display for when the system is on. The second and third displays will both have segments 0, 4, 5, 6 will be lit.
The SSD are low level sensitive, meaning they light up when they are 0. The labels in the second picture tell you the position in which the 0's should be placed to form the shape you want. For example, to make the letter 'n', segments 0, 1, 2, 4, and 5 must be lit, meaning all of those positions will be zero. The other positions, in this case positions 3 and 6, will be 1. Therefore to make the letter 'n' the 7 bit binary that will be fed to the pins is 0001001. Since each board is different, you may have to reserve the numbers in your board specifically, however this is how they're all supposed to work.
The pins needed for this project can be found on pages 36 to 38 of the Altera DE2-115 user manual. Notice that the SSD pins have 7 pins per display, such as HEX0[0] to HEX0[6]. Each position of the 7 bit binary number will each get one of these 7 pins. However, though the 7 bit binary number will go from position 0 to position 6, to get the right order of pins, they must count down.
HEX0[6] will be position 0, HEX0[5] will be position 1, etc.
The code is as follows:
module armedStatusDisplay(armedState, SSD, SSD1, SSD2);
input armedState;
output reg [6:0]SSD, SSD1, SSD2;
always @(armedState)
begin
SSD2 = 7'b0000001;
if(armedState == 1)
begin
SSD = 7'b1111111;
SSD1 = 7'b0001001;
end
else
begin
SSD = 7'b0111000;
SSD1 = 7'b0111000;
end
end
endmodule
Step 4: Sound Module
The sound module utilizes the LilyPad Buzzer. It receives inputs from the main module, and if certain conditions are met, it sounds the alarm. The main module recognizes if the alarm is armed (armed state = 1) and if the light hitting the IR break beam sensor has been interrupted while the system was armed (triggered state = 1). If both are 1, then the alarm will sound.
The code is as follows:
// code in alarm module is taken from
http://www.fpga4fun.com/MusicBox1.html and modified
module alarmSound(speaker, clk, triggeredState);
input clk;
input triggeredState;
output speaker;
parameter clkdivider = 25000000/440/2;
reg [23:0] tone;
always @(posedge clk)
if (triggeredState == 1)
tone<= tone+1;
reg [14:0] counter;
always @(posedge clk)
if (triggeredState == 1)
begin
if(counter==0)
counter<= (tone[23] ? clkdivider-1 : clkdivider/2-1);
else
counter<= counter-1;
end
reg speaker;
always @(posedge clk)
if (triggeredState == 1)
if(counter==0)
speaker<= ~speaker;
endmodule
Step 5: Main Module
This module pieces all of the other modules together to get the full alarm system. It receives information directly from the IR break beam sensor to determine the triggered state and recognizes whether or not the system is in an armed or disarmed state. The system is armed by slide switches on the bottom of the FPGA board; one pin to turn the system on, and one to turn the system off once it is set off. The pins for the switches can be found on pages 36 of the user manual.
This module gives input to both of the other modules.
The code is as follows:
// Main module
module finalproject(armedIn, beam, clk, disarmedIn, armedState, beamOut, disarmedState, speaker, SSD, SSD1, SSD2, triggeredState) ;
input armedIn; // SW0
input beam;
input clk;
input disarmedIn; // SW1
output regarmedState = 0; //LEDR17
output beamOut; //LEDG0
output regdisarmedState = 1; //LEDR16
output speaker;
output [6:0]SSD, SSD1, SSD2;
outputreg triggeredState = 0;
parameter on = 1;
parameter off = 0;
assign beamOut = beam; // indicated on ledg0 if the beam is broken
// watching all of the inputs
always @(armedIn, disarmedIn, beam)
begin
if (armedIn)
begin
armedState<= on;
disarmedState<= off;
end
if (disarmedIn)
begin
armedState<= off;
disarmedState<= on;
triggeredState<= off;
end
if ((beam == 0) && (armedState == 1) && (disarmedState == 0))
triggeredState<= on;
end
armedStatusDisplay display1(armedState,SSD,SSD1,SSD2); // displays the current state of the alarm on SSD
alarmSound alarm1(speaker, clk, triggeredState); // sound the alarm
endmodule
Step 6: Demonstration
Please watch the attached video to see a demonstration of our alarm system.
The full code is as follows:
module finalproject(armedIn, beam, clk, disarmedIn, armedState, beamOut, disarmedState, speaker, SSD, SSD1, SSD2, triggeredState) ;
input armedIn;
input beam;
input clk;
input disarmedIn;
output reg armedState = 0;
output beamOut;
output reg disarmedState = 1;
output speaker;
output [6:0]SSD, SSD1, SSD2;
output reg triggeredState = 0;
parameter on = 1;
parameter off = 0;
assign beamOut = beam; // indicated on ledg0 if the beam is broken
// watching all of the inputs
always @(armedIn, disarmedIn, beam)
begin
if (armedIn)
begin
armedState<= on;
disarmedState<= off;
end
if (disarmedIn)
begin
armedState<= off;
disarmedState<= on;
triggeredState<= off;
end
if ((beam == 0) && (armedState == 1) && (disarmedState == 0))
triggeredState<= on;
end
armedStatusDisplay display1(armedState,SSD,SSD1,SSD2); // displays the current state of the alarm on SSD
alarmSound alarm1(speaker, clk, triggeredState); // sound the alarm
endmodule
// code in alarm module is taken from http://www.fpga4fun.com/MusicBox1.html and modified
module alarmSound(speaker, clk, triggeredState);
input clk;
input triggeredState;
output speaker;
parameter clkdivider = 25000000/440/2;
reg [23:0] tone;
always @(posedge clk)
if (triggeredState == 1)
tone<= tone+1;
reg [14:0] counter;
always @(posedge clk)
if (triggeredState == 1)
begin
if(counter==0)
counter<= (tone[23] ? clkdivider-1 : clkdivider/2-1);
else
counter<= counter-1;
end
reg speaker;
always @(posedge clk)
if (triggeredState == 1)
if(counter==0)
speaker<= ~speaker;
endmodule
module armedStatusDisplay(armedState, SSD, SSD1, SSD2);
input armedState;
output reg [6:0]SSD, SSD1, SSD2;
always @(armedState)
begin
SSD2 = 7'b0000001;
if(armedState == 1)
begin
SSD = 7'b1111111;
SSD1 = 7'b0001001;
end
else
begin
SSD = 7'b0111000;
SSD1 = 7'b0111000;
end
end
endmodule
The full code in a .zip file is attached below.
Attachments
Step 7: References
Links for the IR break beam sensor picture:
http://www.adafruit.com/images/1200x900/2168.02.jpg
https://www.adafruit.com/products/2168
Link to information explaining the use of the IR sensor. Code is included on this page for use with Arduino. None of this code was used but it informed our general understanding of the sensor and the need for a pullup resistor.
https://learn.adafruit.com/ir-breakbeam-sensors
Links for the FPGA board picture:
http://www.terasic.com.tw/attachment/archive/502/image/image_88_thumb.jpg
http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=139&No=502
Link for the FPGA user manual:
ftp://ftp.altera.com/up/pub/Altera_Material/12.1/Boards/DE2-115/DE2_115_User_Manual.pdf
Links for the original picture of our team logo:
http://images.fineartamerica.com/images-medium-large-5/caffeine-molecule-kate-paulos.jpg
http://fineartamerica.com/featured/caffeine-molecule-kate-paulos.html
Link to Altera DE2 series datasheet for audio:
ftp://ftp.altera.com/up/pub/Altera_Material/11.1/University_Program_IP_Cores/Audio_Video/Audio.pdf
Link to code taken and modified from:
http://www.fpga4fun.com/MusicBox1.html
Sample sound codes:
http://marsohod.org/index.php/play-pmv
http://marsohod.org/index.php/notes-synt
Links to pictures used in this Instructable (in order of appearance)
- https://i.ytimg.com/vi/zk7RlcGGkK8/maxresdefault.jpg
- http://www.johnloomis.org/altera/DE2/segments.jpg
- http://previews.123rf.com/images/wamsler/wamsler1412/wamsler141200025/34571756-noise-warning-sign-grungy-style-vector-illustration-Stock-Vector.jpg
- http://www.clker.com/cliparts/1/d/6/5/1375477225215864851On-Switch.svg.med.png
- http://www.photonics.com/images/Web/Articles/2014/1/7/IRLight.jpg