ST AN1601 APPLICATION NOTE

AN1601
APPLICATION NOTE
SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

INTRODUCTION

This application note des cribes a software ex ample for driv ing a DALI slave board using an ST7DALI (ST7LITE2 family) microcontroller. It is supplied with the kit ST7DALI-EVAL and can be ordered with the code ST7DALI-EVAL.
The software is written in C language and is compatible with both Metrowerks and Cosmic compilers.
Lamp-Ballast
DALI sl ave
1-10 V
software
DALI master board
DALI slave board
DALI network
Rev. 1.1
AN1601/0404 1/23
1
SOFTWARE IMPLEMENTATION FO R ST7DALI-EVAL

1 PROCESS OV ERVIEW

First of all, the DALI slave software initializes the slave system; afterwards, when the DALI master board sends a forward frame (basically 1 address byte and 1 data byte), and the DALI slave board receives the forward frame, a DALI interrupt (IT) is generated. This interrupt sets a flag, when this flag is set, the program che cks whether the c ommand is addr essed to this ballast or not. If the c ommand is a ddress ed to thi s ballast the comman d hand ling process is started and the DALI slave board reacts to the received command.
New frame arrival
Dali IT
Main.c
Process
command
DALI_CMD
2/23
2
SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

2 GENERAL STRUCTURE OF THE DALI S LA VE SOFTW ARE

The following diagram shows the different software modules and their relationships.
Figure 1. General Block Diagram
PERIPHERAL
MODULES
DALI_REG
(DALI registers)
Init
main. c
Process
Command
DALI_CMD
(DALI commands)
DALI_PUB
Inits
Dali
IT
clock_reset_
supply
ports
main_clock_
contr
pwm_ar_timer
_12bit
lite_timer_8bit
IT
EEPROM
Note: The names of DALI_CMD module functions are prefixed by DALIC_. DALI_REG module functions are prefixed by DALIR_, and DALI_PUB module functions are prefixed by DALIP_.
3/23
SOFTWARE IMPLEMENTATION FO R ST7DALI-EVAL

3 MODULE DE SCRIPTIONS

3.1 MAIN.C MODUL E

For DALI communication, the microcontroller has to monitor the low voltage state on the DALI bus (it is not allowed to be more than 500ms), and so it needs a process to differentiate a frame reception from a bus down.
This module calls all the ini tiali zation routines in the other modules, then i t calls the r outines to switch on the red and green LEDs on the board, and finally it enters an infinite loop.
This loop could be divided in two par ts, the managem ent of the low vo ltage condition of the DALI BUS and fade rate plus the management of the new D ALI frame reception.
The management of the low voltage condition and fade rate i s obtained using a st ate machine, synchronized with a period of 1 ms, in fact the lite_timer_IT_state variable is set to one every 1 ms.
To better understand how it works, please refer to Figure 12 in appendix A. To manage the DALI frame reception, it checks the "dali_receive_status" flag in order to see
if a new forward frame has been received by the microcontroller (MCU). If so, it calls the "DALIC_isTalkingToMe" function to check whether the comma nd is addressed to this ballast or not. If it is, it switches on the green LED and starts the command handling process; other­wise it switch es on the red LED. Fin ally it rese ts the "dali_ receive _statu s" flag to rest art the cycle.

3.2 DALI_CMD MODULE

The main purpose of this module is to handle the DALI commands. DALI_CMD contains several functions, most of them handle a particular DALI command, but
three of them are called from outside the module (from main.c):
1) The “DALIC_Init”, function initializes the ballast at its “POWER_ON_LEVEL”.
2) The “DALIC_isTalkingToMe” function, checks whether the command is addressed to this ballast or not.
3) The “DALIC_ProcessCommand” function is the first step in the process of executing a command. It checks if a repetition fault has occurred (according to the specification, an­other command between an expected repetition is ignored and leads to the cancellation of the repetition sequence) and it checks whether the command is a special one or a normal one.
The sequence continues as shown in Figure 2:
4/23
SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL
Figure 2. DALI_CMD Module Sequence
Reserved special command
a
Special command
Other special command
b
Command
Direct arc power
c
control command
Normal command
Other normal command
d
Notes:
a) DALIP_Reserved_Special_Function is called. This function is empty, it is reserved for fu-
ture needs. b) The function for handling a special command is called through the “special_jt” table. c) The “DALIC_Direct_Arc function handles this kind of command. d) The function for handling a normal command, is called through the “normal_jt” table (that
points to the function). Note: In the case of COSMIC compilation, this is divided into thr ee tabl es to avoid “long array
problems (this COSMIC problem has since been solved).

3.3 DALI_REG MODULE

In accordance with the DALI spec ification, some data variables giving information on the bal­last and its status have to be stored in memory; we refer to these variables as DALI registers.
The DALI_REG module handles the reading and writing of the DALI registers. It allows access to any of the DALI reg isters in the s ame wa y, whe rever t hey are physic ally sit uated ( ROM, EEPROM, RAM ).
Normally you dont need to use the functions of this module directly (you can access most of these registers using the functions defined for this pur pose in the DA LI_PUB module). H ow­ever, in case you need direct access to the registers, you can find the description of these functions and how to use them in Appendix B.
5/23
SOFTWARE IMPLEMENTATION FO R ST7DALI-EVAL

3.4 PERIPHERAL MODULES

The purpose of these modules is to handle the different peri pherals and hardware blocks of the MCU, each one is in charge of a specific block.
All these modules have the same file structure. Each module has three files:
xxx_hr.h where all or part of the registers and the register bits are defined. xxx.h that contains the d eclaration of the public functions and constants. xxx.c that contains the function routines.
(xxx represents the name of the module)

3.4.1 “clock_reset_supply” module

This module handles the RC Oscillator Control Register (RCCR) and the System Integrity Control/Status Register (SICSR). In the current version, it just configures the RCCR to cali­brate the RC oscillator frequency. Two factory calibration values are store d in the first two EEPROM addresses, however you can calibrate the RC with a different value. Please refer to the ST7FDALI datasheet SUPPLY, RESET AND CLOCK MANAGEMENT section for more details.

3.4.2 “dali” module

This module handles the DALI peripheral. It initializes the peripheral (DALI_Init function), and contains the DALI interrupt routine that
handles the arrival of a forward frame. It also contains the (Send_DALI_Frame) function that allows sending backward frames to the master boar d. Please refer to t he ST7FDALI da ­tasheet, section DALI CO MMUNICATION MODULE for more details.

3.4.3 “eeprom” module

This module handles the EEPROM of the MCU. It initializes the EEPROM, so it saves the DALI regi sters (their reset values) in the EE PR OM
the first time that the program is started. It also contains the functions in charge of the physical reading and writing of the EEPROM. When you use the EEPROM, you dont need to use these functions directly, since a group of functions for handling the EEPROM is defined in the DALI_PUB module.

3.4.4 “lite_timer_8bit” mod ule

This module handles the Lite Timer peripheral (Two 8-bit upcounters for timing purposes). In the current version, it just uses upcounter 1.
It initializes the Lite Timer so that the interrupt routine is run every 1 ms, this routine carries out the various countdowns required by the program.
6/23
SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

3.4.5 main_clock_contr mo dule

This module contains the Main Clock Control initialization routine that handles the Main Clock Control/Status Register (MCCSR). In the current version, it enables the MCO output clock; i.e. the CPU clock signal can be seen on this pin.

3.4.6 ports” module

This module handles the MCU I/O ports. In the current version of the software, this application just uses the PA1 and PA2 ports; they are used as outputs for switching the LEDs on and off, to indicate whether a forward frame has been addressed to this ballast or not.

3.4.7 pwm_ar_timer_12bit module

This module controls the 12-bit autoreload timer. In this application the 12-bit autorel oad timer is used for gene rating a PW M signa l to c ontrol
the power level of the lamp (the PWM duty cycle determines the DC output level of the slave board).
So, the purpose of this module is to initialize the timer and set up the PWM duty cycle ac­cording to the command received.

3.5 DALI_PUB MODULE

This module has to be m odified (if n eeded ) by the us er. The fol lowing sections desc ribe the main parts of the module.

3.5.1 ROM registers

According the DALI sp ecification, t he DA LI ve rsion numbe r a nd phy sical min. level re gis ­ters have to be stored in ROM, these two values are defined in this module by the “ROMRegs” table as follows: ROMRegs[]={0,25}, where the first value is the version number and the second is the physical min. level, you can modify thes e values according to the bal last used.

3.5.2 Fading functions

DALIP_LaunchTimer: starts a countdown in the Lite Timer interrupt routine (lite_timer_8bit module), so that the “DALIP_TimerCallback” function is called every 1ms. The parameter passed represent s the number of times th at the function “DA LIP_T imerCa llback” will be called, but i f you pass 0xF F th e fu nctio n wil l be called eve ry 1ms no n s top un til the functi on
DALIP_DoneTimer is c alled.DALIP_DoneTimer: is used to stop the tim e r started by DALIP_LaunchTimer. It should be
called as soon as the process is finished to let the MCU enter in SLOW-WAIT-MODE (in order to save power) if it has nothing more to do.
7/23
Loading...
+ 16 hidden pages