DEE Laboratory 5. Project #2: Blink_LED Buttons, keyboards, events and interrupts. FSM structure and CLK synchronisation. |
1. Specifications | Planning | Dev. & test | Prototype | Report |
Design a LED blinker using Arduino.
|
Fig. 1. Blinker with ON/FF button ST and frequency selection switch P. |
NOTE: Other versions of the same project:
Blink_LED: Using PIC18F and bare-metal programming in C language
Blink_LED: Using PIC18F and MCC Melody
In this way we can observe how the main ideas and concepts for specifying and planning are very similar even if the final product is implemented using different technologies and tools.
Specifications | 2. Planning | Dev. & test | Prototype | Report |
We can select pins from the Arduino board. Only two external interrupts are available in the ATmega 328P chip, thus we connect ST_L push-button to the INT0. The switch P and the outputs W and W_L can be placed at any other digital pin. The chip's datasheet is available here and all the details on Arduino board UNO R3 model are accessed at these pages.
|
Fig. 2. Hardware circuit in Arduino: reset, OSC, P switch, ST_L push-button, W output, W_L output. |
We plan the project as an FSM to control the program flow. Thus, we may be able to imagine RAM variables, hardware-software diagram, state diagram, output logic, state logic, read inputs, write outputs and also the interrupt service routine to be able to detect ST click events.
|
Fig. 3. Hardware-software diagram and the required RAM variables. |
In this way, we can imagine how many states will be required to generate the corresponding outputs. the timing variable var_CLK_flag will be used only in Blinking state to generate the waveform var_W.
|
Fig. 4. Proposed state diagram. |
|
Fig. 5. State logic truth table and its equivalent flowchart. |
|
Fig. 6. Output logic truth table and its equivalent flowchart. |
|
Fig. 7. Interrupt service routine to interface the external button. |
Using the value var_P read from the switch we can set two frequencies for the output signal var_W.
|
Fig. 8. Timing functions to trigger the var_CLK_flag each timing period TP. |
Project location:
C:\DEE\LAB5\Blink_LED\(files)
Specs | Planning | 3. Dev. & 4. Test | Prototype | Report |
We can capture the circuit in Proteus "Blink_LED.pdsprj" using the available Arduino model.
|
Fig. 9. Hardware capture in Proteus. |
This is the source file translation "main.ino" that includes all the planning ideas. It is easy to imagine a single SWITCH-CASE statement to implement both, state_logic and output_logic truth tables in the same FSM_Blinking_LED() function.
This is the full project "Blinking_LED.zip" developed and simulated in Proteus.
We can compile using the Arduino IDE and obtain the ELF file to test the circuit performing Proteus simulations. Or instead, we can use directly the compiler embedded in Proteus to do the same task (Rebuild project top tap).
|
Fig. 10. Proteus schematic and source code windows in the same developing and simulation environment. |
We can run and check whether the application works. We can also execute step by step and use break points to visualise in detail the program flow and RAM variables.
|
Fig. 11. Proteus running the blinking LED application. For debugging purposes we can set up several instruments: logic analyser, frequency meter, watch window, virtual terminal, etc. |
- Measure how long does it take to run the main loop
- Measure the accuracy of the timing function using break points when the var_CLK_flag is set. We aim to generate 5 Hz and 200 Hz square waves.
Specs | Planning | Dev. & Test | 5.Prototype | Report |
Let us wire the Arduino board to an external switch P and push-button ST_L. We can solder in another universal PCB the LED W and W_L. We can program the ATmega328P chip from the Arduino IDE selecting the corresponding board and serial port.
|
Fig. 12. Uploading the program to the Arduino board. |
You can visualise the two blinking frequencies as usual using the compact instrument VB8012.
|
Fig. 13. Picture of the prototype operating along with a Tera terminal to monitor the serial port as a debugger. |
Alternatively, you can also upload the code to the board using the standard Arduino IDE, and use the the serial port as a debugger tool to show information on the current state and RAM variables.
Additional questions and experimentation:
1. Modify the parameters to generate a 2.4 kHz and 4.8 kHz square waves. Visualise them using the oscilloscope or the logic analyser.
2. Capture the push-button click signal. Analyse it to visualise signal bounce or noise that can interfere with the FSM.
3. Use the LAB5 PCB shield implemented in KiCad to solder all the components and repeat the experiment.
Specs | Planning | Dev. & Test | Prototype | 6. Report |