|
|||||
Chapter 3 problems |
- D3.3 - |
Designing a LED rotator (μC - C) |
|||
|
1. Specifications
(upgrade the text as the D2.6)
Our aim is to implement the LED rotator in Fig. 1 using a microcontroller PIC18F4520, C language and our programming style.
The same project designed using hardware is stated in D2.3.
The system operates by means of two control signals:
CE_ L = 1 (do nothing), CE_ L = 0 (run rotating)
SR_L = 0 (shift and rotate right), SR_L = 1 (shift and rotate left)
Fig. 1. LED rotator based on microcontroller PIC18F4520. |
Design phase #1: some questions to kick off the project and organise it as a FSM in four sections. You can conceive this project phase consisting of 3 design steps:
- step #1: continuous right rotation with also switch CE_L and external CLK signal (or push-button).
- step #2: Add switch SR_Lto be able to run rotating right and left.
- step #3: you can add an start/stop (ST) pushbutton, so that when clicking it the system will start running, and when clicking it again, it will stop when the end sequence is reached and LEDs show the initial code "10000000".
a) Draw the function table and the state diagram indicating state transitions and outputs.
b) Draw the hardware schematic. Buttons and switches, resistors, inputs SR_L, CE_L, outputs LED(7..0), reset circuit MCLR_L and quartz crystal oscillator of 8 MHz. Explain how to configure inputs and outputs in init_system().
c) Draw the hardware/software diagram indicating the required RAM variables and how the FSM is solved in software.
d) Draw the truth tables and their equivalent flowcharts for state_logic() and output_logic() functions.
e) What is the interrupt service routine ISR() used in this application? Draw its flowchart.
f) Develop and test (debugging) the project capturing the hardware circuit in Proteus and writting the C source code.
Design phase #2:
Let us add an LCD display to this application. The idea is to use several characters to represent an equivalent sequence rotation.
g) Enhance the schematic from design phase #1 to include an LCD attached to port D as studied in tutorials.
h) Enhance the software and the source file to drive the LCD.
In this design phase also two design steps may be conceived, for instance:
- step #1: Print ASCII messages on the LCD.
- step #2: Print as well the number of rotations (dynamic numerical data).
Design phase #3:
The external CLK is replaced by the internal 8-bit TMR2 peripheral to generate interrupts (TMR2IF).
i) Calculate TMR2 parameters required to generate a CLK of 2.5 Hz (var_CLK_flag period = 400 ms) to run the machine.
j) Add a new switch SP (speed) to be able to select between two different rotation periods: 400 ms and 40 ms.
Fig. 1. LED rotator. TMR0 (or TMR2) has replaced the external CLK circuit. |
Ideas on the solution are discussed in 1920Q1 EXA2 (P5)