ST AN1601 APPLICATION NOTE

AN1601

APPLICATION NOTE

SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

INTRODUCTION

This application note describes a software example for driving 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 slave

software

1-10 V

DALI slave board

DALI

 

master

 

board

DALI network

Rev. 1.1

AN1601/0404

1/23

1

SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

1 PROCESS OVERVIEW

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 checks whether the command is addressed to this ballast or not. If the command is addressed to this ballast the command handling 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

ST AN1601 APPLICATION NOTE

SOFTWARE IMPLEMENTATION FOR ST7DALI-EVAL

2 GENERAL STRUCTURE OF THE DALI SLAVE SOFTWARE

The following diagram shows the different software modules and their relationships.

Figure 1. General Block Diagram

 

 

 

PERIPHERAL

 

 

 

MODULES

Init

main. c

Inits

Dali

 

 

 

 

 

 

 

IT

 

Process

 

 

 

Command

 

clock_reset_

 

 

 

 

 

 

supply

 

DALI_CMD

 

ports

 

 

 

 

(DALI commands)

 

 

DALI_REG

 

 

main_clock_

(DALI registers)

 

 

contr

 

 

 

pwm_ar_timer

 

 

 

_12bit

 

DALI_PUB

 

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 FOR ST7DALI-EVAL

3 MODULE DESCRIPTIONS

3.1 MAIN.C MODULE

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 initialization routines in the other modules, then it calls the routines 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 parts, the management of the low voltage condition of the DALI BUS and fade rate plus the management of the new DALI frame reception.

The management of the low voltage condition and fade rate is obtained using a state 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 command is addressed to this ballast or not. If it is, it switches on the green LED and starts the command handling process; otherwise it switches on the red LED. Finally it resets the "dali_receive_status" flag to restart 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, another 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

a

command

 

Special

 

command

 

Other special

b

command

 

Command

 

Direct arc power

c

control command

 

Normal

 

command

 

Other normal

d

command

 

Notes:

 

a)“DALIP_Reserved_Special_Function” is called. This function is empty, it is reserved for future 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 three tables to avoid “long array” problems (this COSMIC problem has since been solved).

3.3 DALI_REG MODULE

In accordance with the DALI specification, some data variables giving information on the ballast 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 registers in the same way, wherever they are physically situated (ROM, EEPROM, RAM).

Normally you don’t need to use the functions of this module directly (you can access most of these registers using the functions defined for this purpose in the DALI_PUB module). However, 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 FOR ST7DALI-EVAL

3.4 PERIPHERAL MODULES

The purpose of these modules is to handle the different peripherals 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 declaration 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 calibrate the RC oscillator frequency. Two factory calibration values are stored 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 board. Please refer to the ST7FDALI datasheet, section DALI COMMUNICATION 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 registers (their reset values) in the EEPROM 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 don’t 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” module

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” module

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 autoreload timer is used for generating a PWM signal to control 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 according to the command received.

3.5 DALI_PUB MODULE

This module has to be modified (if needed) by the user. The following sections describe the main parts of the module.

3.5.1 ROM registers

According the DALI specification, the DALI “version number” and “physical min. level” registers 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 these values according to the ballast 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 represents the number of times that the function “DALIP_TimerCallback” will be called, but if you pass 0xFF the function will be called every 1ms non stop until the function “DALIP_DoneTimer” is called.

“DALIP_DoneTimer”: is used to stop the timer 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