STEVAL-ILL009V1 reference board
AN2531
26/40
8.6 Software
The software is written in C language with several modules, but the most important files for
proper operation of the STEVAL-ILL009V1 reference board are the following:
●
main.c
●
blink.c
●
pwm_ar_timer_12bit.c
●
spi.c
●
adc_8bit.c
Note:
The final code has slightly less than 1.4 KBytes and it will fit the ST7FLITE09 memory.
Main programming flowchart is shown in
. The program starts in main.c and
initializes the microcontroller functions such as RC oscillator calibration, ports initialization,
PWM AR timer setting for time base generation and SPI initialization (SPI clock frequency).
Afterwards, the interrupts are enabled and the program runs in a never-ending loop in
function blink.c.
Basically three interrupts can occur. First, an AR timer overflow interrupt, which generates
a time base 156 µs for the software dimming in order to have precise brightness regulation.
When this interrupt occur, the program checks if all data have been already sent through
SPI or not. If not the data are missed and the program waits for next interrupt (156 µs), but it
is only some kind of backup protection. The second interrupt is a SPI interrupt, which
informs that data (single byte) have been already sent. The last interrupt is an external input
interrupt, which detects that button was pressed.
Figure 15.
Main program flowchart
The heart of the software is a blink function running in a never-ending loop. In the start part
(
), the program waits until a PWM interrupt occurs during synchronization then the
Counter_SW value is incremented. Generally, Counter_SW represents the number of levels
for the software PWM modulation and in this case it is 64 (6-bit resolution) (described in
detail in
). The Brightness value set by potentiometer P2 is converted by the ADC
to a value between 0 and 64 in each SW PWM period (each 10 ms / 100 Hz) and this value
sets the PWM brightness on the Output Enable (OE) pin.
AM00296
FLOWCHARTS for the RGB color control board
MAIN
Microcontroller
initialization
Enable
interrupts
Main procedure
BLINK
AR_Timmer_OF
interrupt after
each 156 µs
All DATA
are sent
N
Y
Time base
ON
Return
All DATA are sent
YES
SPI interrupt
Return