ETC DRM004

Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Digitally Addressable
Lighting Interface
(DALI) Unit
Using the
MC68HC908KX8
Designer Reference
Manual
M68HC08
Microcontrollers
DRM004/D
Rev. 3.0, 3/2002
WWW.MOTOROLA.COM/SEMICONDUCTORS
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Digitally Addressable Lighting
Interface (DALI) Unit
Using the MC68HC908KX8
By: Magnus Grampp
Grampp R & D HB
Skimmelvagen 14
SE-252 86 Helsingborg
Sweden
Grampp R & D
Telephone: +46 42 913 95
Fax: +46 70 614 96 39
Email: [email protected]
Web: http://www.grampp.se
Motorola and the Stylized M Logo are registered trademarks of Motorola, Inc.
DigitalDNA is a trademark of Motorola, Inc.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
© Motorola, Inc., 2002
DRM004 — Rev. 3.0
3
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Revision History
To provide the most up-to-date information, the revision of our
documents on the World Wide Web will be the most current. Your printed
copy may be an earlier revision. To verify you have the latest information
available, refer to:
http://www.motorola.com/semiconductors
Freescale Semiconductor, Inc...
The following revision history table summarizes changes contained in
this document. For your convenience, the page number designators
have been linked to the appropriate location.
Revision History
Date
November,
2001
November,
2001
March,
2002
Revision
Level
1
Description
Page
Number(s)
5.5.3 DALI Module — Description reworded for clarity
57
Figure 3-11. cpu-Init( ) Flowchart — Clock frequency changed
from 9.8304 MHz to19.6608 MHz
40
F.4 Master: cpu.c — Code replaced
89
F.6 Master: dali.c — Code replaced
93
F.15 Master: rs232.c — Code replaced
113
G.5 Slave: cpu.c — Code replaced
122
G.7 Slave: dali.c — Code replaced
125
G.11 Slave: lamp.c — Code replaced
135
G.14 Slave: rs232.c — Code replaced
159
Appendix B. DALI Master Unit Schematic and Layout — Replaced
master schematic and master layout for readability.
71
Appendix D. DALI Slave Unit Schematic and Layout — Replaced
slave schematic and slave layout for readability.
79
G.11 Slave: lamp.c — Code changed to buffered PWM
135
2
3
DRM004 — Rev. 3.0
Digitally Addressable Lighting Interface (DALI) Unit
4
MOTOROLA
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
List of Sections
Section 1. General Description . . . . . . . . . . . . . . . . . . . . 19
Freescale Semiconductor, Inc...
Section 2. DALI Demonstration Board . . . . . . . . . . . . . . 23
Section 3. DALI Master Unit . . . . . . . . . . . . . . . . . . . . . . . 27
Section 4. DALI Protocol Standard . . . . . . . . . . . . . . . . . 45
Section 5. DALI Slave Unit . . . . . . . . . . . . . . . . . . . . . . . . 49
Section 6. PC Software . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Appendix A. DALI Instruction Set . . . . . . . . . . . . . . . . . . 67
Appendix B. DALI Master Unit Schematic
and Layout. . . . . . . . . . . . . . . . . . . . . . . . . . 71
Appendix C. DALI Master Unit Bill of Materials . . . . . . . 75
Appendix D. DALI Slave Unit Schematic
and Layout. . . . . . . . . . . . . . . . . . . . . . . . . . 79
Appendix E. DALI Slave Bill of Materials . . . . . . . . . . . . 83
Appendix F. DALI Master Unit Source
Code Files . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Appendix G. DALI Slave Source Code Files. . . . . . . . . 117
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
List of Sections
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
7
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Sections
DRM004 — Rev. 3.0
8
Digitally Addressable Lighting Interface (DALI) Unit
List of Sections
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Table of Contents
Freescale Semiconductor, Inc...
Section 1. General Description
1.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.3
Design Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4
Introduction to DALI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Section 2. DALI Demonstration Board
2.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3
Contents of the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4
System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.5
System Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.6
System Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.7
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Section 3. DALI Master Unit
3.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.4
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.4.1
Microcontroller Unit (MCU) . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4.2
DALI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4.3
Keyboard Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
9
Freescale Semiconductor, Inc.
Table of Contents
3.4.4
3.4.5
3.4.6
3.4.7
The LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Monitor Mode Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Freescale Semiconductor, Inc...
3.5
The Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
3.5.1
Main Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.5.2
Central Processor Unit (CPU) Module . . . . . . . . . . . . . . . . . 39
3.5.3
DALI Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.5.4
Keys Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.5.5
Liquid Crystal Display (LCD) Module . . . . . . . . . . . . . . . . . . 41
3.5.6
RS232 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6
Upgrading the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6.1
Board Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.2
Monitor Mode Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.3
Replacing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Section 4. DALI Protocol Standard
4.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.3
Electrical Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.4
Protocol Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Section 5. DALI Slave Unit
5.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.3
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.4
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.4.1
Microcontroller Unit (MCU) . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.2
DALI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.3
Lamp Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.4.4
RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
5.4.5
Monitor Mode Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.4.6
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
DRM004 — Rev. 3.0
10
Digitally Addressable Lighting Interface (DALI) Unit
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Table of Contents
5.5
The Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
5.5.1
Main Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.5.2
Central Processor Unit (CPU) Module . . . . . . . . . . . . . . . . . 57
5.5.3
DALI Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.4
Lamp Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.5
RS232 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Freescale Semiconductor, Inc...
5.6
Upgrading the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6.1
Board Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6.2
Reprogramming the Code . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Section 6. PC Software
6.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.3
Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.4
User manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.5
The Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Appendix A. DALI Instruction Set
Appendix B. DALI Master Unit Schematic and Layout
Appendix C. DALI Master Unit Bill of Materials
Appendix D. DALI Slave Unit Schematic and Layout
Appendix E. DALI Slave Bill of Materials
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
11
Freescale Semiconductor, Inc.
Table of Contents
Freescale Semiconductor, Inc...
Appendix F. DALI Master Unit Source Code Files
F.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
F.2
Master: common.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
F.3
Master: cpu.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
F.4
Master: cpu.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
F.5
Master: dali.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
F.6
Master: dali.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
F.7
Master: dali.lkf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
F.8
Master: iokx8.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
F.9
Master: keys.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
F.10
Master: keys.c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
F.11
Master: lcd.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
F.12
Master: lcd.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
F.13
Master: main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
F.14
Master: rs232.h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
F.15
Master: rs232.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
F.16
Master: vector.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Appendix G. DALI Slave Source Code Files
DRM004 — Rev. 3.0
12
G.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
G.2
Slave: command.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
G.3
Slave: common.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
G.4
Slave: cpu.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
G.5
Slave: cpu.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
G.6
Slave: dali.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
G.7
Slave: dali.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Digitally Addressable Lighting Interface (DALI) Unit
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Table of Contents
G.8
Slave: dali.lkf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
G.9
Slave: iokx8.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131
G.10 Slave: lamp.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134
G.11 Slave: lamp.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
G.12 Slave: main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
G.13 Slave: rs232.h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158
Freescale Semiconductor, Inc...
G.14 Slave: rs232.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159
G.15 Slave: vector.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
13
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Table of Contents
DRM004 — Rev. 3.0
14
Digitally Addressable Lighting Interface (DALI) Unit
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
List of Figures
Freescale Semiconductor, Inc...
Figure
Title
1-1
The DALI Bus System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2-1
2-2
The DALI Demonstration Board . . . . . . . . . . . . . . . . . . . . . . . .24
The LCD Display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3-1
3-2
3-3
3-4
3-5
3-6
3-7
3-8
3-9
3-10
3-11
DALI Master Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
DALI Transmit Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
DALI Receive Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Keyboard Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Monitor Mode Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
DALI Master Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
main( ) Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
cpu-Init( ) Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
4-1
4-2
DALI Master Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
DALI Slave Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5-1
5-2
5-3
5-4
5-5
5-6
5-7
5-8
5-9
DALI Slave Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
LED Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
DALI Transmit Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
DALI Receive Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Lamp Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Monitor Mode Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
DALI Slave Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Page
List of Figures
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
15
Freescale Semiconductor, Inc.
List of Figures
Freescale Semiconductor, Inc...
Figure
DRM004 — Rev. 3.0
16
Title
Page
5-10
5-11
main( ) Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56
lamp_WriteFlash( ) Flowchart . . . . . . . . . . . . . . . . . . . . . 59
6-1
DALI Demo Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
B-1
B-2
DALI Master Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
DALI Master Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
D-1
D-2
DALI Slave Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
DALI Slave Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Digitally Addressable Lighting Interface (DALI) Unit
List of Figures
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
List of Tables
Freescale Semiconductor, Inc...
Table
Title
2-1
Examples of DALI Commands . . . . . . . . . . . . . . . . . . . . . . . . . 26
4-1
4-2
Description of Stored Parameters. . . . . . . . . . . . . . . . . . . . . . . 46
Type of Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5-1
Default Values for the User Defined Data. . . . . . . . . . . . . . . . . 58
6-1
DALI Messages Used in the DALI Demo Application . . . . . . . . 65
A-1
A-2
Standard Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Special Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
C-1
DALI Master Bill of Materials . . . . . . . . . . . . . . . . . . . . . . . . . . 75
E-1
DALI Slave Bill of Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Page
List of Tables
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
17
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Tables
DRM004 — Rev. 3.0
18
Digitally Addressable Lighting Interface (DALI) Unit
List of Tables
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 1. General Description
Freescale Semiconductor, Inc...
1.1 Contents
1.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.3
Design Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.4
Introduction to DALI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
1.2 Introduction
This document defines the reference design for a low-cost DALI (Digital
Addressable Lighting Interface). It shows how to use the Motorola
MC68HC908KX8/KX2 in a master-slave configuration where the units
are communicating with a simple protocol. The communication protocol,
the hardware, and the software are described in this document and
although the application is intended for illumination control, the structure
is also applicable for similar purposes.
1.3 Design Overview
The design is divided into two separate units a DALI master unit and a
DALI slave unit. The DALI slave unit can set the luminosity of a
connected lamp. The desired brightness level is set by the DALI master
unit, which has a simple human interface consisting of a four-digit liquid
crystal display (LCD), two shaft encoders, and a push button. The DALI
master unit sends the wanted values to the connected DALI slave units.
The communication is based around the DALI standard, which is an
asynchronous, half-duplex, serial protocol over a two-wire differential
bus. See Figure 1-1.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
General Description
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
19
Freescale Semiconductor, Inc.
General Description
DALI
SLAVE
DALI
SLAVE
DALI
SLAVE
Freescale Semiconductor, Inc...
DALI
MASTER
Figure 1-1. The DALI Bus System
The software is re-programmable by using the built-in monitor mode
interface. Both the DALI master unit and the DALI slave unit can be
controlled through an RS232 interface.
A DALI demonstration board consisting of a DALI master unit and four
DALI slave units is obtainable through Motorola.
1.4 Introduction to DALI
The lighting industry has developed a new standard for communication
with electronic ballast (ECG). It is an interface standard for
communication between a controller and the ECGs. This standard goes
by the name of DALI (Digital Addressable Lighting Interface) and it will
be included as an appendix to ECG standard IEC 929.
DALI is designed for the use of standard components and for simple
wiring which means low costs.
Fields of application may be:
DRM004 — Rev. 3.0
20
•
Day lighting and night lighting
•
Different lighting for varying activities in multi-purpose rooms such
as hotels, conference rooms, etc.
•
Possibilities of dimming the lights and increasing the lighting
according to requirements
Digitally Addressable Lighting Interface (DALI) Unit
General Description
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
General Description
Introduction to DALI
•
Properly adjusted light settings depending on the direction of the
daylight (e.g., in the morning, at noon, in the afternoon)
•
Energy savings
Freescale Semiconductor, Inc...
The DALI installation is based on the master-slave principle:
•
The user operates the system through the controller (master).
•
The controller sends messages to all the ECGs (slaves)
containing an address and a command.
•
The address determines whether the ECG should listen.
•
Each ECG is digitally addressed and therefore is insensitive to
electromagnetic noise (compare with an analogue 1–10-volt
system).
For instance, the command could be current brightness value or lamp on
or lamp off. Lighting values and group assignment will be stored in the
ECGs.
The ECGs may be assigned up to sixteen freely definable groups and
each group can store up to sixteen different lighting values for the
lighting scenes. Each ECG can be assigned to more than one group.
There may be up to 64 ECGs per each controller.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
General Description
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
21
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
General Description
DRM004 — Rev. 3.0
22
Digitally Addressable Lighting Interface (DALI) Unit
General Description
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 2. DALI Demonstration Board
Freescale Semiconductor, Inc...
2.1 Contents
2.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3
Contents of the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.4
System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.5
System Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.6
System Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.7
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.2 Introduction
This section describes how to connect and use a DALI (Digital
Addressable Lighting Interface) demonstration board. A DALI
demonstration board can be obtained through Motorola. It is always
delivered with the software already loaded so only a power supply and
four lamps have to be connected to get the system started.
NOTE:
It is necessary to read this section to get an understanding of the system
even if you do not have a demonstration board.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Demonstration Board
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
23
Freescale Semiconductor, Inc.
DALI Demonstration Board
2.3 Contents of the System
Five printed circuit cards and the cables connecting them are mounted
on the DALI demonstration board.
Freescale Semiconductor, Inc...
The system also consists of:
•
One 4-wire cable for communication with a PC, see Section 6. PC
Software
•
One 6-wire cable for replacing the software, see 3.6 Upgrading
the Software (Master) and 5.6 Upgrading the Software (Slave)
•
CD-ROM containing all software and documentation
2.4 System Overview
The DALI demonstration board consists of a DALI master unit and four
DALI slave units. They are connected through a 2-wire DALI network.
The master unit controls all the slave units and each slave unit can
control a lamp. See Figure 2-1.
SLAVE UNITS
MASTER UNIT
Figure 2-1. The DALI Demonstration Board
DRM004 — Rev. 3.0
24
Digitally Addressable Lighting Interface (DALI) Unit
DALI Demonstration Board
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Demonstration Board
System Installation
2.5 System Installation
Freescale Semiconductor, Inc...
The system has to be powered from an external source. The
requirement for this supply is 12 V (10–14 V) DC. The power
consumption is dependent on the number and size of the connected
lamps. The master and slave boards without the lamps connected
consume less then 500 mA.
Use any 12-V lamps with a power consumption equal to or less than
10 W. A 12-V/10-W halogen light bulb would be a good choice. The
power supply has to be dimensioned according to this. Mascot 9120/12
is sufficient for this purpose but several other power supplies that meet
the above criteria can be used.
Connect the lamps to the 2-way Phoenix screw terminal for each slave
unit and connect the power supply to the terminal socket (12 V to red
cable and 0 V to black cable).
2.6 System Operation
After connecting the power supply the system starts in its default mode.
Every slave unit should light its connected lamp and the LED should be
lit showing that the slave unit is running.
The LCD on the master unit should show 00:00 (see Figure 2-2). The
system is now ready to accept commands according to the DALI
standard.
ADDRESS
COMMAND
Figure 2-2. The LCD Display
The LCD on the master shows data to be sent to the slave as two
hexadecimal numbers. Normally this is an address followed by a
command. By turning the shaft encoders the address and the command
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Demonstration Board
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
25
Freescale Semiconductor, Inc.
DALI Demonstration Board
Freescale Semiconductor, Inc...
can be changed. Pushing the button on the right side of the shaft
encoders sends the data to the slave units. The data sent may result in
an answer from the slave. This is shown on the LCD as “Axx” where xx
stands for a hexadecimal number.
For more information regarding addressing modes and commands see
Section 4. DALI Protocol Standard. Address 0xFF and command
0xFF have a special meaning in this system. Selecting this initializes a
demo sequence, where the master automatically sends a command to
change the scene, with 3 second's interval. It starts with scene 0 and
continues until scene 15 and after that it starts with scene 0 again. This
will continue until new data is selected.
If an individual lamp is to be addressed the factory settings for the short
addresses of the slave units are 0, 1, 2, and 3.
2.7 Examples
Here are some examples to test the system. Enter the address and the
command according to Table 2-1 using the shaft encoders and push
button.
Table 2-1. Examples of DALI Commands
DRM004 — Rev. 3.0
26
Address
Command
Action
FE
E6
Set the light level to E6 (approximately 50%)
on all lamps
02
FE
Set lamp 3 to 100% light level
FF
01
Dim up all lamps for 200 ms
01
00
Turn off lamp 1
07
92
Check if lamp 4 is working
(No answer means YES, A FF means NO)
Digitally Addressable Lighting Interface (DALI) Unit
DALI Demonstration Board
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 3. DALI Master Unit
Freescale Semiconductor, Inc...
3.1 Contents
3.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.4
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.4.1
Microcontroller Unit (MCU) . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4.2
DALI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.4.3
Keyboard Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4.4
The LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4.5
The RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.4.6
Monitor Mode Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.4.7
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.5
The Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
3.5.1
Main Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.5.2
Central Processor Unit (CPU) Module . . . . . . . . . . . . . . . . . 39
3.5.3
DALI Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.5.4
Keys Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.5.5
Liquid Crystal Display (LCD) Module . . . . . . . . . . . . . . . . . . 41
3.5.6
RS232 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6
Upgrading the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6.1
Board Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.2
Monitor Mode Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.3
Replacing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
27
Freescale Semiconductor, Inc.
DALI Master Unit
3.2 Introduction
Freescale Semiconductor, Inc...
This section describes the design, hardware, and software of the DALI
(Digital Addressable Lighting Interface) master unit. The unit has a
human interface consisting of:
•
4-digit liquid crystal display (LCD)
•
Two shaft encoders
•
A push button
With these, the operator could select and address a DALI command to
be sent over the DALI interface. The master unit also has an RS232
interface for communicating with a PC and a monitor mode interface to
enable download of new software.
3.3 Features
The master unit is designed as a multi-purpose communication
controller with these features:
•
A MC68HC908KX8
•
A display composed of a 4-digit LCD
•
A keyboard composed of two shaft encoders and a push button
•
A DALI interface
•
A RS232 interface
•
A monitor mode interface
•
A small wire and wrap area for custom extensions
Refer to Section 2. DALI Demonstration Board for a description of
how to use the DALI master unit.
DRM004 — Rev. 3.0
28
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Hardware
3.4 Hardware
Freescale Semiconductor, Inc...
The DALI master unit is built around the MC68HC908KX8. Connected to
the central processor unit (CPU) are:
•
DALI interface
•
Keyboard interface
•
LCD interface
•
RS232 interface
•
Monitor mode interface
The RS232 and the monitor mode interfaces are electrically isolated
from the rest of the unit. This is done to enable the DALI slave unit to use
the same circuitry. Therefore, to use these interfaces separate cabling
has to be connected. See Figure 3-1.
DALI
INTERFACE
RS232
INTERFACE
LCD
CPU
MONITOR
MODE
INTERFACE
KEYBOARD
POWER
SUPPLY
Figure 3-1. DALI Master Unit
Schematics, layout, and parts list can be found in Appendix B. DALI
Master Unit Schematic and Layout and in Appendix C. DALI Master
Unit Bill of Materials.
The hardware design is intended for demonstration purposes only. It is
functional in a normal office environment. There are many possibilities to
improve the design for increased functionality and reliability. Costs can
be reduced for high volume production.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
29
Freescale Semiconductor, Inc.
DALI Master Unit
3.4.1 Microcontroller Unit (MCU)
Freescale Semiconductor, Inc...
The MCU used in this design is the MC68HC908KX8, that has these
advantages:
•
Low pin count
•
Internal clock oscillator
•
Embedded FLASH memory (8 Kbytes) which can be used for both
code and data
•
Embedded random-access memory (RAM) (192 bytes)
•
In-circuit programmable through the monitor mode interface
•
M68HC08 compatible code
As all members of the M68HC08 Family, it has compact and fast
executing code as well as several development and support tools
available from both Motorola and third parties.
The possibility of writing data into the FLASH memory during program
execution is used in this application. However, the advantage of having
an internal oscillator is not fully realized in this application. The most
common reason for adjusting the clock frequency is to save power.
Another reason for using an internal oscillator is to save space. If saving
space is not necessary, than devices like the MC68HC908JK3 with
external clock generation can be used to achieve the same design. This
processor has a slightly bigger package (20 pins instead of 16 pins with
one extra input/output (I/O)) but is a good alternative for this application.
Since the size of the code is less than 2 Kbytes, the MC68HC908KX2
could also be an alternative.
More information regarding the CPU can be found in the
MC68HC908KX8, MC68HC908KX2 HCMOS Microcontroller Unit
Technical Data, Motorola order number MC68HC908KX8/D.
DRM004 — Rev. 3.0
30
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Hardware
3.4.2 DALI Interface
The DALI interface has one circuit for transmitting (see Figure 3-2) and
one circuit for receiving (see Figure 3-3).
The transmission consists mainly of a power transistor (T1) for switching
the power on and off. The power transistor is regulated by two transistors
(T2 and T3).
Freescale Semiconductor, Inc...
One of the two transistors (T3) is controlled from the processor (PTB7)
through an inverter (IC4). A low signal from the processor gives a high
signal after the inverter. This high signal opens the transistor (T3) which
switches off the power transistor (T1). A high signal from the processor
gives a low signal after the inverter, closing the transistor (T3) and
switching on the power transistor (T1).
The other transistor (T2) is controlled by the current flowing through the
resistor (R1). If a DALI slave unit is connected, this current will be the
same as that flowing through the power transistor. The value of the
resistor is chosen in such a way that when the current exceeds 250 mA
the voltage level across the resistor will open the transistor (T2) which in
its turn closes the power transistor (T1). In this way the current is
maximized to 250 mA.
12 V
T1
DALI
T2
PTB7
IC4
T3
R1
0V
0V
0V
0V
Figure 3-2. DALI Transmit Circuit
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
31
Freescale Semiconductor, Inc.
DALI Master Unit
The comparator (IC3) handles the reception and sends the received
signal to the processor (IRQ1 and PTB6). If very accurate voltage levels
are to be achieved the surrounding resistors should be trimmed. The
inverter (IC4) converts the signals to the correct logical level.
12 V
Freescale Semiconductor, Inc...
10 V
0V
IRQ1
PTB6
IC3
DALI
IC4
0V
Figure 3-3. DALI Receive Circuit
NOTE:
DRM004 — Rev. 3.0
32
The interface has no protection against over voltage and no
electromagnetic interference (EMI) suppression.
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Hardware
3.4.3 Keyboard Interface
The master unit can receive user command through a push button (S1)
and two shaft encoders (S2 and S3). They are connected to the
processor (PTA0–PTA4). See Figure 3-4.
PTA4
Freescale Semiconductor, Inc...
PTA3
S2
0V
PTA1
PTA2
S3
0V
PTA0
S1
0V
0V
Figure 3-4. Keyboard Interface
3.4.4 The LCD Interface
The LCD (DIS1) is controlled by the processor (PTB0–PTB2) through
the LCD driver circuit (IC5). See Figure 3-5.
PTB0
PTB1
PTB2
CLOCK
LOAD
IC5
DATA
DIS1
Figure 3-5. LCD Interface
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
33
Freescale Semiconductor, Inc.
DALI Master Unit
3.4.5 The RS232 Interface
Freescale Semiconductor, Inc...
The RS232 interface is connected to the processor (PTB4 and PTB5)
and a pin header (JP4). With a cable it can be connected to the RS232
driver circuit (IC6) through the pin header JP5. The external connection
is by way of a D-sub connector (X3). The RS232 interface is not
protected against over voltages, different ground potential or EMI
interference. Connect the cable when the system is not powered. See
Figure 3-6.
12 V
PTB4/RXD
IC6
PTB5/TXD
JP4
JP5
X3
0V
Figure 3-6. RS232 Interface
DRM004 — Rev. 3.0
34
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Hardware
3.4.6 Monitor Mode Interface
Freescale Semiconductor, Inc...
The monitor mode interface is connected to the processor (PTA0, PTA1,
PTB6, and IRQ1) if all four switches on the DIP-switch are off and a
cable is connected between the pin header JP1 and pin header JP6.
Connect the cable when the system is not powered. When power is
returned, the processor is in monitor mode (see MC68HC908KX8,
MC68HC908KX2 HCMOS Microcontroller Unit Technical Data,
Motorola order number MC68HC908KX8/D for more information). The
communication with the processor during the monitor mode goes
through the D-sub (X2), the RS driver circuit (IC6), and the buffer (IC7).
The crystal oscillator (QG1) ensures that the RS232 communication
speed is 9600 baud. See Figure 3-7.
IC7
IC6
X2
0V
12 V
12 V
PTA1
0V
PTA0
VTST
IRQ0
PTB6/OSC1
JP1
0V
JP6
9.8304 MHz
QA1
0V
Figure 3-7. Monitor Mode Interface
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
35
Freescale Semiconductor, Inc.
DALI Master Unit
3.4.7 Power Supply
Freescale Semiconductor, Inc...
The linear regulator (IC2 and IC8) makes the 5-volt conversion. There is
no external protection against over voltages or EMI interference but the
diode D1 serves as protection against wrong polarity. The input voltage
can vary between 7 and 30 volts for the 5-volt conversion but the DALI
interface requires that the voltage be kept within 10 to 14 volts. See
Figure 3-8.
5V
12 V
IC2/IC8
D1
0V
0V
Figure 3-8. Power Supply
3.5 The Software
The software handles the DALI, the RS232 communication tasks, and
the human interface. It is based around a main module that first initializes
common variables and the utility modules then goes into an endless
loop. The different utility modules are updated through interrupts. If an
event occurs in one utility module which leads to the need to act in
another utility module, a flag is set. The main module scans these flags
and takes action accordingly. No call is made directly from one utility
module to another. Since the structure is based on what action the
different software modules will do, several processor dependent
functions (TIM, ADC, etc.) may be used in one module. See Figure 3-9.
The source code can be viewed in Appendix F. DALI Master Unit
Source Code Files.
DRM004 — Rev. 3.0
36
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
The Software
CPU
DALI
MAIN
KEYS
Freescale Semiconductor, Inc...
LCD
RS232
Figure 3-9. DALI Master Software
All code is written in C language except for the startup routine. The
assembler, compiler, and linker used are from COSMIC Software which
can be found at:
http://www.cosmic-software.com
NOTE:
There is also the possibility of using software from Metrowerks which
can be found at:
http://www.metrowerks.com
3.5.1 Main Module
The main module consists of initializing global variables, calls to
initializing routines in other modules, and an eternal loop. In the eternal
loop different flags are checked to see if an action has to be taken. The
computer operating properly (COP) watchdog counter is also cleared in
the loop. See Figure 3-10.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
37
Freescale Semiconductor, Inc.
DALI Master Unit
INITIALIZE
VARIABLES
INITIALIZE
MODULES
Freescale Semiconductor, Inc...
ENABLE
INTERRUPTS
LIGHT LED
CLEAR COP
YES
SHOW NEW DATA
ON LCD
YES
SEND DATA
ON DALI
YES
SHOW ANSWER
ON THE LCD
YES
SHOW ERROR
ON THE LCD
NEW DATA?
NO
SEND?
NO
ANSWER?
NO
ERROR?
NO
Figure 3-10. main( ) Flowchart
DRM004 — Rev. 3.0
38
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
The Software
3.5.2 Central Processor Unit (CPU) Module
Freescale Semiconductor, Inc...
The CPU module is responsible for setting up the processor correctly.
This includes:
•
LVI (power supervision)
•
Port direction
•
Port data
•
Built-in pullup resistor
•
IRQ1 interrupt
•
Internal clock speed
If the clock has not previously been trimmed this is handled in the
module. The clock trim value is stored in the FLASH by using the on-chip
FLASH programming routines. The call is made by calling
clock_write( ) which is defined as follows:
#define clock_write() _asm("ldhx #$FDFF\njsr $1009\n")
See Figure 3-11.
For more information regarding the on-chip routines, refer to the
Motorola Application Note entitled Using MC68HC908 On-Chip FLASH
Programming Routines, Motorola order number AN1831/D.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
39
Freescale Semiconductor, Inc.
DALI Master Unit
ENABLE LVI
TRIMMED?
NO
DISABLE COP
YES
READ TRIM VALUE
FROM FLASH
YES
Freescale Semiconductor, Inc...
INITIALIZE PORTS
AND DISABLE IRQ1
CHANGE CLOCK
TO 19.6608 MHz
TRIMMED?
NO
EXIT
SET TRIM VALUE
AND INITIALIZE SCI
SEND CHARACTER
0x55 ON SCI
BREAK
SIGNAL?
YES
INCREASE TRIM
VALUE
NO
DALI
SHORTED?
YES
WRITE TRIM
VALUE TO FLASH
NO
EXIT
Figure 3-11. cpu-Init( ) Flowchart
DRM004 — Rev. 3.0
40
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Upgrading the Software
3.5.3 DALI Module
The DALI communication is handled in the DALI module. Several parts
of the processor are used. Incoming data is detected by an IRQ interrupt.
Then this data is sampled with an interval (4800 times per second) set
by the timebase module (TBM). The timebase module also controls the
transmission. If data is to be repeated this is handled in the DALI module.
Freescale Semiconductor, Inc...
3.5.4 Keys Module
The keys module detects changes to the shaft encoders or the use of the
push button. The push button is simply handled by the keyboard
interrupt module (KBI). This is not possible with the shaft encoders since
it is impossible to determine which of the shaft encoders were rotated
using only one common interrupt. The need for more interrupt sources is
solved by enabling the input capture capability of the timer interface
module (TIM).
3.5.5 Liquid Crystal Display (LCD) Module
The LCD is controlled through the driver circuit by the LCD module. The
data is clocked into the shift register of the driver circuit by toggling the
PTB output pins.
3.5.6 RS232 Module
The RS232 module handles the serial communication over RS232. It
uses the serial communication interface module (SCI). The baud rate is
preset to 9600 baud.
3.6 Upgrading the Software
To be able to reprogram the software, the processor has to be set into a
monitor mode. The monitor mode is a state of the processor where
simple debugging and downloading of new code is possible. During the
monitor mode, the processor is running a built-in program that
communicates through a single pin. The monitor mode is described in
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
41
Freescale Semiconductor, Inc.
DALI Master Unit
more detail in the document MC68HC908KX8, MC68HC908KX2
HCMOS Microcontroller Unit Technical Data, Motorola order number
MC68HC908KX8/D.
3.6.1 Board Configuration
Freescale Semiconductor, Inc...
To configure the board in monitor mode:
•
Disconnect the power supply and connect a free serial
communication port of the PC (or the computer that
communicates with the processor) to the D-sub on the DALI
master unit marked “Monitor” using a serial communication cable.
•
Connect a cable between JP1 and JP6 (see Appendix B. DALI
Master Unit Schematic and Layout).
•
Set the DIP switch to “OFF”.
When the power supply is reconnected the processor is in the monitor
mode.
After exiting monitor mode, the cable between the pin headers has to be
removed and the DIP switch has to be set to “ON” to return to normal
mode.
3.6.2 Monitor Mode Software
There is freely available software for the PC environment that cares
about the most common tasks during the monitor mode. The program
“PROG08SZ” from P&E Microcomputer Systems, Inc.
(http://www.pemicro.com) will work fine if the main task is to download
new software to the DALI modules. With that software you define the
DALI unit as a Class III board. The monitor mode interface is prepared
for a communication speed at 9600.
DRM004 — Rev. 3.0
42
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit
Upgrading the Software
3.6.3 Replacing the Code
By using monitor mode software, the FLASH memory of the DALI master
unit can be erased and new software downloaded. After a successful
replacement of the code the internal clock has to be trimmed.
Freescale Semiconductor, Inc...
The internal clock generator of the processor has a tolerance of ±25%.
This can be trimmed down to ±2%. In the process of loading new
software the trim values are corrupted. Since the system is dependent
on correct communication speed, a trimming has to take place before
the code can be executed properly. This is done through the RS232
interface, the DALI interface, and by using an oscilloscope.
•
Connect the computer to the D-sub on the DALI master unit
marked “Serial”.
•
Connect a cable between JP4 and JP5 (see Appendix B. DALI
Master Unit Schematic and Layout).
•
Connect the oscilloscope between ground and PTB5/TXD on the
DALI unit.
A PC program that can generate a break signal on the serial
communication port is also needed. When the system is powered a
square-wave signal, which should be slightly larger than 2400 Hz, is
visible on the oscilloscope. The frequency should be changed until it is
between 2385 and 2415 Hz. Sending a break signal does this. For each
break signal the frequency is lowered by about 5 Hz. When the correct
frequency is achieved the trim value can be stored by making a
temporary short-circuit across the DALI signal wires. The next time the
unit is restarted the clock is automatically trimmed and the execution of
the program is normal.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
43
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Master Unit
DRM004 — Rev. 3.0
44
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 4. DALI Protocol Standard
Freescale Semiconductor, Inc...
4.1 Contents
4.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.3
Electrical Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.4
Protocol Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2 Introduction
This section describes the main properties of the DALI (Digital
Addressable Lighting Interface) protocol. More information regarding
the DALI protocol can be found in the document A.C.-Supplied
Electronic Ballast for Tubular Fluorescent Lamps, Performance
Requirement, Requirements for Controllable Ballasts which can be
obtained from IEC.
Some major characteristics of the DALI protocol are:
•
Asynchronous serial protocol
•
1200 baud, bi-phase encoding, half-duplex
•
Two-wire differential
•
Voltage difference above 9.5 V means high level
•
Voltage difference below 6.5 means low level
•
The master unit controls the communication
•
64 slave units can be connected
•
Each slave unit can be individually addressed
•
The master unit sends 1 start bit, 16 bit data, and two stop bits
•
The slave unit sends 1 start bit, 8 bit data, and two stop bits
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Protocol Standard
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
45
Freescale Semiconductor, Inc.
DALI Protocol Standard
4.3 Electrical Specification
Freescale Semiconductor, Inc...
The DALI communication is serial using two wires for communicating in
both directions. The voltage difference between the wires indicates if it
is a high or low level. A voltage difference above 9.5 V is a high level and
a voltage difference less than 6.5 V is a low level. The master unit
communicates with the slave units by setting the level high or low
according to the serial protocol described in 4.4 Protocol Specification.
When no communication takes place the master unit keeps the level
high.
The slave unit responds to the master unit by setting the level high or
low. A high level is simply achieved by not interfering with the high level
set by the master unit. A low level is obtained by forcing a short circuit
across the wires. This is possible to do since the DALI standard states
that the current supply for the DALI communication has to be limited to
250 mA.
Simultaneous communication is not possible since there is only one pair
of wires.
4.4 Protocol Specification
There are a number of parameters stored in each slave unit (see
Table 4-1). These parameters indicate how the lamp should behave in
different situations.
Table 4-1. Description of Stored Parameters
Type of Parameter
DRM004 — Rev. 3.0
46
Description
Actual dim level
The current light level of the lamp or physically the arc
power level.
Power on level
The light level to use when powering up the slave
System failure level
The light level to use if the communication fails
Minimum level
The minimum allowed light level
Maximum level
The maximum allowed light level
Digitally Addressable Lighting Interface (DALI) Unit
DALI Protocol Standard
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Protocol Standard
Protocol Specification
Table 4-1. Description of Stored Parameters (Continued)
Freescale Semiconductor, Inc...
Type of Parameter
Description
Fade rate
The speed to change the light level during a certain time
interval
Fade time
The time between the change of light levels
Short address
The individual address of a unit
Search address
An address used during address initialization
Random address
An address used during address initialization
Group
A value indicating which group the slave belongs to
(16 bits)
Scene
Light levels for different scenes (16 bytes)
Status information
Holds the current status information regarding the slave
Version number
The currently implemented DALI protocol version number
Physical minimum
level
The smallest allowed physical arc power level
Messages can be sent over the DALI communication wires to change or
check the values.
The serial communication speed is 1200 baud with bi-phase encoding.
All communication is controlled from a master. Every lamp is connected
to a slave unit that is silent until the master requires an answer. A
message from a master consists of one start bit, 16 bits data, and two
stop bits. The data from the master unit consists of an 8-bit address part
and an 8-bit command part. See Figure 4-1.
ADDRESS BYTE
S
7
6
5
4
3
2
COMMAND BYTE
1
0
7
6
5
4
3
2
1
0
S
S
START BIT
STOP BITS
Figure 4-1. DALI Master Message
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Protocol Standard
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
47
Freescale Semiconductor, Inc.
DALI Protocol Standard
An answer from a slave unit consists of 1 start bit, 8 data bits and 2 stop
bits.
RESPONSE BYTE
S
7
6
5
4
3
2
1
0
S
S
START BIT
STOP BITS
Freescale Semiconductor, Inc...
Figure 4-2. DALI Slave Message
Up to 64 slaves can be connected to the same network and each slave
can receive an individual address, which is called the short address.
There is also the possibility of assigning a slave unit to a group. Up to 16
groups can exist and a slave unit can belong to several groups. A
message can also be broadcasted to all slave units.
Table 4-2. Type of Addresses
Type of Addresses
Byte Description
Short address
0AAAAAAS (AAAAAA = 0 to 63, S = 0/1)
Group address
100AAAAS (AAAA = 0 to 15, S = 0/1)
Broadcast address
1111111S (S = 0/1)
Special command
101CCCC1 (CCCC = command number)
The command byte is to be interpreted as an arc power level if bit S is 0.
The arc power can be between 00 (off) and FE (maximum power level).
A 1 in the position S means that the command byte is to be interpreted
as a DALI command. Refer to Appendix A. DALI Instruction Set for a
list of all available commands.
DRM004 — Rev. 3.0
48
Digitally Addressable Lighting Interface (DALI) Unit
DALI Protocol Standard
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 5. DALI Slave Unit
Freescale Semiconductor, Inc...
5.1 Contents
5.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.3
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.4
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.4.1
Microcontroller Unit (MCU) . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.2
DALI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.4.3
Lamp Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.4.4
RS232 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
5.4.5
Monitor Mode Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.4.6
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.5
The Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
5.5.1
Main Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.5.2
Central Processor Unit (CPU) Module . . . . . . . . . . . . . . . . . 57
5.5.3
DALI Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.4
Lamp Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.5
RS232 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.6
Upgrading the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6.1
Board Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6.2
Reprogramming the Code . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.2 Introduction
This section describes the design of the DALI (Digital Addressable
Lighting Interface) slave unit hardware and the software. The DALI slave
unit receives DALI commands from a DALI master unit through a DALI
interface. These commands tell the DALI slave unit how to control a
connected lamp.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
49
Freescale Semiconductor, Inc.
DALI Slave Unit
5.3 Features
Freescale Semiconductor, Inc...
The DALI slave unit is designed to be as small and simple as possible.
It has the following features:
•
A MC68HC908KX8
•
A polarity insensitive DALI interface
•
A power switch for controlling a 12-V/10-W lamp
•
A current sensor for controlling the lamp status
5.4 Hardware
The hardware consists of a power MOSFET, the CPU
(MC68HC908KX8), and a DALI interface. A low-ohm resistor is used to
sense the current through the connected lamp by using the
analog-to-digital (A/D) converter in the central processor unit (CPU). An
LED is also connected to the CPU to enable debugging even if no lamp
is connected. See Figure 5-1
DALI
INTERFACE
LED
CPU
LAMP
INTERFACE
POWER
SUPPLY
Figure 5-1. DALI Slave Unit
Schematics, layout and part list can be found in Appendix D. DALI
Slave Unit Schematic and Layout and Appendix E. DALI Slave Bill
of Materials.
DRM004 — Rev. 3.0
50
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
Hardware
The slave unit in a real-life application is probably part of an electronic
ballast (ECG). To simplify the design a high-voltage fluorescent tube is
replaced by a low-voltage halogen light bulb.
Freescale Semiconductor, Inc...
NOTE:
The current flowing through a halogen light bulb is high (approximately
1 A) so the connected cables have to be dimensioned accordingly. The
construction is protected against temporary short-circuit conditions but a
permanent short circuit condition will overheat some components with
permanent damage as a consequence.
There is no hardware included on the slave unit to enter the monitor
mode. The slave unit can be connected to the monitor mode interface on
the master unit by using a cable.
5.4.1 Microcontroller Unit (MCU)
The MCU used in this design, as in the master unit, is the
MC68HC908KX8. An LED (D1) is directly connected to the processor
(PTA3) to indicate if the software is running correctly. See Figure 5-2.
5V
PTA3
D1
Figure 5-2. LED Interface
More information regarding the CPU can be found in the
MC68HC908KX8, MC68HC908KX2 HCMOS Microcontroller Unit
Technical Data, Motorola order number MC68HC908KX8/D.
5.4.2 DALI Interface
The DALI interface of the slave unit will not supply any current.
Therefore, it can easily be optically isolated to prevent ground loops.
Although making the solution polarity insensitive is not stated by the
DALI standard it is suggested as an improvement. In this application, this
is done by having two-way opto-diodes and an electronic relay.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
51
Freescale Semiconductor, Inc.
DALI Slave Unit
The transmission uses an optically isolated electronic relay (IC5). By
almost short-circuiting the DALI communication cables, it lowers the
voltage since the current is limited. By using free pins on the inverter
(IC2) the processor (PTB7) there is enough current for controlling. See
Figure 5-3.
Freescale Semiconductor, Inc...
5V
DALI
PTB7
IC2
IC5
Figure 5-3. DALI Transmit Circuit
The reception is done by a two-way opto-coupler (IC3). To get a true
logical signal the opto-coupler is connected to an Schmitt-trigger inverter
(IC2) before the signal reaches the processor (IRQ1 and PTB6). See
Figure 5-4.
5V
IRQ1
PTB6
IC2
DALI
IC3
0V
Figure 5-4. DALI Receive Circuit
DRM004 — Rev. 3.0
52
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
Hardware
5.4.3 Lamp Interface
Controlling the lamp current is done by a protected power MOSFET (T1).
The processor controls the transistor directly (PTA2).
NOTE:
The current is fairly high and could cause damage if a hardware error
occurs.
Freescale Semiconductor, Inc...
To detect lamp failure a current sensing circuitry is included. This is done
by letting the lamp current flow over a shunt resistance (R2). The
generated voltage is measured by the built-in analog-to-digital (A/D)
converter in the processor (PTB3/AD3). See Figure 5-5.
12 V
D
G
PTA2
T1
S
0V
PTB3/AD3
R2
0V
Figure 5-5. Lamp Interface
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
53
Freescale Semiconductor, Inc.
DALI Slave Unit
5.4.4 RS232 Interface
Only JP1 is placed on the slave unit. For communication over an
RS232 interface, a cable has to be connected to the master unit. See
Figure 5-6.
Freescale Semiconductor, Inc...
12 V
PTB4/RXD
PTB5/TXD
JP1
0V
Figure 5-6. RS232 Interface
5.4.5 Monitor Mode Interface
The monitor mode interface only consists of the pin header JP2 and DIP
switch S1. For simplicity the rest of the interface is located on the master
unit and has to be connected with a cable. See Figure 5-7.
12 V
PTA1
PTA0
IRQ0
PTB6/OSC1
JP2
0V
Figure 5-7. Monitor Mode Interface
DRM004 — Rev. 3.0
54
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
The Software
5.4.6 Power Supply
The power supply solution is identical to the one used in the master unit.
The regulator IC4 is responsible for the 5-volt conversion. Incorrect
polarity is handled by D2. See Figure 5-8.
5V
12 V
IC4
Freescale Semiconductor, Inc...
D2
0V
0V
Figure 5-8. Power Supply
5.5 The Software
The software for the master unit and the slave unit is very similar but they
do not share the code although some files have the same name. The
structure is however identical. See Figure 5-9.
The source code can be viewed in Appendix G. DALI Slave Source
Code Files.
CPU
DALI
MAIN
LAMP
RS232
Figure 5-9. DALI Slave Software
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
55
Freescale Semiconductor, Inc.
DALI Slave Unit
5.5.1 Main Module
The main module in the slave unit has the same structure as the main
module in the master unit. If the initialization process is successful,
toggling an output pin on PTA lights the LED. The possibility to source
and sink high current on PTA is used for directly connecting the LED to
the processor. See Figure 5-10.
Freescale Semiconductor, Inc...
INITIALIZE
VARIABLES
INITIALIZE
MODULES
ENABLE
INTERRUPTS
LIGHT LED
CLEAR COP
YES
HANDLE NEW
DATA IN LAMP
YES
SEND ANSWER ON
DALI AND RS232
YES
SET LAMP TO
FAILURE LEVEL
NEW DATA?
NO
ANSWER?
NO
DALI LOST?
NO
Figure 5-10. main( ) Flowchart
DRM004 — Rev. 3.0
56
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
The Software
5.5.2 Central Processor Unit (CPU) Module
The difference between the CPU module of the slave unit and the CPU
module of the master unit is that the setup of ports is adapted to the
difference in hardware.
Freescale Semiconductor, Inc...
5.5.3 DALI Module
The data received from a slave unit is 16 bits and the data sent is 8 bits.
This is opposite to a master unit. To avoid disturbance from the timer
interface module (TIM) this is disabled during transmission and
reception of data. The DALI communication is monitored so that a
disconnected slave unit sets its lamp to a failure level.
5.5.4 Lamp Module
This is the largest module. It handles all activities related to the lamp.
These include:
•
Regulating the light level of the lamp by a PWM-signal
•
Storing parameters for the user-defined data
•
Supervision of the lamp current
The lamp module also interprets all DALI commands.
The timer interface module (TIM) is used to handle all timing. The same
timer is used for generating the pulse-width modulator (PWM) signal for
controlling the light level. The current measurement is done by using the
analog-to-digital converter (ADC).
If the memory is empty, the user-defined data will be set to the default
values as shown in Table 5-1.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
57
Freescale Semiconductor, Inc.
DALI Slave Unit
Table 5-1. Default Values for the User Defined Data
Freescale Semiconductor, Inc...
Memory Position
Type of Parameter
Default Value
FD80
Power on level
FE
FD81
System failure level
FE
FD82
Minimum level
01
FD83
Maximum level
FE
FD84
Fade rate
07
FD85
Fade time
00
FD86
Short address
FF
FD87-FD89
Random address
FF FF FF
FD8A-FD8B
Group
00 00
FD8C-FD9B
Scene
FF … FF
The storage of new user-defined data in the FLASH memory is handled
by the on-chip FLASH programming routines. To erase the data area in
the FLASH memory a call is made to flash_erase( ) which is
defined as:
#define flash_erase() _asm("ldhx #$FD80\njsr $1006\n")
The definition for flash_write( ) is:
#define flash_write() _asm("ldhx #$FD80\njsr $1009\n")
DRM004 — Rev. 3.0
58
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
The Software
INITIALIZE
VARIABLES
COPY FLASH DATA
AREA TO BUFFER
Freescale Semiconductor, Inc...
MERGE NEW DATA
WITH BUFFER
DISABLE
INTERRUPTS
ERASE FLASH
DATA AREA
WRITE BUFFER
DATA TO FLASH
ENABLE
INTERRUPTS
Figure 5-11. lamp_WriteFlash( ) Flowchart
For more information regarding the on-chip routines, refer to the
Motorola Application Note entitled Using MC68HC908 On-Chip FLASH
Programming Routines, Motorola order number AN1831/D.
5.5.5 RS232 Module
The RS232 module is similar to the module for the master unit. The
difference is that other flags are set. Messages received over RS232 by
a master are forwarded over the DALI communication line but on a slave
the messages are handled directly as if they had arrived over the DALI
net.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
59
Freescale Semiconductor, Inc.
DALI Slave Unit
5.6 Upgrading the Software
Freescale Semiconductor, Inc...
Reprogramming the software in the DALI slave unit is done in a similar
way as in the DALI master unit. Refer to 3.6 Upgrading the Software
for more information. The main difference is that the DALI slave unit
does not have a complete monitor mode interface. Therefore, to enter
the monitor mode the slave unit has to use the monitor mode interface
on the master unit.
5.6.1 Board Configuration
To configure the board in monitor mode:
•
Disconnect the power supply and connect a free serial
communication port of the PC (or the computer that
communicates with the processor) to the D-sub on the DALI
master unit marked “Monitor” using a serial communication cable.
•
Connect a cable between JP2 on the DALI slave unit (see
Appendix D. DALI Slave Unit Schematic and Layout) and JP6
on the DALI Master unit (see Appendix B. DALI Master Unit
Schematic and Layout).
•
Set the DIP switch on the DALI slave unit to “OFF”.
When the power supply is reconnected the processor is in the monitor
mode.
After exiting the monitor mode, the cable between the pin headers has
to be removed and the DIP switch has to be set to “ON” to return to the
normal mode.
5.6.2 Reprogramming the Code
By using monitor mode software the FLASH memory of the DALI master
unit can be erased and new software downloaded. Erasing the memory
also clears all user-defined data in the slave unit including the short
address. Therefore, the user-defined data (especially the short address)
has to be set when downloading of new software and clock trimming are
finished.
DRM004 — Rev. 3.0
60
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit
Upgrading the Software
The interrupt vector is cleared when other parts of the FLASH memory
are erased. Since the slave unit updates the contents of the FLASH
memory during execution it is necessary to protect the interrupt vector
area. After the code is replaced the memory position FF7E (FLASH
Block Protect Register) has to be set to FE.
Freescale Semiconductor, Inc...
Trimming of the internal clock has to be done as described in
3.6 Upgrading the Software. However, the cable should be connected
between JP1 on the DALI slave unit (see Appendix D. DALI Slave Unit
Schematic and Layout) and JP5 on the DALI master unit (see
Appendix D. DALI Slave Unit Schematic and Layout).
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
61
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Unit
DRM004 — Rev. 3.0
62
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Section 6. PC Software
Freescale Semiconductor, Inc...
6.1 Contents
6.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.3
Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.4
User manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6.5
The Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.2 Introduction
There is a possibility of controlling the DALI (Digital Addressable
Lighting Interface) master through an RS232 interface (9600 baud, no
parity, 8 data bits, and one stop bit). The DALI master handles data
received over the RS232 interface the same way as the data is entered
by the shaft encoders and the push button. This means that everything
that can be done manually on the master board can also be controlled
remotely. Answers received from a slave unit are also echoed on the
RS232 interface. The liquid crystal display (LCD) on the master unit
displays all the data communicated. To demonstrate this possibility there
is a small application called “DALI demo”.
6.3 Installation
The “DALI demo” application will work on any PC running a 32-bit
Microsoft® Windows® and having one free serial communication port. It
is installed through a standard setup program. Follow the instructions on
the screen.
Microsoft and Windows are registered trademarks of Microsoft Corporation in the U.S. and/or
other countries.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
PC Software
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
63
Freescale Semiconductor, Inc.
PC Software
6.4 User manual
Freescale Semiconductor, Inc...
To be able to communicate with the DALI master:
•
A serial communication cable has to be connected between the
PC and the D sub on the master unit marked “Serial”.
•
The RS232 communication has to be enabled on the DALI master
unit by connecting the pin header JP4 and pin header JP5 with a
cable, see Appendix B. DALI Master Unit Schematic and
Layout.
Before starting the program “DALI demo” all slave units have to be
connected to the master.
Figure 6-1. DALI Demo Application
Start “DALI demo” through the “Start” menu in Microsoft Windows. The
“DALI demo” application checks all short addresses to search for
connected slaves.
DRM004 — Rev. 3.0
64
Digitally Addressable Lighting Interface (DALI) Unit
PC Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
PC Software
The Source Code
It displays a tab for every connected lamp. On each tab the luminosity
and the fade time can be selected. By pressing the button “Set” the new
setting will be communicated to the DALI slaves through the DALI
master. Selecting another scene makes it possible to store 16 settings.
Freescale Semiconductor, Inc...
6.5 The Source Code
The “DALI demo” application is developed using Visual Basic 6.0. It
consists of a single Visual Basic Form File “Main”. Each action by the
user results in a series of DALI messages. See Table 6-1.
Table 6-1. DALI Messages Used in the DALI Demo Application
Action
Messages
Values
Answer
Initialization
Ask status
XX 90 (XX=short address)
LL (LL=status)
Set new
Store data in DTR
Store DTR as fade time
Set light level
Move light level to DTR
Save DTR as scene
A3
XX
XX
FF
FF
-
Select scene
Ask fade time
Ask light level
FF 1Z (Z=scene)
XX A5 (XX=short address)
XX A0
Change scene
WW
2E
YY
21
4Z
(WW=fade time)
(XX=short address)
(YY=light level)
(Z=scene)
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
PC Software
For More Information On This Product,
Go to: www.freescale.com
MM (MM=fade time)
NN (NN=light level)
DRM004 — Rev. 3.0
65
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
PC Software
DRM004 — Rev. 3.0
66
Digitally Addressable Lighting Interface (DALI) Unit
PC Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix A. DALI Instruction Set
Freescale Semiconductor, Inc...
The DALI (Digital Addressable Lighting Interface) protocol specifies a
number of commands that a DALI unit should recognize. They consist of
two bytes where normally the first byte indicates the address of the
receiver and the second byte contains the actual command. These
commands are listed in Table A-1.
Some special commands use both bytes. Since these commands do not
have an address byte, they are broadcasted to every unit. The special
commands are listed in Table A-2.
NOTE:
In Table A-1 and Table A-2:
•
The DTR (Data Transfer Register) is a memory location in the
DALI unit used for temporary data transfer.
•
The answer YES corresponds to the hexadecimal value FF. If no
answer is received it will be interpreted as the answer NO.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Instruction Set
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
67
Freescale Semiconductor, Inc.
DALI Instruction Set
Table A-1. Standard Commands
Freescale Semiconductor, Inc...
Command
Value
Description
Answer
00
Extinguish the lamp without fading
—
01
Dim up 200 ms using the selected fade rate
—
02
Dim down 200 ms using the selected fade rate
—
03
Set the actual arc power level one step higher without fading
—
04
Set the actual arc power level one step lower without fading
—
05
Set the actual arc power level to the maximum value
—
06
Set the actual arc power level to the minimum value
—
07
Set the actual arc power level one step lower without fading
—
08
Set the actual arc power level one step higher without fading
—
10+Scene
Set the light level to the value stored for the selected scene
—
20
Reset the parameters to default settings
—
21
Store the current light level in the DTR
—
2A
Store the value in the DTR as the maximum level
—
2B
Store the value in the DTR as the minimum level
—
2C
Store the value in the DTR as the system failure level
—
2D
Store the value in the DTR as the power on level
—
2E
Store the value in the DTR as the fade time
—
2F
Store the value in the DTR as the fade rate
—
40+Scene
Store the value in the DTR as the selected scene
—
50+Scene
Remove the selected scene from the slave unit
—
60+Group
Add the slave unit to the selected group
—
70+Group
Remove the slave unit from the selected group
—
80
Store the value in the DTR as a short address
—
90
Returns the status of the slave as XX
91
Check if the slave is working
YES/NO
92
Check if there is a lamp failure
YES/NO
93
Check if the lamp is operating
YES/NO
94
Check if the slave has received a level out of limit
YES/NO
DRM004 — Rev. 3.0
68
XX
Digitally Addressable Lighting Interface (DALI) Unit
DALI Instruction Set
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Instruction Set
Table A-1. Standard Commands (Continued)
Freescale Semiconductor, Inc...
Command
Value
Description
Answer
95
Check if the slave is in reset state
YES/NO
96
Check if the slave is missing a short address
YES/NO
97
Returns the version number as XX
XX
98
Returns the content of the DTR as XX
XX
99
Returns the device type as XX
XX
9A
Returns the physical minimum level as XX
XX
9B
Check if the slave is in power failure mode
YES/NO
A0
Returns the current light level as XX
XX
A1
Returns the maximum allowed light level as XX
XX
A2
Returns the minimum allowed light level as XX
XX
A3
Return the power up level as XX
XX
A4
Returns the system failure level as XX
XX
A5
Returns the fade time as X and the fade rate as Y
XY
B0+Scene
Returns the light level XX for the selected scene
XX
C0
Returns a bit pattern XX indicating which group (0-7) the slave belongs to
XX
C1
Returns a bit pattern XX indicating which group (8-15) the slave belongs to
XX
C2
Returns the high bits of the random address as HH
HH
C3
Return the middle bit of the random address as MM
MM
C4
Returns the lower bits of the random address as LL
LL
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Instruction Set
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
69
Freescale Semiconductor, Inc.
DALI Instruction Set
Table A-2. Special Commands
Freescale Semiconductor, Inc...
Special
Command Value
Description
Answer
A1 00
All special mode processes shall be terminated
—
A3 XX
Store value XX in the DTR
—
A5 XX
Initialize addressing commands for slaves with address XX
—
A7 00
Generate a new random address
—
A9 00
Compare the random address with the search address
—
AB 00
Withdraw from the compare process
—
B1 HH
Store value HH as the high bits of the search address
—
B3 MM
Store value MM as the middle bits of the search address
—
B5 LL
Store value LL as the lower bits of the search address
—
B7 XX
Program the selected slave with short address XX
—
B9 XX
Check if the selected slave has short address XX
YES/NO
BB 00
The selected slave returns its short address XX
XX
BD 00
Go into physical selection mode
—
DRM004 — Rev. 3.0
70
Digitally Addressable Lighting Interface (DALI) Unit
DALI Instruction Set
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix B. DALI Master Unit Schematic and Layout
Freescale Semiconductor, Inc...
This appendix includes:
•
DALI master schematic — Figure B-1
•
DALI master layout — Figure B-2
Refer to Appendix D. DALI Slave Unit Schematic and Layout for the
mater unit schematic and layout information.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
71
X1–4
X1–3
X1–2
MSTBA4
4
390
R4
0, 22 µF
C3
2 BYV10
3
GND
R1
D1
GND
GND
GND
BZX55
1
GND
GND
47 k
1
3
R6
3
LMC7221BIN
2
+5 V
+12 V
+12 V
BD135
T1
INVERT
V+
NONINVERT OUT
V–
IC3
D2
BC337
2 T2
GND
GND
R3
1
R2
OUT
GND
C2
IC2
0, 1 µF
0,33 µF
MC78L05ACP
IN
1k
10 k
C1
GND
GND
1
2
3
4
5
6
7
TEST2
ON
MC74HC04A
VCC
A6
Y6
A5
Y6
A4
Y4
JP1
1
2
3
4
5
6
GND PIN6
GND
14
13
12
11
10
9
8
+5 V
NDIR-D4ST
A1
Y1
A2
Y2
A3
Y3
GND
IC4
1
2
3
4
S4
+12 V
GND
GND
+5 V
10 k
R12
10 k
10K
R11
R10
+5 V
GND
GND
PIN8
JP2
1
2
3
4
5
6
7
8
VDD CLOCK
LOAD SEG1
SEG32
IC5
GND
GND
DATAOUT
DATAIN
SEG4
PTB5/TXD
PTB4/RXD
PTA2/KBD2
PTB2/AD2 PTB6/OSC1
PTB1/AD1
PTB0/AD0
IRQ1
PTA0/KBD0 PTA3/KBD3
10
11
12
13
14
15
VDD 16
0.1 µF
PTA1/KBD1 PTA4/KBD4
C4
SEG[1..16]
MC68HC908
8 PTB3/AD3 PTB7/OSC2 9
7
6
5
4
3
2
1 V
SS
IC1
LCD
BP
SEG6
33 pF
SEG15
JP3
1
2
3
4
5
6
7
8
+5 V
PIN8
Figure B-1. DALI Master Schematic (Sheet 1 of 2)
GND
1
T3
3 BC337
2
R5
+5 V
R9
1k
X1–1
2, 7
1k
R8
R7
PAD1
10 k
10 k
HC0438A
C8
+5 V
SEG[17..32]
R13
DALI Master Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
10 k
4 3 2 1
LCD
COM
SP505PR
DIS1
3
COM1 40
34
4G
35
4F
4A 36
37
4B
R15
+5 V
2
L
+5 V
f
e
1
d
g
a
c
b
PIN4
S1
0, 22 nF
GND
S2
S3
EC16B04V
0, 22 nF
GND
GND
GND
P$2
EC16B04V
0, 1 µF
P$1
GND
12 V
GND
GND
JP4
1
2
3
4
C6
C7
C5
MEC3CTL9
10 k
1
21
22
23
24
25
26
27
28
29
30
31
32
3G
3F
3A
3B
L
2G
2F
2A
2B
1G
1F
1A
72
10 k
R14
DRM004 — Rev. 3.0
5
4E
6
4D
7
4C
8
3DP
9
3E
10
3D
11
3C
12
2DP
13
2E
14 2D
15 2C
16 1DP
17 1E
18 1D
19 1C
20 1B
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
DALI Master Unit Schematic and Layout
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
GND
GND
GND
6
7
8
9
2
3
4
5
F09H
X3
9
5
1
8
10 µF
10 µF
C14 + C13 +
7
4
F09H
6
3
C1+
VCC
C1–
VDD
D01
DI1
D02
DI2
DO3
DI3
MC145407P
C2+
GND
C2–
VSS
Rx1
Tx1
Rx2
Tx2
Rx3
Tx3
IC6
GND
20
19
18
17
16
15
14
13
12
11
ELC-2,5
C15 +
CAPNP-5
+ ELC-2, 5
C16
+5 V
GND
1
2
3
4
5
6
7
VCC
OE4
A4
Y4
OE3
A3
Y3
GND
C9
+5 V
7
14
GND
+5 V
14
13
12
11
10
9
8
0, 1 µF
MC74HC12
OE1
A1
Y1
OE2
A2
Y2
GND
IC7
+5 V
GND
VCC
QG1
X0-14
OUT
NC/TS
GND
8
JP5
1k
BZX55
1
R17
D3
Figure B-1. DALI Master Schematic (Sheet 2 of 2)
GND
1
2
3
4
5
6
7
8
9
10
GND
C12
R16
2
10 K
X2
PIN4
1
2
3
4
PIN6
JP6
1
2
3
4
5
6
GND
GND
GND
+5 V
0, 1 µF
C11
GND
GND
GND
0, 33 µF
C10
GND
1
OUT
IN
MOTOROLA
IC8
MC78L05ACP
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
DALI Master Unit Schematic and Layout
DRM004 — Rev. 3.0
73
S1
PAD1
S2
20
C6
DALI Master Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
21
R15
R13
Serial
14
1
PTB7
PTB6
PTB5
PTB4
PTA2
PTA3
PTA4
VDD
IC4
40
IC5
8
7
9
C4
R10
Serial
PTB3
PTB2
PTB1
PTB0
IRQ1
PTA0
PTA1
VSS
1
20
X3
R12
6
1
F09
Monitor
C10
Figure B-2. DALI Master Layout
R14
C5 C7
C8
21
R11
40
JP1
DIS1
JP3
D3
R17
Monitor
JP6
Serial
JP5
JP2
LCD
4 3 2 1
10
11
9
5
C2
7
8
2, 54
T2
F09
IC7
IC6
3
3
2
R6
1
2
T3
1
IC2
C12
9
5
C1
R3
R2
D2
R5
R1
D1
R4
1 2 3
T1
C16 C9
1
+
14
+ C15
1
20
6
1
X2 C13 + C14
IC8
R7
1
C11
S3
1
JP4
8
IC1
16
R9
S4
R16
R8
OFF
QG1
74
2, 54
Monitor
C3
X1 +12 V 0 V da da
1
2
3
4
DRM004 — Rev. 3.0
1
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
DALI Master Unit Schematic and Layout
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix C. DALI Master Unit Bill of Materials
Freescale Semiconductor, Inc...
This appendix provides a bill of materials for the DALI (Digital
Addressable Lighting Interface) master unit.
Refer to Appendix E. DALI Slave Bill of Materials for the slave unit bill
of materials.
Table C-1. DALI Master Bill of Materials (Sheet 1 of 3)
Id.
Type
Description
Package
Supplier
IC1
MC68HC908KX8
Processor
DIP16
Motorola
IC2
MC78L05ACP
Regulator
TO92
Motorola/ON
IC3
LMC7221BIN
Comparator
DIP8
National
IC4
MC74HC04N
Inverter
DIP14
Motorola/ON
IC5
HC0438A
LCD driver
DIP40
Hughes
IC6
MC145407P
RS232 driver
DIP20
Motorola/ON
IC7
MC74HC125N
3-state buffer
DIP14
Motorola/ON
IC8
MC78L05ACP
Regulator
TO92
Motorola/ON
QG1
IQXO-350C, 9.8304 MHz
Clock oscillator
DIP14
IQD
D1
BYV10-30
Schottky diode
SOD81
Philips
D2
BZX55/C10
Zener diode
DO35
Temic
D3
BZX55/C8V2
Zener diode
DO35
Temic
T1
BD135
Power transistor
TO125
Motorola/ON
T2
BC337
Transistor
TO92
Philips
T3
BC337
Transistor
TO92
Philips
DIS1
SP505PR
LCD
DIP40
Seiko
R1
2.7 Ω, 0.6 W
Resistor
Spacing 10 mm
R2
1 kΩ, 0.6 W
Resistor
Spacing 10 mm
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
75
Freescale Semiconductor, Inc.
DALI Master Unit Bill of Materials
Table C-1. DALI Master Bill of Materials (Sheet 2 of 3)
Freescale Semiconductor, Inc...
Id.
Type
Description
Package
R3
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R4
390 Ω, 0.6 W
Resistor
Spacing 10 mm
R5
1 kΩ, 0.6 W
Resistor
Spacing 10 mm
R6
47 kΩ, 0.6 W
Resistor
Spacing 10 mm
R7
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R8
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R9
1 kΩ, 0.6 W
Resistor
Spacing 10 mm
R10
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R11
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R12
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R13
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R14
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R15
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R16
10 kΩ, 0.6 W
Resistor
Spacing 10 mm
R17
1 kΩ, 0.6 W
Resistor
Spacing 10 mm
C1
Ceramic 0.33 µF, 63 V
Capacitor
Spacing 5 mm
C2
Ceramic 0.1 µF, 63 V
Capacitor
Spacing 5 mm
C3
Ceramic 0.22 µF, 63 V
Capacitor
Spacing 5 mm
C4
Ceramic 0.1 µF, 63 V
Capacitor
Spacing 5 mm
C5
Ceramic 2200 pF, 63 V
Capacitor
Spacing 5 mm
C6
Ceramic 2200 pF, 50 V
Capacitor
Spacing 5 mm
C7
Ceramic 2200 pF, 50 V
Capacitor
Spacing 5 mm
C8
Ceramic 33 pF, 50 V
Capacitor
Spacing 5 mm
C9
Ceramic 0.1 µF, 63 V
Capacitor
Spacing 5 mm
C10
Ceramic 0.33 µF, 63 V
Capacitor
Spacing 5 mm
C11
Ceramic 0.1 µF, 63 V
Capacitor
Spacing 5 mm
C12
Ceramic 0.33 µF, 63 V
Capacitor
Spacing 5 mm
C13
Electrolytic 10 µF, 16 V
Capacitor
Spacing 2.5 mm
DRM004 — Rev. 3.0
76
Supplier
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Bill of Materials
Table C-1. DALI Master Bill of Materials (Sheet 3 of 3)
Freescale Semiconductor, Inc...
Id.
Type
Description
Package
Supplier
C14
Electrolytic 10 µF, 16 V
Capacitor
Spacing 2.5 mm
C15
Electrolytic 10 µF, 16 V
Capacitor
Spacing 2.5 mm
C16
Electrolytic 10 µF, 16 V
Capacitor
Spacing 2.5 mm
S1
Multimec 3CTL9
Push-button
Hole
MEC
S2
EC16B24204
Shaft encoder
Hole
Alps
S3
EC16B24204
Shaft encoder
Hole
Alps
S4
NDIR-04ST, 4-p
DIP-switch
Hole
APEM
JP1
MTA100/156, 6-p
Connector
2.54 mm, straight
AMP
JP2
Not mounted
JP3
Not mounted
JP4
MTA100/156, 4-p
Connector
2.54 mm, straight
AMP
JP5
MTA100/156, 4-p
Connector
2.54 mm, straight
AMP
JP6
MTA100/156, 6-p
Connector
2.54 mm, straight
AMP
X1
MSTBA 2.5/4-G-5.08
Connector
5.08 mm
Phoenix
X2
D-sub, 9-p, female, 90°
Connector
Hole
X3
D-sub, 9-p, female, 90°
Connector
Hole
—
FI-349/30/SE15K/W
Heat sink
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
Alutronic
DRM004 — Rev. 3.0
77
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Master Unit Bill of Materials
DRM004 — Rev. 3.0
78
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix D. DALI Slave Unit Schematic and Layout
Freescale Semiconductor, Inc...
This appendix includes:
•
DALI slave schematic — Figure D-1
•
DALI slave layout — Figure D-2
Refer to Appendix B. DALI Master Unit Schematic and Layout for the
mater unit schematic and layout information.
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
79
3
+5 V
4
X1–4
MSTBA4
X1–3
2
1
IC5
10 k
R8
GND
1
2
D2
BYS10–45
1
2
3
4
5
6
7
COLL
EM
DALI Slave Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
MC74AC14
IC4
GND
+5 V
GND
4
3
IN1
VCC 14
OUT1
IN6 13
IN2
OUT6 12
OUT2
IN5 11
IN3
OUT5 10
OUT3
IN4 9
GND OUT4 8
IC2
SFH6206
A/C
C/A
IC3
PVAL3N
X1–2
200
1
2
3
4
VOUT
GND
GND
NC
GND
3.9 k
R9
8
7
6
5
VIN
GND
GND
NC
MC78L00A
P$1
P$2
P$3
P$4
+5 V
S1
C2
1
0.33 µF
JP2
1
2
3
4
5
6
GND PIN6
P$8
P$7
P$6
P$5
+12 V
GND
+5 V
GND
10 k
R1
GND
PIN8
JP3
1
2
3
4
5
6
7
8
8
7
6
5
4
3
2
1
10
11
12
13
14
+5 V
PTB7/OSC2 9
PTB6/OSC1
PTB5/TXD
PTB4/RXD
PTA2/KBD2
MC68HC908K
PTB3/AD3
PTB2/AD2
PTB1/AD1
PTB0/AD0
IRQ1
PTA0/KBD0 PTA3/KBD3
15
VDD 16
PTA1/KBD1 PTA4/KBD4
VSS
IC1
0.1 µF
C1
Figure D-1. DALI Slave Schematic
APEMIKN04
4 3 2
X1–1
R10
8
S/D
2
A
5
D/S
C
3
ON
+12 V
10 k
R7
PIN8
JP4
1
2
3
4
5
6
7
8
+5 V
+5 V
EL15–21
GND D1
10 k
0.1 µF
10 k
C3
R5
+5 V
+5 V
12 V
PIN4
JP1
1
2
3
4
T1
MLD1N06CL
240
R3
GND
R4
GND
R6
80
39 k
DRM004 — Rev. 3.0
0, 18
GND
R2
Freescale Semiconductor, Inc...
2
1
X2–1
MSTBA2
X2–2
Freescale Semiconductor, Inc.
DALI Slave Unit Schematic and Layout
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Unit Schematic and Layout
4
1
R5
JP4
R6
R2
Figure D-2. DALI Slave Layout
C2
JP1
T1
2
X2
IC4
1
3
2
Freescale Semiconductor, Inc...
MLD1N06CL
1
C3
R9
IC3
R1
IC2
D1
C1
1
14
R3
IC1
16L
R7
R4
R8
D2
JP2
5
X1
2
R10
ON
S1
1
2
3
2
1
4
4
3
3
IC5
8
BYS10-45
JP3
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
81
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Unit Schematic and Layout
DRM004 — Rev. 3.0
82
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Unit Schematic and Layout
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix E. DALI Slave Bill of Materials
Freescale Semiconductor, Inc...
This appendix provides a bill of materials for the DALI (Digital
Addressable Lighting Interface) master unit.
Refer to Appendix C. DALI Master Unit Bill of Materials for the master
unit bill of materials.
Table E-1. DALI Slave Bill of Materials
Id.
Type
Description
Package
Supplier
IC1
MC68HC908KX8
Processor
SO16
Motorola
IC2
MC74AC14
Inverter
SO14
Motorola/ON
IC3
SFH6206-3
Opto coupler
SMD
Infineon
IC4
MC78L05AC
Regulator
SO8
Motorola/ON
IC5
PVA1354NS
Opto relay
SMD
IR (Optorelä)
D1
EL15-21SYGC
LED
1206
Everlight
D2
BYS10-45
Shottky diode
SOD106A
Temic
T1
MLD1N06CL
Power transistor
DPAK
Motorola/ON
R1
10 kΩ, 1/8 W
Resistor
0805
R2
0.18 Ω, 1 W
Resistor
2512
R3
240 Ω, 1/8 W
Resistor
0805
R4
39 kΩ, 1/8 W
Resistor
0805
R5
10 kΩ, 1/8 W
Resistor
0805
R6
10 kΩ, 1/8 W
Resistor
0805
R7
10 kΩ, 1/8 W
Resistor
0805
R8
10 kΩ, 1/8 W
Resistor
0805
R9
3.9 kΩ, 1/8 W
Resistor
0805
R10
200 Ω, 1/8 W
Resistor
0805
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
Megitt
DRM004 — Rev. 3.0
83
Freescale Semiconductor, Inc.
DALI Slave Bill of Materials
Table E-1. DALI Slave Bill of Materials (Continued)
Freescale Semiconductor, Inc...
Id.
Type
Description
Package
Supplier
C1
Ceramic 0.1 µF, 25 V
Capacitor
0805, GRM40
Murata
C2
Ceramic 0.33 µF, 16 V
Capacitor
0805, GRM40
Murata
C3
Ceramic 0.1 µF, 25 V
Capacitor
0805, GRM40
Murata
S1
IKN0403001, 4-p
DIP-switch
SMD
APEM
X1
MSTBA 2.5/4-G-5.08
Connector
5.08 mm
Phoenix
X2
MSTBA 2.5/2-G-5.08
Connector
5.08 mm
Phoenix
JP1
MTA100/156, 4-p
Connector
2.54 mm, straight
AMP
JP2
MTA100/156, 6-p
Connector
2.54 mm, straight
AMP
JP3
Not mounted
JP4
Not mounted
DRM004 — Rev. 3.0
84
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix F. DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.1 Contents
F.2
Master: common.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
F.3
Master: cpu.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
F.4
Master: cpu.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
F.5
Master: dali.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
F.6
Master: dali.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
F.7
Master: dali.lkf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
F.8
Master: iokx8.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
F.9
Master: keys.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
F.10
Master: keys.c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
F.11
Master: lcd.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
F.12
Master: lcd.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
F.13
Master: main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
F.14
Master: rs232.h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
F.15
Master: rs232.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
F.16
Master: vector.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
85
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.2 Master: common.h
//
//
//
//
//
//
//
//
//
//
//
//
//
//
common.h
This header contains common definitions
Prepared: Motorola AB
Functional level: Common
Revision: R1A
Rev
P1A
P1B
R1A
Date
001023
010201
010212
Reason/description
Initial version
Added declaration for embedded ROM flash routines
Released version
#ifndef COMMON
#define COMMON
#define TRUE 1
#define FALSE 0
// Global definition
extern unsigned char address;
extern unsigned char command;
// The DALI address
// The DALI command
extern unsigned char answer;
// The DALI answer
extern unsigned char error;
// Stores the last error code
#define SRSR_ERROR
// Reset due to a hardware/software error
0x01
extern unsigned int flag;
// Keep track of all events
#define
#define
#define
#define
#define
//
//
//
//
//
NEW_DATA
SEND_DATA
ERROR_EVENT
ANSWER_EVENT
DEMO_MODE
0x01
0x02
0x04
0x08
0x10
// Macro definitions
#define ei() _asm("cli")
#define di() _asm("sei")
DRM004 — Rev. 3.0
86
Set
Set
Set
Set
Set
when new data is set
when data is to be sent
if an error has occurred
if an answer has arrived
if the demo mode is active
// Enable interrupt
// Disable interrupt
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: common.h
// Declarations for the embedded ROM flash routines
#define CTRLBYT (unsigned char *)0x0048
// Address to a variable containing a erase flag
#define CPUSPD (unsigned char *)0x0049
// Address to a variable containing the cpu speed
#define LADDR
(unsigned int *)0x004A
// Address to a variable containing the last address to write
#define DATA
(unsigned char *)0x004C
// Address to the data array to be written into flash
Freescale Semiconductor, Inc...
#define clock_write() _asm("ldhx #$FDFF\njsr $1009\n")
#endif
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
87
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.3 Master: cpu.h
//
//
//
//
//
//
//
//
//
//
//
//
//
cpu.h
This header contains definitions for the cpu module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001023
010212
Reason/description
Initial version
Released version
#ifndef CPU
#define CPU
// Initialize
extern void cpu_Init(void);
// Interrupt handler for reset
extern @interrupt void _stext(void);
// Trap lost interupts
extern @interrupt void cpu_Trap(void);
#endif
DRM004 — Rev. 3.0
88
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: cpu.c
Freescale Semiconductor, Inc...
F.4 Master: cpu.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
cpu.c
This module handles all cpu related tasks
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
P1B
R1A
R1B
Date
001023
000201
010212
011016
Reason/description
Initial version
Added automatic clock calibration
Released version
Adapted to new clock speed
#include "common.h"
#include "iokx8.h"
#define TRIM_FACTOR_ADDR (unsigned char *)0xFDFF
#define TRIM_FACTOR *(TRIM_FACTOR_ADDR) // Internal clock generator trim factor
// Initialize
void cpu_Init(void)
{
unsigned char trimmed;
unsigned char ser_rec;
unsigned char dali_rec;
// Initialize LVI to 5V
if (TRIM_FACTOR!=0xFF)
{
// Initialize LVI to 5V
CONFIG2 |= 0x08;
}
else
{
// Initialize LVI to 5V and disable COP
CONFIG2 |= 0x09;
}
// Initialize ports
DDRA = 0x00;
// Initialize PTA0 to PTA4 as input registers
PTAPUE = 0x1F; // Enable internal pullup on PTA0 to PTA4
PTB = 0xA1;
// Set initial values for PTB
DDRB = 0xA7;
// Initialize PTB0, PTB1, PTB2, PTB5 and PTB7 as output register
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
89
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
// Mask IRQ1 interrupt
ISCR = 0x06;
// Change internal clock speed to simplify baud rate selection
ICGMR = 0x40;
// Results in 19.6608 MHz
Freescale Semiconductor, Inc...
// Trim internal clock (if a trim value is stored in flash)
if (TRIM_FACTOR!=0xFF)
{
ICGTR = TRIM_FACTOR;
}
else
{
// Clock is not trimmed
while ((PTB & 0x50)!=0x50) // Wait until the signals are stable
;
// Initialize SCI for transmission
ICGTR = 0x40;
// Start with a low value
SCBR = 0x06;
// Baud rate 4800
SCC1 = 0x40;
// Enable SCI
SCC2 = 0x08;
// Transmitter enabled
ser_rec = 0x10;
dali_rec = 0x40;
trimmed = FALSE;
while (trimmed==FALSE) // Loop forever
{
while ((SCS1 & 0x80)==0x00)
// Wait until transmit buffer is empty
;
SCDR = 0x55;
// Bit pattern
if ((PTB & 0x10)==0x00 && ser_rec!=0x00)
{
(ICGTR)++;
}
ser_rec = PTB & 0x10;
if ((PTB & 0x40)==0x00 && dali_rec!=0x00)
{
*CTRLBYT = 0x00;
// Page erase
*CPUSPD = 0x4F;
// 4 * 19.6608
*LADDR = (unsigned int)TRIM_FACTOR_ADDR; // Last address in the
flash memory
*DATA = ICGTR;
clock_write();
if (TRIM_FACTOR==ICGTR)
{
trimmed = TRUE;
}
}
dali_rec = PTB & 0x40;
}
}
}
DRM004 — Rev. 3.0
90
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: cpu.c
Freescale Semiconductor, Inc...
// Trap lost interupts
@interrupt void cpu_Trap(void)
{
while (1==1)
;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
91
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.5 Master: dali.h
//
//
//
//
//
//
//
//
//
//
//
//
//
dali.h
This header contains definitions for the dali module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001110
010212
Reason/description
Initial version
Released version
#ifndef DALI
#define DALI
// Initialize
extern void dali_Init(void);
// Sends the DALI address and command on the dali port
extern void dali_SendData(void);
// Interrupt handler for incoming data on the dali port
extern @interrupt void dali_Start(void);
// Interrupt handler for timebase module
extern @interrupt void dali_Tick(void);
#endif
DRM004 — Rev. 3.0
92
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: dali.c
Freescale Semiconductor, Inc...
F.6 Master: dali.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
dali.c
This module handles all tasks related to the dali port
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
R1A
R1B
Date
001110
010212
011010
Reason/description
Initial version
Released version
Adapted to new clock speed, Reception improved to be more tolerant
The timebase module (TBM) is used
#include "common.h"
#include "iokx8.h"
// Address
#define BROADCAST 0xFF
// Broadcast address for the DALI network
// Normal commands
#define GO_TO_SCENE 0x10
#define DEMO 0xFF
included in the DALI standard)
// Command for changing scene
// Command for starting the demo mode (not
// Special commands
#define INITIALISE 0xA5
#define RANDOMISE 0xA7
// Command for starting initialization mode
// Command for generating a random address
static unsigned char send_position;
static unsigned char send_active;
static unsigned char send_value;
// Position in the data to transfer
// True if transfer has started
// Holds the logic level to transfer
static
static
static
static
//
//
//
//
unsigned
unsigned
unsigned
unsigned
char
char
char
char
rec_position;
rec_active;
rec_value;
rec_bit;
Position in the data to receive
True if reception has started
Holds the received logic level
Number of received bits
static unsigned char demo_scene;
static unsigned int demo_tick;
// Holds the current scene
// Number of ticks since last scene change
static unsigned char repeat_active;
// True if a command shall be repeated
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
93
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
// Initialize
void dali_Init(void)
{
send_active = FALSE;
rec_active = FALSE;
repeat_active = FALSE;
TBCR = 0x2E;
// Interrupt 9600 times/second
ISCR = 0x04;
// Enable IRQ1 interrupt
}
// Sends the DALI address and command on the dali port
void dali_SendData(void)
{
// Check if it is the special command for starting the demo mode
if (address==BROADCAST && command==DEMO)
{
demo_tick = 0;
demo_scene = 0;
address = BROADCAST;
command = GO_TO_SCENE;
flag |= DEMO_MODE | NEW_DATA;
}
// Check if some commands shall be repeated
if (repeat_active==TRUE)
{
repeat_active = FALSE;
}
else
{
if (address & 0x01)
{
// Command
if ((address & 0xE0)==0xA0 || (address & 0xE0)==0xC0)
{
// Special command
if (address==INITIALISE || address==RANDOMISE)
{
// Command shall be repeated within 100 ms
repeat_active = TRUE;
}
}
else
{
// Normal command
if (command>=0x20 && command<=0x80)
{
// Command shall be repeated within 100 ms
repeat_active = TRUE;
}
}
}
}
DRM004 — Rev. 3.0
94
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: dali.c
Freescale Semiconductor, Inc...
// Wait until dali port is idle
while (send_active || rec_active)
;
ISCR = 0x06;
// Disable IRQ1 interrupt
send_value = 0x00;
send_position = 0;
send_active = TRUE; // Activate the timer module to transfer
}
// Interrupt handler for incoming data on the dali port
@interrupt void dali_Start(void)
{
ISCR = 0x06;
// Disable IRQ1 interrupt
answer = 0x00;
// Clear answer
rec_bit = 0;
// No bit has been received
rec_value = 0x00;
// Value is low when starting to receive
rec_position = 0;
rec_active = TRUE; // Activate the timer module to receive
}
// Interrupt handler for timebase module
@interrupt void dali_Tick(void)
{
unsigned char temp_value;
TBCR |= 0x08;
// Acknowledge the interrupt
if (rec_active==TRUE)
{
temp_value = PTB & 0x40;
rec_position++;
if (temp_value!=rec_value)
{
// An edge has been detected
switch (rec_bit)
{
case 0:
// Start bit
rec_bit++;
rec_position = 0;
break;
case 9:
// First stop bit
if (rec_position>6)
{
// Stop bit error, no edge should exist, stop receiving
rec_active = FALSE;
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
case 10:
// Second stop bit
// Stop bit error, no edge should exist, stop receiving
rec_active = FALSE;
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
95
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
ISCR = 0x04;
// Enable IRQ1 interrupt
break;
default:
// The address and command bits
if (rec_position>6)
{
// Store the values
if (temp_value)
{
answer |= (1<<(8-rec_bit));
}
rec_bit++;
rec_position = 0;
}
break;
}
rec_value = temp_value;
}
else
{
// Signal level stable
switch (rec_bit)
{
case 0:
// Start bit
if (rec_position==8)
{
// Start bit error, too long delay before edge, stop receiving
rec_active = FALSE;
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
case 9:
// First stop bit
if (rec_position==8)
{
if (temp_value==0)
{
// Stop bit error, wrong level, stop receiving
rec_active = FALSE;
ISCR = 0x04;
// Enable IRQ1 interrupt
}
else
{
rec_bit++;
rec_position = 0;
}
}
break;
case 10:
// Second stop bit
if (rec_position==8)
{
DRM004 — Rev. 3.0
96
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: dali.c
Freescale Semiconductor, Inc...
// Receive ready
flag |= ANSWER_EVENT;
rec_active = FALSE;
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
default:
// The address and command bits
if (rec_position==10)
{
// Data bit error, too long delay before edge, stop receiving
rec_active = FALSE;
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
}
}
}
if (send_active==TRUE)
{
if ((send_position & 0x03)==0)
{
PTB = (PTB & ~0x80) | send_value;
if (send_position==0)
{
send_value = 0x80; // Second half of start bit
}
if (send_position>=4 && send_position<=128)
{
// Extract bit level
// Check if address or command
if (send_position<68)
{
// Address
temp_value = (address>>((64-send_position)/8)) & 0x01;
}
else
{
// Command
temp_value = (command>>((128-send_position)/8)) & 0x01;
}
// Check if first or second half of data bit
if (send_position & 0x04)
{
// First half
if (temp_value==0x00)
{
send_value = 0x80;
}
else
{
send_value = 0x00;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
97
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
}
else
{
// Second half
if (temp_value==0x00)
{
send_value = 0x00;
}
else
{
send_value = 0x80;
}
Freescale Semiconductor, Inc...
}
}
if (send_position==132)
{
send_value = 0x80; // Start of stop bit and settling time
}
if (send_position==160)
{
ISCR = 0x04;
// Enable IRQ1 interrupt
}
if (send_position==236)
{
send_active = FALSE;
if (repeat_active==TRUE)
{
flag |= SEND_DATA;
}
}
}
send_position++;
}
if (flag & DEMO_MODE)
{
demo_tick++;
// Change scene after 3 seconds
if (demo_tick==28800)
{
demo_tick = 0;
demo_scene++;
if (demo_scene>15)
{
demo_scene = 0;
}
address = BROADCAST;
command = GO_TO_SCENE+demo_scene;
flag |= NEW_DATA | SEND_DATA;
}
}
}
DRM004 — Rev. 3.0
98
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: dali.lkf
F.7 Master: dali.lkf
Freescale Semiconductor, Inc...
#
#
LINK COMMAND FILE Example for 68HC908KX8
Copyright (c) 2000 by Motorola AB
+seg .text -b 0xE000 -m0x1E00 -nCODE -sROM # program start address
+seg .const -a CODE -it -sROM
# constants and strings
+seg .bsct -b 0x40 -m0xC0 -nZPAGE -sRAM
# zero page start address
+seg .ubsct -a ZPAGE -nUZPAGE -sRAM
+seg .data -a UZPAGE -nIDATA -sRAM
# data start address
+seg .bss -a IDATA -nUDATA -sRAM
crtsi.o
# startup routine
main.o
# application program
lcd.o
cpu.o
keys.o
rs232.o
dali.o
"C:\COSMIC\EVAL08\Lib\libi.h08"
"C:\COSMIC\EVAL08\Lib\libm.h08"
+seg .const -b 0xFFDC
vector.o
# vectors start address
# interrupt vectors
+def [email protected]
+def __stack=0x0FF
# symbol used by library
# stack pointer value
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
99
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
F.8 Master: iokx8.h
/* IO DEFINITIONS FOR MC68HC908KX8
* Copyright (c) 2000 by Motorola AB
* Based on definition from Cosmic
*/
Freescale Semiconductor, Inc...
#define uint
unsigned int
/* PORTS section
*/
@tiny volatile char
@tiny volatile char
@tiny volatile char
@tiny volatile char
@tiny volatile char
PTA
PTB
DDRA
DDRB
PTAPUE
@0x00;
@0x01;
@0x04;
@0x05;
@0x0d;
/*
/*
/*
/*
/*
port A */
port B */
data direction port A */
data direction port B */
pull-up enable port A */
/* SCI section
*/
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
SCC1
SCC2
SCC3
SCS1
SCS2
SCDR
SCBR
@0x13;
@0x14;
@0x15;
@0x16;
@0x17;
@0x18;
@0x19;
/*
/*
/*
/*
/*
/*
/*
SCI
SCI
SCI
SCI
SCI
SCI
SCI
char
char
char
char
char
char
char
control register 1 */
control register 2 */
control register 3 */
status register 1 */
status register 2 */
data register */
baud rate */
/* KEYBOARD section
*/
@tiny volatile char KBSCR
@0x1a;
/* keyboard status/control register */
@tiny volatile char KBIER
@0x1b;
/* keyboard interrupt enable */
/* TIMEBASE section
*/
@tiny volatile char TBCR
@0x1c;
/* timebase module control */
/* IRQ section
*/
@tiny volatile char ISCR
@0x1d;
/* IRQ status/control register */
/* CONFIG section
*/
@tiny volatile char CONFIG1
@tiny volatile char CONFIG2
@0x1e;
@0x1f;
/* configuration register 1 */
/* configuration register 2 */
/* TIMER section
*/
@tiny volatile char TSC
@tiny volatile uint TCNT
@0x20;
@0x21;
/* timer status/ctrl register */
/* timer counter register */
DRM004 — Rev. 3.0
100
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Master Unit Source Code Files
Master: iokx8.h
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
char
char
uint
char
char
char
uint
char
char
char
uint
char
char
TCNTH
TCNTL
TMOD
TMODH
TMODL
TSC0
TCH0
TCH0H
TCH0L
TSC1
TCH1
TCH1H
TCH1L
@0x21;
@0x22;
@0x23;
@0x23;
@0x24;
@0x25;
@0x26;
@0x26;
@0x27;
@0x28;
@0x29;
@0x29;
@0x2a;
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
char
char
char
char
char
ICGCR
ICGMR
ICGTR
ICGDVR
ICGDSR
@0x36;
@0x37;
@0x38;
@0x39;
@0x3a;
/*
/*
/*
/*
/*
ICG
ICG
ICG
ICG
ICG
/* A/D section
*/
@tiny volatile char ADSCR
@tiny volatile char ADR
@tiny volatile char ADICLK
@0x3c;
@0x3d;
@0x3e;
/* A/D status/ctrl register */
/* A/D data register */
/* A/D input clock register */
/* SIM section
*/
@near volatile char SBSR
@near volatile char SRSR
@near volatile char SBFCR
@0xfe00;
@0xfe01;
@0xfe03;
/* SIM break status register */
/* SIM reset status register */
/* SIM break control register */
/* INTERUPT section
*/
@near volatile char INT1
@near volatile char INT2
@near volatile char INT3
@0xfe04;
@0xfe05;
@0xfe06;
/* INTERUPT status register 1 */
/* INTERUPT status register 2 */
/* INTERUPT status register 3 */
/* FLASH section
*/
@near volatile char FLTCR
@near volatile char FLCR
@near volatile char FLBPR
@0xfe07;
@0xfe08;
@0xff7e;
/* FLASH test control register */
/* FLASH control register */
/* FLASH block protect register */
/* BREAK section
*/
@near volatile char BRKAR
@near volatile uint BRK
@near volatile char BRKH
@0xfe02;
@0xfe09;
@0xfe09;
/* BREAK auxiliary register */
/* BREAK address register */
/* BREAK address register low */
/* ICG section
*/
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
counter high */
counter low */
modulo register */
modulo high */
modulo low */
chan 0 status/ctrl */
chan 0 register */
chan 0 high */
chan 0 low */
chan 1 status/ctrl */
chan 1 register */
chan 1 high */
chan 1 low */
control register */
multiplier register */
trim register */
divider control register */
stage control register */
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
101
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
@near volatile
@near volatile
char BRKL
char BRKSCR
@0xfe0a;
@0xfe0b;
/* BREAK address register high */
/* BREAK status/ctrl register */
/* LVI section
*/
@near volatile char LVISR
@0xfe0c;
/* LVI status register */
/* COP section
*/
@near volatile char COPCTL
@0xffff;
/* COP control register */
Freescale Semiconductor, Inc...
#undef uint
DRM004 — Rev. 3.0
102
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: keys.h
Freescale Semiconductor, Inc...
F.9 Master: keys.h
//
//
//
//
//
//
//
//
//
//
//
//
//
keys.h
This header contains definitions for the keys module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001025
010212
Reason/description
Initial version
Released version
#ifndef KEYS
#define KEYS
// Initialize
extern void keys_Init(void);
// Interrupt handler for send button
extern @interrupt void keys_SendButton(void);
// Interrupt handler for command pulse sender
extern @interrupt void keys_CommandPulse(void);
// Interrupt handler for address pulse sender
extern @interrupt void keys_AddressPulse(void);
#endif
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
103
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.10 Master: keys.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
keys.c
This module handles all tasks related to the keys
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001025
010212
Reason/description
Initial version
Released version
The keyboard interrupt module (KBI) and the timer interface module (TIM)
are used
#include "common.h"
#include "iokx8.h"
// Initialize
void keys_Init(void)
{
// Keyboard Interrupt Module
KBIER = 0x01;
// Interrupt enabled on PTA0
KBSCR = 0x04;
// Interrupt request not masked, Clear interrupt request, Falling edges
sensitivity
// Timer Interface Module
TSC = 0x00;
// Start timer (only interrupts are used, not the captured values)
TSC0 = 0x48;
// Interrupt enabled, Input capture on falling edge
TSC1 = 0x48;
// Interrupt enabled, Input capture on falling edge
}
// Interrupt handler for send button
@interrupt void keys_SendButton(void)
{
flag |= SEND_DATA;
flag &= ~DEMO_MODE; // Clear demo mode
}
// Interrupt handler for command pulse sender
@interrupt void keys_CommandPulse(void)
{
DRM004 — Rev. 3.0
104
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: keys.c
TSC1 &= ~0x80;
// Clear flag bit
// Check in which direction the pulse sender is rotated
if (PTA & 0x10)
{
command++;
}
else
{
command--;
}
flag |= NEW_DATA;
Freescale Semiconductor, Inc...
}
// Interrupt handler for address pulse sender
@interrupt void keys_AddressPulse(void)
{
TSC0 &= ~0x80;
// Clear flag bit
// Check in which direction the pulse sender is rotated
if (PTA & 0x02)
{
address++;
}
else
{
address--;
}
flag |= NEW_DATA;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
105
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.11 Master: lcd.h
//
//
//
//
//
//
//
//
//
//
//
//
//
lcd.h
This header contains definitions for the lcd module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001023
010212
Reason/description
Initial version
Released version
#ifndef LCD
#define LCD
// Initialize
extern void lcd_Init(void);
// Print the address and the command on the LCD module
extern void lcd_ShowData(void);
// Print the answer on the LCD module
extern void lcd_ShowAnswer(void);
// Print the error code on the LCD module
extern void lcd_ShowError(void);
#endif
DRM004 — Rev. 3.0
106
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: lcd.c
Freescale Semiconductor, Inc...
F.12 Master: lcd.c
//
//
//
//
//
//
//
//
//
//
//
//
//
lcd.c
This module handles all lcd related tasks
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001023
010212
Reason/description
Initial version
Released version
#include "common.h"
#include "iokx8.h"
// Translation tables between hexadecimal digits and corresponding bits to
set on the LCD
#define COLON 0x01000000
const unsigned long digit1[16] =
{
0x000DE000, 0x00082000, 0x000EC000,
0x000B2000, 0x00076000, 0x0007E000,
0x000FE000, 0x000F2000, 0x000FA000,
0x0005C000, 0x000AE000, 0x0007C000,
};
const unsigned long digit2[16] =
{
0x00E00E00, 0x00800200, 0x00D00C00,
0x00B00200, 0x00700600, 0x00700E00,
0x00F00E00, 0x00F00200, 0x00F00A00,
0x00600C00, 0x00900E00, 0x00700C00,
};
const unsigned long digit3[16] =
{
0x1C0000E0, 0x10000020, 0x1A0000C0,
0x16000020, 0x0E000060, 0x0E0000E0,
0x1E0000E0, 0x1E000020, 0x1E0000A0,
0x0C0000C0, 0x120000E0, 0x0E0000C0,
};
0x000E6000,
0x000C2000,
0x0003E000,
0x00078000
0x00D00600,
0x00C00200,
0x00300E00,
0x00700800
0x1A000060,
0x18000020,
0x060000E0,
0x0E000080
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
107
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
const unsigned long digit4[16] =
{
0xC000000F, 0x00000003, 0xA000000D,
0x60000003, 0xE0000006, 0xE000000E,
0xE000000F, 0xE0000003, 0xE000000B,
0xC000000C, 0x2000000F, 0xE000000C,
};
0xA0000007,
0x80000003,
0x6000000E,
0xE0000008
Freescale Semiconductor, Inc...
// Takes data and sends it to LCD driver
static void lcd_SendData(unsigned long data)
{
unsigned char index;
for (index = 0; index<32; index++)
{
if (data & 0x01)
{
PTB |= 0x04;
// Set DATA high (PTB2)
}
else
{
PTB &= ~0x04;
// Set DATA low (PTB2)
}
data >>= 1;
PTB &= ~0x01;
// Toggle CLOCK (PTB0)
PTB |= 0x01;
}
}
// Initialization
void lcd_Init(void)
{
PTB |= 0x02;
// Set LOAD high (PTB1)
lcd_SendData(digit1[0x00] | digit2[0x00] | digit3[0x00] | digit4[0x00] |
COLON);
}
// Print the address and the command on the LCD module
void lcd_ShowData(void)
{
unsigned long result;
result = digit1[(address & 0xF0) >> 4] | digit2[address & 0x0F];
// Add digit 1 & 2
result |= digit3[(command & 0xF0) >> 4] | digit4[command & 0x0F];
// Add digit 3 & 4
result |= COLON;
// Add :
lcd_SendData(result);
}
DRM004 — Rev. 3.0
108
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: lcd.c
// Print the answer on the LCD module
void lcd_ShowAnswer(void)
{
unsigned long result;
result = digit2[0x0A] | digit3[(answer & 0xF0) >> 4] | digit4[answer &
0x0F];
lcd_SendData(result);
Freescale Semiconductor, Inc...
}
// Print the error code on the LCD module
void lcd_ShowError(void)
{
unsigned long result;
result = digit2[0x0E] | digit3[(error & 0xF0) >> 4] | digit4[error &
0x0F];
lcd_SendData(result);
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
109
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.13 Master: main.c
//
//
//
//
//
//
//
//
//
//
//
//
//
main.c
This module contains the main function
Prepared: Motorola AB
Functional level: Application
Revision: R1A
Rev
P1A
R1A
#include
#include
#include
#include
#include
#include
#include
Date
001023
010212
Reason/description
Initial version
Released version
"common.h"
"iokx8.h"
"cpu.h"
"lcd.h"
"keys.h"
"rs232.h"
"dali.h"
// Global variables declaration
unsigned char address;
unsigned char command;
// The DALI address
// The DALI command
unsigned char answer;
// The DALI answer
unsigned char error;
// Stores the last error code
unsigned int flag;
// Keep track of all events
// Main function
void main(void)
{
address = 0x00;
command = 0x00;
// Initialize when starting
// Initialize when starting
answer = 0x00;
// Initialize when starting
error = 0x00;
// Initialize when starting
flag = 0x00;
// Initialize when starting
cpu_Init();
lcd_Init();
keys_Init();
// Initialize the cpu module
// Initialize the lcd module
// Initialize the keys module
DRM004 — Rev. 3.0
110
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: main.c
rs232_Init();
dali_Init();
// Initialize the keys module
// Initialize the dali module
ei();
// Enable interrupt
while (1==1)
{
COPCTL = 0x00;
// Loop forever
// Clear COP counter
Freescale Semiconductor, Inc...
// NEW_DATA flag can be set from the keys module,
// the rs232 module or the dali module
if (flag & NEW_DATA)
{
flag &= ~NEW_DATA;
// Clear NEW_DATA flag
lcd_ShowData();
// Update lcd with new address and command
}
// SEND_DATA flag can be set from the keys module,
// the rs232 module or the dali module
if (flag & SEND_DATA)
{
flag &= ~SEND_DATA;
// Clear SEND_DATA flag
dali_SendData();
// Send address and command on the dali port
}
// ANSWER_EVENT flag can be
if (flag & ANSWER_EVENT)
{
flag &= ~ANSWER_EVENT;
lcd_ShowAnswer();
rs232_SendAnswer();
}
set from the dali module
// Clear ANSWER_EVENT flag
// Update the lcd with the answer
// Send the answer on the rs232 port
// ERROR_EVENT flag can be set from any module
if (flag & ERROR_EVENT)
{
flag &= ~ERROR_EVENT;
// Clear ERROR_EVENT flag
lcd_ShowError();
// Update the lcd with the error code
}
}
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
111
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Freescale Semiconductor, Inc...
F.14 Master: rs232.h
//
//
//
//
//
//
//
//
//
//
//
//
//
rs232.h
This header contains definitions for the rs232 module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001027
010212
Reason/description
Initial version
Released version
#ifndef RS232
#define RS232
// Initialize
extern void rs232_Init(void);
// Sends the DALI answer on the rs232 port
extern void rs232_SendAnswer(void);
// Interrupt handler for received data on the rs232 port
extern @interrupt void rs232_ReceiveData(void);
#endif
DRM004 — Rev. 3.0
112
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: rs232.c
Freescale Semiconductor, Inc...
F.15 Master: rs232.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
rs232.c
This module handles all tasks related to the rs232 port
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
R1A
R1B
Date
001027
010212
011016
Reason/description
Initial version
Released version
Adapted to new clock speed
The serial communication interface module (SCI) is used
#include "common.h"
#include "iokx8.h"
static unsigned char first; // Keeps track if incoming data is address or command
// Initialize
void rs232_Init(void)
{
SCBR = 0x05;
//
SCC1 = 0x40;
//
SCC2 = 0x2C;
//
enabled
first = TRUE;
//
}
Baud rate 9600
Enable SCI
Enable receive interrupt, transmitter enabled, receiver
Next incoming byte is an address
// Sends the answer on the rs232 port
void rs232_SendAnswer(void)
{
while ((SCS1 & 0x80)==0x00) // Wait until transmit buffer is empty
;
SCDR = answer;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
113
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Master Unit Source Code Files
// Interrupt handler for received data on the rs232 port
@interrupt void rs232_ReceiveData(void)
{
if (SCS1 & 0x20)
// Received data available in SCDR
{
if (first==TRUE)
{
address = SCDR;
first = FALSE;
// Next data is a command
}
else
{
command = SCDR;
first = TRUE;
// Next data is an address
flag |= NEW_DATA | SEND_DATA;
flag &= ~DEMO_MODE; // Clear demo mode
}
}
}
DRM004 — Rev. 3.0
114
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Master Unit Source Code Files
Master: vector.c
Freescale Semiconductor, Inc...
F.16 Master: vector.c
//
//
//
//
//
//
//
//
//
//
//
//
//
vector.c
This module contains the interrupt vector
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
#include
#include
#include
#include
Date
001023
010212
Reason/description
Initial version
Released version
"cpu.h"
"keys.h"
"rs232.h"
"dali.h"
void (* const _vectab[])()
{
dali_Tick,
//
cpu_Trap,
//
keys_SendButton,
//
cpu_Trap,
//
rs232_ReceiveData, //
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
keys_CommandPulse, //
keys_AddressPulse, //
cpu_Trap,
//
dali_Start,
//
cpu_Trap,
//
_stext
//
};
=
Timebase module
ADC conversion complete
Keyboard
SCI transmit
SCI receive
SCI receive error
Reserved
Reserved
Reserved
Reserved
Reserved
TIM overflow
TIM channel 1
TIM channel 0
CMIREQ
IRQ1
SWI
Reset
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
115
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Master Unit Source Code Files
DRM004 — Rev. 3.0
116
Digitally Addressable Lighting Interface (DALI) Unit
DALI Master Unit Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DALI Unit
Appendix G. DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.1 Contents
G.2
Slave: command.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
G.3
Slave: common.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
G.4
Slave: cpu.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
G.5
Slave: cpu.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
G.6
Slave: dali.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
G.7
Slave: dali.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
G.8
Slave: dali.lkf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
G.9
Slave: iokx8.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131
G.10 Slave: lamp.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134
G.11 Slave: lamp.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
G.12 Slave: main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
G.13 Slave: rs232.h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158
G.14 Slave: rs232.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159
G.15 Slave: vector.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
117
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.2 Slave: command.h
//
//
//
//
//
//
//
//
//
//
//
//
//
command.h
This header contains DALI command definitions
Prepared: Motorola AB
Functional level: Application
Revision: R1A
Rev
P1A
R1A
Date
001216
010212
Reason/description
Initial version
Released version
#ifndef COMMAND
#define COMMAND
// Indirect arc power control commands
#define OFF
#define UP
#define DOWN
#define STEP_UP
#define STEP_DOWN
#define RECALL_MAX_LEVEL
#define RECALL_MIN_LEVEL
#define STEP_DOWN_AND_OFF
#define ON_AND_STEP_UP
#define GO_TO_SCENE
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x07
0x08
0x10
// General configuration commands
#define RESET
#define STORE_ACTUAL_LEVEL_IN_THE_DTR
0x20
0x21
// Arc power parameters settings
#define STORE_THE_DTR_AS_MAX_LEVEL
#define STORE_THE_DTR_AS_MIN_LEVEL
#define STORE_THE_DTR_AS_SYSTEM_FAILURE_LEVEL
#define STORE_THE_DTR_AS_POWER_ON_LEVEL
#define STORE_THE_DTR_AS_FADE_TIME
#define STORE_THE_DTR_AS_FADE_RATE
#define STORE_THE_DTR_AS_SCENE
0x2A
0x2B
0x2C
0x2D
0x2E
0x2F
0x40
// System parameters settings
#define REMOVE_FROM_SCENE
#define ADD_TO_GROUP
#define REMOVE_FROM_GROUP
#define STORE_DTR_AS_SHORT_ADDRESS
0x50
0x60
0x70
0x80
DRM004 — Rev. 3.0
118
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: command.h
// Queries related to status information
#define QUERY_STATUS
#define QUERY_BALLAST
#define QUERY_LAMP_FAILURE
#define QUERY_LAMP_POWER_ON
#define QUERY_LIMIT_ERROR
#define QUERY_RESET_STATE
#define QUERY_MISSING_SHORT_ADDRESS
#define QUERY_VERSION_NUMBER
#define QUERY_CONTENT_DTR
#define QUERY_DEVICE_TYPE
#define QUERY_PHYSICAL_MINIMUM_LEVEL
#define QUERY_POWER_FAILURE
0x90
0x91
0x92
0x93
0x94
0x95
0x96
0x97
0x98
0x99
0x9A
0x9B
// Queries related to arc power parameters settings
#define QUERY_ACTUAL_LEVEL
0xA0
#define QUERY_MAX_LEVEL
0xA1
#define QUERY_MIN_LEVEL
0xA2
#define QUERY_POWER_ON_LEVEL
0xA3
#define QUERY_SYSTEM_FAILURE_LEVEL
0xA4
#define QUERY_FADE
0xA5
// Queries related to system parameters settings
#define QUERY_SCENE_LEVEL
0xB0
#define QUERY_GROUPS_0_7
0xC0
#define QUERY_GROUPS_8_15
0xC1
#define QUERY_RANDOM_ADDRESS_H
0xC2
#define QUERY_RANDOM_ADDRESS_M
0xC3
#define QUERY_RANDOM_ADDRESS_L
0xC4
// Terminate special processes
#define TERMINATE
0xA1
// Download information to the dtr
#define DATA_TRANSFER_REGISTER
0xA3
// Addressing commands
#define INITIALISE
#define RANDOMISE
#define COMPARE
#define WITHDRAW
#define SEARCHADDRH
#define SEARCHADDRM
#define SEARCHADDRL
#define PROGRAM_SHORT_ADDRESS
#define VERIFY_SHORT_ADDRESS
#define QUERY_SHORT_ADDRESS
#define PHYSICAL_SELECTION
0xA5
0xA7
0xA9
0xAB
0xB1
0xB3
0xB5
0xB7
0xB9
0xBB
0xBD
#endif
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
119
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.3 Slave: common.h
//
//
//
//
//
//
//
//
//
//
//
//
//
//
common.h
This header contains common definitions
Prepared: Motorola AB
Functional level: Common
Revision: R1A
Rev
P1A
P1B
R1A
Date
001023
010201
010212
Reason/description
Initial version
Added declaration for embedded ROM flash routines
Released version
#ifndef COMMON
#define COMMON
#define TRUE 1
#define FALSE 0
// Global definition
extern unsigned char address;
extern unsigned char command;
// The DALI address
// The DALI command
extern unsigned char answer;
// The DALI answer
extern unsigned int flag;
// Keep track of all events
#define NEW_DATA
#define SEND_ANSWER
#define SIGNAL_ERROR
// Set when the DALI
0x01
// Set when new data has arrived
0x02
// Set when an answer is to be sent
0x04
signal level has been low for more than 500 ms
// Macro definitions
#define ei() _asm("cli")
#define di() _asm("sei")
// Enable interrupt
// Disable interrupt
// Declarations for the embedded ROM flash routines
#define CTRLBYT (unsigned char *)0x0048
// Address to a variable containting a erase flag
#define CPUSPD (unsigned char *)0x0049
// Address to a variable containing the cpu speed
#define LADDR
(unsigned int *)0x004A
// Address to a variable containing the last address to write
#define DATA
(unsigned char *)0x004C
// Address to the data array to be written into flash
#define flash_erase() _asm("ldhx #$FD80\njsr $1006\n")
#define flash_write() _asm("ldhx #$FD80\njsr $1009\n")
#define clock_write() _asm("ldhx #$FDFF\njsr $1009\n")
#endif
DRM004 — Rev. 3.0
120
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: cpu.h
Freescale Semiconductor, Inc...
G.4 Slave: cpu.h
//
//
//
//
//
//
//
//
//
//
//
//
//
cpu.h
This header contains definitions for the cpu module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001023
010212
Reason/description
Initial version
Released version
#ifndef CPU
#define CPU
// Initialize
extern void cpu_Init(void);
// Interrupt handler for reset
extern @interrupt void _stext(void);
// Trap lost interupts
extern @interrupt void cpu_Trap(void);
#endif
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
121
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.5 Slave: cpu.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
cpu.c
This module handles all cpu related tasks
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
P1B
R1A
R1B
Date
001023
000201
010212
011016
Reason/description
Initial version
Added automatic clock calibration
Released version
Adapted to new clock speed
#include "common.h"
#include "iokx8.h"
#define TRIM_FACTOR_ADDR (unsigned char *)0xFDFF
#define TRIM_FACTOR *(TRIM_FACTOR_ADDR) // Internal clock generator trim factor
// Initialize
void cpu_Init(void)
{
unsigned char trimmed;
unsigned char ser_rec;
unsigned char dali_rec;
if (TRIM_FACTOR!=0xFF)
{
// Initialize LVI to 5V
CONFIG2 |= 0x08;
}
else
{
// Initialize LVI to 5V and disable COP
CONFIG2 |= 0x09;
}
// Initialize ports
PTA = 0x08;
// Set initial values for PTA
DDRA = 0x0C;
// Initialize PTA2 and PTA3 as output registers
PTB = 0xA0;
// Set initial values for PTB
DDRB = 0xA0;
// Initialize PTB5 and PTB7 as output register
// Mask IRQ1 interrupt
ISCR = 0x06;
// Change internal clock speed to simplify baud rate selection
ICGMR = 0x40;
// Results in 19.6608 MHz
DRM004 — Rev. 3.0
122
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: cpu.c
// Trim internal clock (if a trim value is stored in flash)
if (TRIM_FACTOR!=0xFF)
{
ICGTR = TRIM_FACTOR;
}
else
{
// Clock is not trimmed
while ((PTB & 0x50)!=0x50) // Wait until the signals are stable
;
// Initialize SCI for transmission
ICGTR = 0x40;
// Start with a low value
SCBR = 0x06;
// Baud rate 4800
SCC1 = 0x40;
// Enable SCI
SCC2 = 0x08;
// Transmitter enabled
ser_rec = 0x10;
dali_rec = 0x40;
trimmed = FALSE;
while (trimmed==FALSE) // Loop forever
{
while ((SCS1 & 0x80)==0x00)
// Wait until transmit buffer is
empty
;
SCDR = 0x55;
// Bit pattern
if ((PTB & 0x10)==0x00 && ser_rec!=0x00)
{
(ICGTR)++;
}
ser_rec = PTB & 0x10;
if ((PTB & 0x40)==0x00 && dali_rec!=0x00)
{
*CTRLBYT = 0x00;
// Page erase
*CPUSPD = 0x4F;
// 4 * 19.6608
*LADDR = (unsigned int)TRIM_FACTOR_ADDR;
// Last address in
the flash memory
*DATA = ICGTR;
clock_write();
if (TRIM_FACTOR==ICGTR)
{
trimmed = TRUE;
}
}
dali_rec = PTB & 0x40;
}
}
}
// Trap lost interupts
@interrupt void cpu_Trap(void)
{
while (1==1)
;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
123
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.6 Slave: dali.h
//
//
//
//
//
//
//
//
//
//
//
//
//
dali.h
This header contains definitions for the dali module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001110
010212
Reason/description
Initial version
Released version
#ifndef DALI
#define DALI
// Initialize
extern void dali_Init(void);
// Sends the DALI answer on the dali port
extern void dali_SendAnswer(void);
// Interrupt handler for incoming data on the dali port
extern @interrupt void dali_Start(void);
// Interrupt handler for timebase module
extern @interrupt void dali_Tick(void);
#endif
DRM004 — Rev. 3.0
124
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: dali.c
Freescale Semiconductor, Inc...
G.7 Slave: dali.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
dali.c
This module handles all tasks related to the dali port
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
R1A
R1B
Date
001110
010212
011010
Reason/description
Initial version
Released version
Adapted to new clock speed, Reception improved to be more tolerant
The timebase module (TBM) is used
#include "common.h"
#include "iokx8.h"
static unsigned char send_position;
static unsigned char send_active;
static unsigned char send_value;
// Position in the data to transfer
// True if transfer has started
// Holds the logic level to transfer
static
static
static
static
//
//
//
//
unsigned
unsigned
unsigned
unsigned
char
char
char
char
rec_position;
rec_active;
rec_value;
rec_bit;
static unsigned int low_counter;
low
Position in the data to receive
True if reception has started
Holds the received logic level
Number of received bits
// Number of ticks the signal level has been
// Initialize
void dali_Init(void)
{
send_active = FALSE;
rec_active = FALSE;
TBCR = 0x2E;
// Interrupt 9600 times/second
ISCR = 0x04;
// Enable IRQ1 interrupt
}
// Sends the DALI address and command on the dali port
void dali_SendAnswer(void)
{
// Check if some commands shall be repeated
// Wait until dali port is idle
while (send_active || rec_active)
;
ISCR = 0x06;
// Disable IRQ1 interrupt
TSC &= ~0x40;
// Disable timer overflow interrupt
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
125
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
send_value = 0x80; // Delay before answering
send_position = 0;
send_active = TRUE; // Activate the timer module to transfer
Freescale Semiconductor, Inc...
}
// Interrupt handler for incoming data on the dali port
@interrupt void dali_Start(void)
{
ISCR = 0x06;
// Disable IRQ1 interrupt
TSC &= ~0x40;
// Disable timer overflow interrupt
address = 0x00;
// Clear address
command = 0x00;
// Clear command
rec_bit = 0;
// No bit has been received
rec_value = 0x00;
// Value is low when starting to receive
rec_position = 0;
rec_active = TRUE; // Activate the timer module to receive
}
// Interrupt handler for timebase module
@interrupt void dali_Tick(void)
{
unsigned char temp_value;
TBCR |= 0x08;
// Acknowledge the interrupt
if (rec_active==TRUE)
{
temp_value = PTB & 0x40;
rec_position++;
if (temp_value!=rec_value)
{
// An edge has been detected
switch (rec_bit)
{
case 0:
// Start bit
rec_bit++;
rec_position = 0;
break;
case 17:
// First stop bit
if (rec_position>6)
{
// Stop bit error, no edge should exist, stop receiving
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
case 18:
// Second stop bit
// Stop bit error, no edge should exist, stop receiving
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
DRM004 — Rev. 3.0
126
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: dali.c
ISCR = 0x04;
// Enable IRQ1 interrupt
break;
default:
// The address and command bits
if (rec_position>6)
{
// Store the values
if (temp_value)
{
// Check if address or command
if (rec_bit<=8)
{
address |= (1<<(8-rec_bit));
}
else
{
command |= (1<<(16-rec_bit));
}
}
rec_bit++;
rec_position = 0;
}
break;
}
rec_value = temp_value;
}
else
{
// Signal level stable
switch (rec_bit)
{
case 0:
// Start bit
if (rec_position==8)
{
// Start bit error, too long delay before edge, stop receiving
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
case 17:
// First stop bit
if (rec_position==8)
{
if (temp_value==0)
{
// Stop bit error, wrong level, stop receiving
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
else
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
127
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
{
rec_bit++;
rec_position = 0;
Freescale Semiconductor, Inc...
}
}
break;
case 18:
// Second stop bit
if (rec_position==8)
{
// Receive ready
flag |= NEW_DATA;
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
default:
// The address and command bits
if (rec_position==10)
{
// Data bit error, too long delay before edge, stop receiving
rec_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
break;
}
}
}
if (send_active==TRUE)
{
if ((send_position & 0x03)==0)
{
PTB = (PTB & ~0x80) | send_value;
if (send_position==24)
{
send_value = 0x00; // First half of start bit
}
if (send_position==28)
{
send_value = 0x80; // Second half of start bit
}
if (send_position>=32 && send_position<=92)
{
// Extract bit level
temp_value = (answer>>((92-send_position)/8)) & 0x01;
// Check if first or second half of data bit
if ((send_position & 0x04)==0)
{
// First half
if (temp_value==0x00)
{
DRM004 — Rev. 3.0
128
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: dali.c
send_value = 0x80;
}
else
{
send_value = 0x00;
}
}
else
{
Freescale Semiconductor, Inc...
// Second half
if (temp_value==0x00)
{
send_value = 0x00;
}
else
{
send_value = 0x80;
}
}
}
if (send_position==96)
{
send_value = 0x80; // Start of stop bit and settling time
}
if (send_position==112)
{
send_active = FALSE;
TSC |= 0x40;
// Enable timer overflow interrupt
ISCR = 0x04;
// Enable IRQ1 interrupt
}
}
send_position++;
}
if (PTB & 0x40)
{
low_counter = 0;
}
else
{
// If the signal level has been low for 500 ms then go to failure level
low_counter++;
if (low_counter>4800)
{
low_counter = 0;
flag |= SIGNAL_ERROR;
}
}
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
129
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
G.8 Slave: dali.lkf
Freescale Semiconductor, Inc...
#
#
LINK COMMAND FILE Example for 68HC908KX8
Copyright (c) 2000 by Motorola AB
+seg .text -b 0xE000 -m0x1E00 -nCODE -sROM # program start address
+seg .const -a CODE -it -sROM
# constants and strings
+seg .bsct -b 0x70 -m0x90 -nZPAGE -sRAM
# zero page start address
+seg .ubsct -a ZPAGE -nUZPAGE -sRAM
+seg .data -a UZPAGE -nIDATA -sRAM
# data start address
+seg .bss -a IDATA -nUDATA -sRAM
crtsi.o
# startup routine
main.o
# application program
cpu.o
dali.o
rs232.o
lamp.o
"C:\COSMIC\EVAL08\Lib\libi.h08"
"C:\COSMIC\EVAL08\Lib\libm.h08"
+seg .const -b 0xFFDC
vector.o
# vectors start address
# interrupt vectors
+def [email protected]
+def __stack=0x0FF
# symbol used by library
# stack pointer value
DRM004 — Rev. 3.0
130
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: iokx8.h
G.9 Slave: iokx8.h
/* IO DEFINITIONS FOR MC68HC908KX8
* Copyright (c) 2000 by Motorola AB
* Based on definition from Cosmic
*/
Freescale Semiconductor, Inc...
#define uint
unsigned int
/* PORTS section
*/
@tiny volatile char
@tiny volatile char
@tiny volatile char
@tiny volatile char
@tiny volatile char
PTA
PTB
DDRA
DDRB
PTAPUE
@0x00;
@0x01;
@0x04;
@0x05;
@0x0d;
/*
/*
/*
/*
/*
port A */
port B */
data direction port A */
data direction port B */
pull-up enable port A */
/* SCI section
*/
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
SCC1
SCC2
SCC3
SCS1
SCS2
SCDR
SCBR
@0x13;
@0x14;
@0x15;
@0x16;
@0x17;
@0x18;
@0x19;
/*
/*
/*
/*
/*
/*
/*
SCI
SCI
SCI
SCI
SCI
SCI
SCI
char
char
char
char
char
char
char
control register 1 */
control register 2 */
control register 3 */
status register 1 */
status register 2 */
data register */
baud rate */
/* KEYBOARD section
*/
@tiny volatile char KBSCR
@0x1a;
/* keyboard status/control register */
@tiny volatile char KBIER
@0x1b;
/* keyboard interrupt enable */
/* TIMEBASE section
*/
@tiny volatile char TBCR
@0x1c;
/* timebase module control */
/* IRQ section
*/
@tiny volatile char ISCR
@0x1d;
/* IRQ status/control register */
/* CONFIG section
*/
@tiny volatile char CONFIG1
@tiny volatile char CONFIG2
@0x1e;
@0x1f;
/* configuration register 1 */
/* configuration register 2 */
/* TIMER section
*/
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
131
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
@tiny
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
char
uint
char
char
uint
char
char
char
uint
char
char
char
uint
char
char
TSC
TCNT
TCNTH
TCNTL
TMOD
TMODH
TMODL
TSC0
TCH0
TCH0H
TCH0L
TSC1
TCH1
TCH1H
TCH1L
@0x20;
@0x21;
@0x21;
@0x22;
@0x23;
@0x23;
@0x24;
@0x25;
@0x26;
@0x26;
@0x27;
@0x28;
@0x29;
@0x29;
@0x2a;
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
char
char
char
char
char
ICGCR
ICGMR
ICGTR
ICGDVR
ICGDSR
@0x36;
@0x37;
@0x38;
@0x39;
@0x3a;
/*
/*
/*
/*
/*
ICG
ICG
ICG
ICG
ICG
/* A/D section
*/
@tiny volatile char ADSCR
@tiny volatile char ADR
@tiny volatile char ADICLK
@0x3c;
@0x3d;
@0x3e;
/* A/D status/ctrl register */
/* A/D data register */
/* A/D input clock register */
/* SIM section
*/
@near volatile char SBSR
@near volatile char SRSR
@near volatile char SBFCR
@0xfe00;
@0xfe01;
@0xfe03;
/* SIM break status register */
/* SIM reset status register */
/* SIM break control register */
/* INTERUPT section
*/
@near volatile char INT1
@near volatile char INT2
@near volatile char INT3
@0xfe04;
@0xfe05;
@0xfe06;
/* INTERUPT status register 1 */
/* INTERUPT status register 2 */
/* INTERUPT status register 3 */
/* FLASH section
*/
@near volatile char FLTCR
@near volatile char FLCR
@near volatile char FLBPR
@0xfe07;
@0xfe08;
@0xff7e;
/* FLASH test control register */
/* FLASH control register */
/* FLASH block protect register */
/* ICG section
*/
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
@tiny volatile
DRM004 — Rev. 3.0
132
status/ctrl register */
counter register */
counter high */
counter low */
modulo register */
modulo high */
modulo low */
chan 0 status/ctrl */
chan 0 register */
chan 0 high */
chan 0 low */
chan 1 status/ctrl */
chan 1 register */
chan 1 high */
chan 1 low */
control register */
multiplier register */
trim register */
divider control register */
stage control register */
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: iokx8.h
Freescale Semiconductor, Inc...
/* BREAK section
*/
@near volatile char
@near volatile uint
@near volatile char
@near volatile char
@near volatile char
BRKAR
BRK
BRKH
BRKL
BRKSCR
@0xfe02;
@0xfe09;
@0xfe09;
@0xfe0a;
@0xfe0b;
/*
/*
/*
/*
/*
BREAK
BREAK
BREAK
BREAK
BREAK
auxiliary register */
address register */
address register low */
address register high */
status/ctrl register */
/* LVI section
*/
@near volatile char LVISR
@0xfe0c;
/* LVI status register */
/* COP section
*/
@near volatile char COPCTL
@0xffff;
/* COP control register */
#undef uint
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
133
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.10 Slave: lamp.h
//
//
//
//
//
//
//
//
//
//
//
//
//
lamp.h
This header contains definitions for the lamp module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001215
010212
Reason/description
Initial version
Released version
#ifndef LAMP
#define LAMP
// Initialization
extern void lamp_Init(void);
// Handles new data
extern void lamp_HandleData(void);
// Set the lamp to failure level
extern void lamp_FailureLevel(void);
// Interrupt handler for the timer interface module
extern @interrupt void lamp_Tick(void);
#endif
DRM004 — Rev. 3.0
134
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: lamp.c
Freescale Semiconductor, Inc...
G.11 Slave: lamp.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
lamp.c
This module controls the lamp
Prepared: Motorola AB
Functional level: Hardware
Revision: R1C
Rev
P1A
P1B
R1A
R1B
R1C
Date
001215
000201
010212
011016
011210
Reason/description
Initial version
Improved current measurement
Released version
Adapted to new clock speed
Changed to buffered PWM
The timer interface module (TIM) and the analog-to-digital converter (ADC)
are used
#include "common.h"
#include "iokx8.h"
#include "command.h"
// Flash memory data definitions
#define START_OF_FLASH_BUFFER
#define STOP_OF_FLASH_BUFFER
(unsigned char *)0xFD80
(unsigned char *)0xFD9F
// 0xFDE0
// 0xFDFF
#define POWER_ON_LEVEL_ADDR
(unsigned char *)0xFD80
#define SYSTEM_FAILURE_LEVEL_ADDR
(unsigned char *)0xFD81
#define MIN_LEVEL_ADDR
(unsigned char *)0xFD82
#define MAX_LEVEL_ADDR
(unsigned char *)0xFD83
#define FADE_RATE_ADDR
#define FADE_TIME_ADDR
#define SHORT_ADDRESS_ADDR
(unsigned char *)0xFD84
(unsigned char *)0xFD85
(unsigned char *)0xFD86
#define RANDOM_ADDRESS_H_ADDR
(unsigned char *)0xFD87
#define RANDOM_ADDRESS_M_ADDR
(unsigned char *)0xFD88
#define RANDOM_ADDRESS_L_ADDR
(unsigned char *)0xFD89
#define GROUP_0_7_ADDR
#define GROUP_8_15_ADDR
#define SCENE_0_15_ADDR
(unsigned char *)0xFD8A
(unsigned char *)0xFD8B
(unsigned char *)0xFD8C
// Power-on level
address
// System failure
level address
// Minimum level
address
// Maximum level
address
// Fade rate address
// Fade time address
// Short address
address
// Random address
high address
// Random address
middle address
// Random address low
address
// Group 0-7 address
// Group 8-15 address
// Scene level array
0-15 address
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
135
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
#define POWER_ON_LEVEL
#define SYSTEM_FAILURE_LEVEL
*(POWER_ON_LEVEL_ADDR)
*(SYSTEM_FAILURE_LEVEL_ADDR)
#define
#define
#define
#define
#define
#define
#define
MIN_LEVEL
MAX_LEVEL
FADE_RATE
FADE_TIME
SHORT_ADDRESS
RANDOM_ADDRESS_H
RANDOM_ADDRESS_M
*(MIN_LEVEL_ADDR)
*(MAX_LEVEL_ADDR)
*(FADE_RATE_ADDR)
*(FADE_TIME_ADDR)
*(SHORT_ADDRESS_ADDR)
*(RANDOM_ADDRESS_H_ADDR)
*(RANDOM_ADDRESS_M_ADDR)
#define RANDOM_ADDRESS_L
#define GROUP_0_7
#define GROUP_8_15
*(RANDOM_ADDRESS_L_ADDR)
*(GROUP_0_7_ADDR)
*(GROUP_8_15_ADDR)
// Power-on level
// System failure
level
// Minimum level
// Maximum level
// Fade rate
// Fade time
// Short address
// Random address high
// Random address
middle
// Random address low
// Group 0-7
// Group 8-15
// Permanent data definitions
#define VERSION_NUMBER
#define PHYSICAL_MIN_LEVEL
0x00
0x01
// The current version number 0.0
// The physically lowest possible level
// Definition for the timer states
#define IDLE_STATE 0x00
#define INIT_STATE 0x01
first data arrives
#define FADE_STATE 0x02
// No change
// State during the first 600 ms or until the
// During this state the lamp is changing to a
new level
// Table containing conversions between light level values and logarithmic dimming
level
static const unsigned int log_level[253] = {
0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
0x0002, 0x0002, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0006,
0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0007, 0x0007, 0x0007,
0x0007, 0x0007, 0x0007, 0x0008, 0x0008, 0x0008, 0x0008, 0x0009,
0x0009, 0x0009, 0x0009, 0x000A, 0x000A, 0x000A, 0x000A, 0x000B,
0x000B, 0x000B, 0x000C, 0x000C, 0x000C, 0x000D, 0x000D, 0x000D,
0x000E, 0x000E, 0x000E, 0x000F, 0x000F, 0x0010, 0x0010, 0x0011,
0x0011, 0x0011, 0x0012, 0x0012, 0x0013, 0x0013, 0x0014, 0x0015,
0x0015, 0x0016, 0x0016, 0x0017, 0x0018, 0x0018, 0x0019, 0x001A,
0x001A, 0x001B, 0x001C, 0x001D, 0x001D, 0x001E, 0x001F, 0x0020,
0x0021, 0x0022, 0x0023, 0x0023, 0x0024, 0x0025, 0x0027, 0x0028,
0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002F, 0x0030, 0x0031,
0x0033, 0x0034, 0x0035, 0x0037, 0x0038, 0x003A, 0x003C, 0x003D,
0x003F, 0x0041, 0x0042, 0x0044, 0x0046, 0x0048, 0x004A, 0x004C,
0x004E, 0x0050, 0x0053, 0x0055, 0x0057, 0x005A, 0x005C, 0x005F,
0x0061, 0x0064, 0x0067, 0x006A, 0x006D, 0x0070, 0x0073, 0x0076,
DRM004 — Rev. 3.0
136
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: lamp.c
Freescale Semiconductor, Inc...
0x0079,
0x0097,
0x00BC,
0x00E9,
0x0122,
0x0169,
0x01C2,
0x022F,
0x02B8,
0x0362,
0x0435,
0x053C,
0x007D,
0x009B,
0x00C1,
0x00F0,
0x012A,
0x0173,
0x01CE,
0x023F,
0x02CB,
0x037A,
0x0453,
0x0561,
0x0080,
0x009F,
0x00C6,
0x00F7,
0x0133,
0x017E,
0x01DB,
0x024F,
0x02DF,
0x0392,
0x0472,
0x0587,
0x0084,
0x00A4,
0x00CC,
0x00FD,
0x013B,
0x0188,
0x01E8,
0x025F,
0x02F3,
0x03AC,
0x0491,
0x05AE,
0x0087, 0x008B,
0x00A8, 0x00AD,
0x00D1, 0x00D7,
0x0104, 0x010C,
0x0144, 0x014D,
0x0193, 0x019E,
0x01F5, 0x0203,
0x0270, 0x0281,
0x0308, 0x031E,
0x03C6, 0x03E0,
0x04B1, 0x04D3,
0x05D7 };
0x008F,
0x00B2,
0x00DD,
0x0113,
0x0156,
0x01AA,
0x0212,
0x0293,
0x0334,
0x03FC,
0x04F5,
0x0093,
0x00B7,
0x00E3,
0x011B,
0x0160,
0x01B5,
0x0220,
0x02A5,
0x034A,
0x0418,
0x0518,
// Number of timer ticks for each fade time
static const unsigned int fade_tick[15] = { 35, 50, 71, 100, 141, 200, 283, 400,
566, 800, 1131, 1600, 2263, 3200, 4526 };
// Number of level steps during 200 ms
static const unsigned char fade_step[15] = { 72, 51, 36, 25, 18, 13, 9, 6, 4, 3, 2,
2, 1, 1, 1 };
static unsigned char level;
// The light level
static unsigned char search_address_h;
static unsigned char search_address_m;
static unsigned char search_address_l;
// Search address high
// Search address middle
// Search address low
static unsigned char dtr;
// The DTR register
static unsigned char last_channel;
// Last channel register used
static unsigned char state_no;
static unsigned int state_time;
// Holds the current state for the timer
// Time until state or level is changed
static unsigned char fade_start_level;
static unsigned char fade_stop_level;
static unsigned int fade_total;
// Start level before fading
// Stop level after fading
// Total time for fade
static unsigned char repeat_time;
static unsigned char repeat_address;
static unsigned char repeat_command;
// Time until repetation time expires
// Address that should be repeated
// Command that should be repeated
static unsigned int address_time;
// Time until addressing commands are
illegal
static unsigned char power_failure;
// Flag is true until certain commands has
arrived
static unsigned char limit_error;
// True if the last requested level was out
of limit
static unsigned char measure_time;
// Time until lamp current can be measured
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
137
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
// Write data into flash at address
static void lamp_WriteFlash(unsigned char *flash_address, unsigned char new_data)
{
unsigned char index;
Freescale Semiconductor, Inc...
// Set all variables necessary
*CTRLBYT = 0x00;
// Page erase
*CPUSPD = 0x4F;
// 4 * 19.6608
*LADDR = (unsigned int)STOP_OF_FLASH_BUFFER; // Last address in the flash memory
// Copy data to buffer
for (index = 0; index<32; index++)
{
*(DATA+index) = *(START_OF_FLASH_BUFFER+index);
}
// Merge the new data into the data buffer
*(DATA+(unsigned char)(flash_address-START_OF_FLASH_BUFFER)) = new_data;
di(); // Disable all interrupts during flash erase and flash write
// Place erase start address in H:X and call the erase routine
flash_erase();
// Place write start address in H:X and call the write routine
flash_write();
ei(); // Enable all interrupts
}
// Reset flash content
static void lamp_ResetFlash(void)
{
unsigned char index;
// Set all variables necessary
*CTRLBYT = 0x00;
// Page erase
*CPUSPD = 0x4F;
// 4 * 19.6608
*LADDR = (unsigned int)STOP_OF_FLASH_BUFFER; // Last address in the flash memory
// Copy data to buffer
for (index = 0; index<32; index++)
{
*(DATA+index) = *(START_OF_FLASH_BUFFER+index);
}
// Merge the new data into the data buffer
*(DATA+((unsigned char)(POWER_ON_LEVEL_ADDR-START_OF_FLASH_BUFFER))) = 254;
*(DATA+((unsigned char)(SYSTEM_FAILURE_LEVEL_ADDR-START_OF_FLASH_BUFFER)))
= 254;
DRM004 — Rev. 3.0
138
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
*(DATA+((unsigned char)(MIN_LEVEL_ADDR-START_OF_FLASH_BUFFER))) =
PHYSICAL_MIN_LEVEL;
*(DATA+((unsigned char)(MAX_LEVEL_ADDR-START_OF_FLASH_BUFFER))) = 254;
*(DATA+((unsigned char)(FADE_RATE_ADDR-START_OF_FLASH_BUFFER))) = 7;
*(DATA+((unsigned char)(FADE_TIME_ADDR-START_OF_FLASH_BUFFER))) = 0;
*(DATA+((unsigned char)(RANDOM_ADDRESS_H_ADDR-START_OF_FLASH_BUFFER))) = 0xFF;
*(DATA+((unsigned char)(RANDOM_ADDRESS_M_ADDR-START_OF_FLASH_BUFFER))) = 0xFF;
*(DATA+((unsigned char)(RANDOM_ADDRESS_L_ADDR-START_OF_FLASH_BUFFER))) = 0xFF;
*(DATA+((unsigned char)(GROUP_0_7_ADDR-START_OF_FLASH_BUFFER))) = 0x00;
*(DATA+((unsigned char)(GROUP_8_15_ADDR-START_OF_FLASH_BUFFER))) = 0x00;
for (index = 0; index<16; index++)
{
*(DATA+((unsigned char)(SCENE_0_15_ADDR-START_OF_FLASH_BUFFER+index))) = 255;
}
di(); // Disable all interrupts during flash erase and flash write
// Place erase start address in H:X and call the erase routine
flash_erase();
// Place write start address in H:X and call the write routine
flash_write();
ei(); // Enable all interrupts
}
// Set the light level
static void lamp_SetLevel(unsigned char wanted_level)
{
unsigned char new_level;
limit_error = FALSE;
new_level = wanted_level;
if (new_level>=1 && new_level<=254)
{
if (new_level<MIN_LEVEL)
{
new_level = MIN_LEVEL;
limit_error = TRUE;
}
if (new_level>MAX_LEVEL)
{
new_level = MAX_LEVEL;
limit_error = TRUE;
}
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
139
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
if (new_level==0)
{
if (last_channel==0)
{
TCH1 = 0x0000;
last_channel = 1;
}
else
{
TCH0 = 0x0000;
last_channel = 0;
}
TSC0 &= ~0x01;
level = new_level;
}
if (new_level>=1 && new_level<=253)
{
if (last_channel==0)
{
TCH1 = log_level[new_level-1];
last_channel = 1;
}
else
{
TCH0 = log_level[new_level-1];
last_channel = 0;
}
TSC0 &= ~0x01;
level = new_level;
}
if (new_level==254)
{
TSC0 |= 0x01;
level = new_level;
}
// Lamp off
// Lamp off
// Not 100% duty cycle
// Set the PWM period
// Set the PWM period
// Not 100% duty cycle
// 100% duty cycle
}
// Test if lamp is functional, returns TRUE if bad lamp
static unsigned char lamp_TestFailure(void)
{
unsigned char current_level;
current_level = level;
lamp_SetLevel(254);
// Turn on lamp for measurement
measure_time = 5;
while (measure_time!=0)
{
COPCTL = 0x00;
}
// Wait until level is stabilized (100 ms)
DRM004 — Rev. 3.0
140
// Clear the COP counter
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: lamp.c
Freescale Semiconductor, Inc...
// Measure voltage over shunt resistor by using the built-in A/D-converter
ADICLK = 0x80;
// Set the ADC input clock to approximately 1 MHz
ADSCR = 0x03;
// Select channel 3 and start conversion
while ((ADSCR & 0x80)==0)
// Wait until conversion is ready
;
lamp_SetLevel(current_level);
// Restore the previous level
if (ADR>0)
{
return (FALSE);
}
return (TRUE);
// Lamp is working
}
// Start dimming using the fade time
static void lamp_StartDimFadeTime(unsigned char new_level)
{
if (new_level!=255)
{
// Not mask
if (FADE_TIME==0)
{
// No fade
lamp_SetLevel(new_level);
state_no = IDLE_STATE;
}
else
{
// Fade with fade time
fade_start_level = level;
fade_stop_level = new_level;
fade_total = fade_tick[FADE_TIME-1];
state_time = fade_total;
state_no = FADE_STATE;
}
}
}
// Handle special commands
static void lamp_HandleSpecialCommands(void)
{
static unsigned withdraw;
static unsigned selection;
unsigned long random_address;
unsigned long search_address;
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
141
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
// Special command
if (address>=0xA7 && address<=0xBD && address_time==0)
{
// Not a valid command until INITIALISE has been received
return;
}
switch (address)
{
case TERMINATE:
address_time = 0;
break;
case DATA_TRANSFER_REGISTER:
dtr = command;
break;
case INITIALISE:
if (command==0x00 || ((command & 0x7E)>>1)==SHORT_ADDRESS)
{
address_time = 45000; // Accept addressing commands for the next
15 minutes
withdraw = FALSE;
selection = FALSE;
}
break;
case RANDOMISE:
// The algorithm used to get a random number can be improved
lamp_WriteFlash(RANDOM_ADDRESS_H_ADDR, TCNTL); // Read timer counter to get
a random number
lamp_WriteFlash(RANDOM_ADDRESS_M_ADDR, TCNTL); // Read timer counter to get
a random number
lamp_WriteFlash(RANDOM_ADDRESS_L_ADDR, TCNTL); // Read timer counter to get
a random number
break;
case COMPARE:
random_address = RANDOM_ADDRESS_H<<16 | RANDOM_ADDRESS_M<<8 |
RANDOM_ADDRESS_L;
search_address = search_address_h<<16 | search_address_m<<8 |
search_address_l;
if (random_address!=search_address || withdraw==FALSE)
{
if (random_address<=search_address)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
}
break;
case WITHDRAW:
withdraw = TRUE;
break;
DRM004 — Rev. 3.0
142
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
case SEARCHADDRH:
search_address_h = command;
break;
case SEARCHADDRM:
search_address_m = command;
break;
case SEARCHADDRL:
search_address_l = command;
break;
case PROGRAM_SHORT_ADDRESS:
if (selection==TRUE)
{
if (lamp_TestFailure()==TRUE)
{
if (command==255)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, 255);
}
else
{
if (((dtr & 0x7E)>>1)<=63)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, (command & 0x7E)>>1);
}
}
}
}
else
{
random_address = RANDOM_ADDRESS_H<<16 | RANDOM_ADDRESS_M<<8 |
RANDOM_ADDRESS_L;
search_address = search_address_h<<16 | search_address_m<<8 |
search_address_l;
if (random_address==search_address)
{
if (command==255)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, 255);
}
else
{
if (((dtr & 0x7E)>>1)<=63)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, (command & 0x7E)>>1);
}
}
}
}
break;
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
143
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
case VERIFY_SHORT_ADDRESS:
if (SHORT_ADDRESS==((command & 0x7E)>>1))
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_SHORT_ADDRESS:
if (selection==TRUE)
{
if (lamp_TestFailure()==TRUE)
{
answer = SHORT_ADDRESS;
flag |= SEND_ANSWER;
}
}
else
{
random_address = RANDOM_ADDRESS_H<<16 | RANDOM_ADDRESS_M<<8 |
RANDOM_ADDRESS_L;
search_address = search_address_h<<16 | search_address_m<<8 |
search_address_l;
if (random_address==search_address)
{
answer = SHORT_ADDRESS;
flag |= SEND_ANSWER;
}
}
break;
case PHYSICAL_SELECTION:
selection = TRUE;
break;
default:
break;
}
}
// Handle normal commands
static void lamp_HandleNormalCommands(void)
{
// Normal commands
switch (command)
{
case OFF:
power_failure = FALSE;
lamp_SetLevel(0);
state_no = IDLE_STATE;
break;
DRM004 — Rev. 3.0
144
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
case UP:
if (level!=0 && level!=MAX_LEVEL)
{
fade_start_level = level;
if (fade_step[FADE_RATE-1]>(MAX_LEVEL-level))
{
fade_stop_level = MAX_LEVEL;
fade_total = (unsigned
int)(MAX_LEVEL-level)*10/fade_step[FADE_RATE-1];
// No of ms until MAX_LEVEL
is reached
}
else
{
fade_stop_level = level+fade_step[FADE_RATE-1];
fade_total = 10; // 200 ms
}
state_time = fade_total;
state_no = FADE_STATE;
}
break;
case DOWN:
if (level!=0 && level!=MIN_LEVEL)
{
fade_start_level = level;
if (fade_step[FADE_RATE-1]>(level-MIN_LEVEL))
{
fade_stop_level = MIN_LEVEL;
fade_total = (unsigned
int)(level-MIN_LEVEL)*10/fade_step[FADE_RATE-1];
// No of ms until MIN_LEVEL
is reached
}
else
{
fade_stop_level = level-fade_step[FADE_RATE-1];
fade_total = 10; // 200 ms
}
state_time = fade_total;
state_no = FADE_STATE;
}
break;
case STEP_UP:
if (level!=0 && level!=MAX_LEVEL)
{
lamp_SetLevel(level+1);
state_no = IDLE_STATE;
}
break;
case STEP_DOWN:
if (level!=0 && level!=MIN_LEVEL)
{
lamp_SetLevel(level-1);
state_no = IDLE_STATE;
}
break;
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
145
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
case RECALL_MAX_LEVEL:
power_failure = FALSE;
lamp_SetLevel(MAX_LEVEL);
state_no = IDLE_STATE;
break;
case RECALL_MIN_LEVEL:
power_failure = FALSE;
lamp_SetLevel(MIN_LEVEL);
state_no = IDLE_STATE;
break;
case STEP_DOWN_AND_OFF:
power_failure = FALSE;
if (level!=0)
{
if (level==MIN_LEVEL)
{
lamp_SetLevel(0);
}
else
{
lamp_SetLevel(level-1);
}
state_no = IDLE_STATE;
}
break;
case ON_AND_STEP_UP:
power_failure = FALSE;
if (level!=MAX_LEVEL)
{
if (level==0)
{
lamp_SetLevel(MIN_LEVEL);
}
else
{
lamp_SetLevel(level+1);
}
state_no = IDLE_STATE;
}
break;
case RESET:
search_address_h = 0xFF;
search_address_m = 0xFF;
search_address_l = 0xFF;
lamp_ResetFlash();
lamp_SetLevel(254);
state_no = IDLE_STATE;
break;
case STORE_ACTUAL_LEVEL_IN_THE_DTR:
dtr = level;
break;
DRM004 — Rev. 3.0
146
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
case STORE_THE_DTR_AS_MAX_LEVEL:
if (dtr>=MIN_LEVEL && dtr<=254)
{
lamp_WriteFlash(MAX_LEVEL_ADDR, dtr);
}
break;
case STORE_THE_DTR_AS_MIN_LEVEL:
if (dtr>=PHYSICAL_MIN_LEVEL && dtr<=MAX_LEVEL)
{
lamp_WriteFlash(MIN_LEVEL_ADDR, dtr);
}
break;
case STORE_THE_DTR_AS_SYSTEM_FAILURE_LEVEL:
lamp_WriteFlash(MIN_LEVEL_ADDR, dtr);
break;
case STORE_THE_DTR_AS_POWER_ON_LEVEL:
if (dtr>=1 && dtr<=254)
{
lamp_WriteFlash(MIN_LEVEL_ADDR, dtr);
}
break;
case STORE_THE_DTR_AS_FADE_TIME:
lamp_WriteFlash(FADE_TIME_ADDR, dtr & 0x0F);
break;
case STORE_THE_DTR_AS_FADE_RATE:
if (dtr & 0x0F)
{
lamp_WriteFlash(FADE_RATE_ADDR, dtr & 0x0F);
}
break;
case STORE_DTR_AS_SHORT_ADDRESS:
if (dtr==255)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, 255);
}
else
{
if (((dtr & 0x7E)>>1)<=63)
{
lamp_WriteFlash(SHORT_ADDRESS_ADDR, (dtr & 0x7E)>>1);
}
}
break;
case QUERY_STATUS:
answer = 0x00;
if (lamp_TestFailure()==TRUE)
{
answer |= 0x02;
}
if (level)
{
answer |= 0x04;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
147
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
if (limit_error==TRUE)
{
answer |= 0x08;
}
if (state_no==FADE_STATE)
{
answer |= 0x10;
}
if (state_no==INIT_STATE)
{
answer |= 0x20;
}
if (SHORT_ADDRESS==255)
{
answer |= 0x40;
}
if (power_failure==TRUE)
{
answer |= 0x80;
}
flag |= SEND_ANSWER;
break;
case QUERY_BALLAST:
answer = 0xFF; // YES
flag |= SEND_ANSWER;
break;
case QUERY_LAMP_FAILURE:
if (lamp_TestFailure()==TRUE)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_LAMP_POWER_ON:
if (level)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_LIMIT_ERROR:
if (limit_error==TRUE)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_RESET_STATE:
if (state_no==INIT_STATE)
{
answer = 0xFF; // YES
DRM004 — Rev. 3.0
148
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
flag |= SEND_ANSWER;
}
break;
case QUERY_MISSING_SHORT_ADDRESS:
if (SHORT_ADDRESS==255)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_VERSION_NUMBER:
answer = VERSION_NUMBER;
flag |= SEND_ANSWER;
break;
case QUERY_CONTENT_DTR:
answer = dtr;
flag |= SEND_ANSWER;
break;
case QUERY_DEVICE_TYPE:
answer = 0; // For low voltage halogen lamps this is 3 but no extended
commands are available
flag |= SEND_ANSWER;
break;
case QUERY_PHYSICAL_MINIMUM_LEVEL:
answer = PHYSICAL_MIN_LEVEL;
flag |= SEND_ANSWER;
break;
case QUERY_POWER_FAILURE:
if (power_failure==TRUE)
{
answer = 0xFF; // YES
flag |= SEND_ANSWER;
}
break;
case QUERY_ACTUAL_LEVEL:
answer = level;
flag |= SEND_ANSWER;
break;
case QUERY_MAX_LEVEL:
answer = MAX_LEVEL;
flag |= SEND_ANSWER;
break;
case QUERY_MIN_LEVEL:
answer = MIN_LEVEL;
flag |= SEND_ANSWER;
break;
case QUERY_POWER_ON_LEVEL:
answer = POWER_ON_LEVEL;
flag |= SEND_ANSWER;
break;
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
149
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
case QUERY_SYSTEM_FAILURE_LEVEL:
answer = SYSTEM_FAILURE_LEVEL;
flag |= SEND_ANSWER;
break;
case QUERY_FADE:
answer = FADE_TIME<<4 | FADE_RATE;
flag |= SEND_ANSWER;
break;
case QUERY_GROUPS_0_7:
answer = GROUP_0_7;
flag |= SEND_ANSWER;
break;
case QUERY_GROUPS_8_15:
answer = GROUP_8_15;
flag |= SEND_ANSWER;
break;
case QUERY_RANDOM_ADDRESS_H:
answer = RANDOM_ADDRESS_H;
flag |= SEND_ANSWER;
break;
case QUERY_RANDOM_ADDRESS_M:
answer = RANDOM_ADDRESS_M;
flag |= SEND_ANSWER;
break;
case QUERY_RANDOM_ADDRESS_L:
answer = RANDOM_ADDRESS_L;
flag |= SEND_ANSWER;
break;
default:
break;
}
switch (command & 0xF0)
{
case GO_TO_SCENE:
power_failure = FALSE;
lamp_StartDimFadeTime(*(SCENE_0_15_ADDR+(command & 0x0F)));
break;
case STORE_THE_DTR_AS_SCENE:
lamp_WriteFlash(SCENE_0_15_ADDR+(command & 0x0F), dtr);
break;
case REMOVE_FROM_SCENE:
lamp_WriteFlash(SCENE_0_15_ADDR+(command & 0x0F), 255);
break;
case ADD_TO_GROUP:
if ((command & 0x0F)<=7)
{
lamp_WriteFlash(GROUP_0_7_ADDR, GROUP_0_7 | (1<<(command & 0x0F)));
}
else
{
lamp_WriteFlash(GROUP_8_15_ADDR, GROUP_8_15 | (1<<((command &
0x0F)-8)));
DRM004 — Rev. 3.0
150
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
}
break;
case REMOVE_FROM_GROUP:
if ((command & 0x0F)<=7)
{
lamp_WriteFlash(GROUP_0_7_ADDR, GROUP_0_7 & ~(1<<(command & 0x0F)));
}
else
{
lamp_WriteFlash(GROUP_8_15_ADDR, GROUP_8_15 & ~(1<<((command &
0x0F)-8)));
}
break;
case QUERY_SCENE_LEVEL:
answer = *(SCENE_0_15_ADDR+(command & 0x0F));
flag |= SEND_ANSWER;
break;
default:
break;
}
}
// Initialization
void lamp_Init(void)
{
// Reset values that are not stored in flash
power_failure = TRUE;
// This is true until certain commands has arrived
limit_error = FALSE;
// No error
dtr = 0;
level = 0;
search_address_h = 0xFF;
search_address_m = 0xFF;
search_address_l = 0xFF;
// Initialize flash values if necessary
if (POWER_ON_LEVEL==255) // Check if flash has been written
{
// Write factory information into flash
lamp_WriteFlash(SHORT_ADDRESS_ADDR, 255);
// No short address
lamp_ResetFlash();
}
repeat_time = 0;
address_time = 0;
// Initialize when starting
// Initialize when starting
// Start timer for initial lamp values
state_time = 30;
// 600 ms
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
151
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
state_no = INIT_STATE;
// Initialize the timer interface module
TSC = 0x76;
// Stop and reset counter, Set prescaler to internal bus/64,
Enable timer overflow interrupt
TMOD = 0x0600;
// Period 50 Hz
Freescale Semiconductor, Inc...
// Initialize channel 0 for PWM
TCH0 = 0x0000;
// Clear channel 0 compare register
last_channel = 0;
TSC0 = 0x3A;
// Set channel 0 to buffered PWM mode
TSC &= ~0x20;
// Start counter
}
// Handles new data
void lamp_HandleData(void)
{
unsigned int group;
// Check if this message is for this unit
if ((address & 0xE1)!=0xA1 && (address & 0xE1)!=0xC1 && (address & 0xFE)!=0xFE)
// Special command or broadcast message
{
if ((address & 0xE0)==0x80)
{
// Group address
group = GROUP_8_15<<8 | GROUP_0_7;
if ((group>>((address & 0x1E)>>1) & 0x01)==0)
{
// Not in this group
return;
}
}
if ((address & 0x80)==0x00)
{
// Short address
if (((address & 0x7E)>>1)!=SHORT_ADDRESS)
{
// Wrong short address
return;
}
}
}
// Message is intended for his unit
// Check if repetetion shall be interrupted
if (repeat_time!=0)
{
// Waiting for repeated message
DRM004 — Rev. 3.0
152
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: lamp.c
if (address!=repeat_address || command!=repeat_command)
{
// Ignore message and clear repeat timer
repeat_time = 0;
return;
}
Freescale Semiconductor, Inc...
}
if ((address & 0x01)==0)
{
// Direct arc power control command
power_failure = FALSE;
lamp_StartDimFadeTime(command);
return;
}
// Check if commands shall be repeated
if ((address & 0xE0)==0xA0 || (address & 0xE0)==0xC0)
{
// Special command
if (address==INITIALISE || address==RANDOMISE)
{
// These commands shall be repeated
if (repeat_time==0)
{
repeat_address = address;
repeat_command = command;
repeat_time = 5;
// 100 ms
return;
}
}
}
else
{
// Normal command
if (command>=0x20 && command<=0x80)
{
// These commands shall be repeated
if (repeat_time==0)
{
repeat_address = address;
repeat_command = command;
repeat_time = 5;
// 100 ms
return;
}
}
}
repeat_time = 0;
if ((address & 0xE0)==0xA0 || (address & 0xE0)==0xC0)
{
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
153
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
// Handle special commands
lamp_HandleSpecialCommands();
}
else
{
// Handle normal commands
lamp_HandleNormalCommands();
}
Freescale Semiconductor, Inc...
}
// Set the lamp to failure level
void lamp_FailureLevel(void)
{
state_no = IDLE_STATE;
lamp_SetLevel(SYSTEM_FAILURE_LEVEL);
}
// Interrupt handler for timer interface module
@interrupt void lamp_Tick(void)
{
unsigned char new_level;
unsigned char diff_level;
TSC &= ~0x80;
// Clear the TIM Overflow Flag Bit
if (measure_time!=0)
{
measure_time--;
}
if (repeat_time!=0)
{
repeat_time--;
}
if (address_time!=0)
{
address_time--;
}
switch (state_no)
{
case IDLE_STATE:
break;
case INIT_STATE:
state_time--;
if (state_time==0)
{
state_no = IDLE_STATE;
lamp_SetLevel(POWER_ON_LEVEL);
}
break;
DRM004 — Rev. 3.0
154
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: lamp.c
case FADE_STATE:
state_time--;
if (state_time==0)
{
state_no = IDLE_STATE;
}
// Calculate fade
if (fade_start_level>fade_stop_level)
{
// Dim down
if (fade_stop_level==0)
{
if (state_time==0)
{
new_level = 0;
}
else
{
// Use MIN_LEVEL instead of 0
diff_level = (unsigned char)((((unsigned
long)fade_start_level-(unsigned long)MIN_LEVEL)*((unsigned long)fade_total-(unsigned
long)state_time))/(unsigned long)fade_total);
new_level = fade_start_level-diff_level;
}
}
else
{
diff_level = (unsigned char)((((unsigned
long)fade_start_level-(unsigned long)fade_stop_level)*((unsigned
long)fade_total-(unsigned long)state_time))/(unsigned long)fade_total);
new_level = fade_start_level-diff_level;
}
}
else
{
// Dim up
diff_level = (unsigned char)((((unsigned long)fade_stop_level-(unsigned
long)fade_start_level)*((unsigned long)fade_total-(unsigned
long)state_time))/(unsigned long)fade_total);
new_level = fade_start_level+diff_level;
}
if (new_level!=level)
{
lamp_SetLevel(new_level);
}
break;
default:
break;
}
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
155
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.12 Slave: main.c
//
//
//
//
//
//
//
//
//
//
//
//
//
main.c
This module contains the main function
Prepared: Motorola AB
Functional level: Application
Revision: R1A
Rev
P1A
R1A
Date
001023
010212
#include
#include
#include
#include
#include
#include
Reason/description
Initial version
Released version
"common.h"
"iokx8.h"
"cpu.h"
"rs232.h"
"dali.h"
"lamp.h"
// Global variables declaration
unsigned char address;
unsigned char command;
// The DALI address
// The DALI command
unsigned char answer;
// The DALI answer
unsigned int flag;
// Keep track of all events
// Main function
void main(void)
{
address = 0x00;
command = 0x00;
// Initialize when starting
// Initialize when starting
answer = 0x00;
// Initialize when starting
flag = 0x00;
// Initialize when starting
cpu_Init();
rs232_Init();
dali_Init();
lamp_Init();
//
//
//
//
ei();
// Enable interrupt
DRM004 — Rev. 3.0
156
Initialize
Initialize
Initialize
Initialize
the
the
the
the
cpu module
rs232 module
dali module
lamp module
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
Slave: main.c
PTA &= ~0x08;
// Switch on LED
while (1==1)
{
COPCTL = 0x00;
// Loop forever
// Clear the COP counter
// NEW_DATA flag can be set from the dali module or from the rs232
module
if (flag & NEW_DATA)
{
flag &= ~NEW_DATA;
// Clear the NEW_DATA flag
lamp_HandleData();
}
// SEND_ANSWER flag can be set from the lamp module
if (flag & SEND_ANSWER)
{
flag &= ~SEND_ANSWER;
// Clear the SEND_ANSWER flag
dali_SendAnswer();
// Send answer on the dali port
rs232_SendAnswer();
// Send answer on the rs232 port
}
// SIGNAL_ERROR flag can be set from the dali module
if (flag & SIGNAL_ERROR)
{
flag &= ~SIGNAL_ERROR; // Clear the SIGNAL_ERROR flag
lamp_FailureLevel();
}
}
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
157
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Freescale Semiconductor, Inc...
G.13 Slave: rs232.h
//
//
//
//
//
//
//
//
//
//
//
//
//
rs232.h
This header contains definitions for the rs232 module
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
Date
001027
010212
Reason/description
Initial version
Released version
#ifndef RS232
#define RS232
// Initialize
extern void rs232_Init(void);
// Sends the DALI answer on the rs232 port
extern void rs232_SendAnswer(void);
// Interrupt handler for received data on the rs232 port
extern @interrupt void rs232_ReceiveData(void);
#endif
DRM004 — Rev. 3.0
158
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: rs232.c
Freescale Semiconductor, Inc...
G.14 Slave: rs232.c
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
rs232.c
This module handles all tasks related to the rs232 port
Prepared: Motorola AB
Functional level: Hardware
Revision: R1B
Rev
P1A
R1A
R1B
Date
001027
010212
011016
Reason/description
Initial version
Released version
Adapted to new clock speed
The serial communication interface (SCI) module is used
#include "common.h"
#include "iokx8.h"
static unsigned char first; // Keeps track if incoming data is address or command
// Initialize
void rs232_Init(void)
{
SCBR = 0x05;
//
SCC1 = 0x40;
//
SCC2 = 0x2C;
//
enabled
first = TRUE;
//
}
Baud rate 9600
Enable SCI
Enable receive interrupt, transmitter enabled, receiver
Next incoming byte is an address
// Sends the answer on the rs232 port
void rs232_SendAnswer(void)
{
while ((SCS1 & 0x80)==0x00) // Wait until transmit buffer is empty
;
SCDR = answer;
}
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
159
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
// Interrupt handler for received data on the rs232 port
@interrupt void rs232_ReceiveData(void)
{
if (SCS1 & 0x20)
// Received data available in SCDR
{
if (first==TRUE)
{
address = SCDR;
first = FALSE; // Next data is a command
}
else
{
command = SCDR;
first = TRUE;
// Next data is an address
flag |= NEW_DATA;
}
}
}
DRM004 — Rev. 3.0
160
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
DALI Slave Source Code Files
Slave: vector.c
Freescale Semiconductor, Inc...
G.15 Slave: vector.c
//
//
//
//
//
//
//
//
//
//
//
//
//
vector.c
This module contains the interrupt vector
Prepared: Motorola AB
Functional level: Hardware
Revision: R1A
Rev
P1A
R1A
#include
#include
#include
#include
Date
001023
010212
Reason/description
Initial version
Released version
"cpu.h"
"rs232.h"
"dali.h"
"lamp.h"
void (* const _vectab[])()
{
dali_Tick,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
rs232_ReceiveData, //
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
lamp_Tick,
//
cpu_Trap,
//
cpu_Trap,
//
cpu_Trap,
//
dali_Start,
//
cpu_Trap,
//
_stext
//
};
=
Timebase module
ADC conversion complete
Keyboard
SCI transmit
SCI receive
SCI receive error
Reserved
Reserved
Reserved
Reserved
Reserved
TIM overflow
TIM channel 1
TIM channel 0
CMIREQ
IRQ1
SWI
Reset
Digitally Addressable Lighting Interface (DALI) Unit
MOTOROLA
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
DRM004 — Rev. 3.0
161
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
DALI Slave Source Code Files
DRM004 — Rev. 3.0
162
Digitally Addressable Lighting Interface (DALI) Unit
DALI Slave Source Code Files
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
HOW TO REACH US:
USA/EUROPE/LOCATIONS NOT LISTED:
Motorola Literature Distribution;
P.O. Box 5405, Denver, Colorado 80217
1-303-675-2140 or 1-800-441-2447
JAPAN:
Motorola Japan Ltd.; SPS, Technical Information Center,
3-20-1, Minami-Azabu Minato-ku, Tokyo 106-8573 Japan
81-3-3440-3569
Freescale Semiconductor, Inc...
ASIA/PACIFIC:
Motorola Semiconductors H.K. Ltd.;
Silicon Harbour Centre, 2 Dai King Street,
Tai Po Industrial Estate, Tai Po, N.T., Hong Kong
852-26668334
TECHNICAL INFORMATION CENTER:
Information in this document is provided solely to enable system and software
implementers to use Motorola products. There are no express or implied copyright
licenses granted hereunder to design or fabricate any integrated circuits or
integrated circuits based on the information in this document.
Motorola reserves the right to make changes without further notice to any products
herein. Motorola makes no warranty, representation or guarantee regarding the
1-800-521-6274
suitability of its products for any particular purpose, nor does Motorola assume any
HOME PAGE:
liability arising out of the application or use of any product or circuit, and specifically
http://www.motorola.com/semiconductors
disclaims any and all liability, including without limitation consequential or incidental
damages. “Typical” parameters which may be provided in Motorola data sheets
and/or specifications can and do vary in different applications and actual
performance may vary over time. All operating parameters, including “Typicals”
must be validated for each customer application by customer’s technical experts.
Motorola does not convey any license under its patent rights nor the rights of
others. Motorola products are not designed, intended, or authorized for use as
components in systems intended for surgical implant into the body, or other
applications intended to support or sustain life, or for any other application in which
the failure of the Motorola product could create a situation where personal injury or
death may occur. Should Buyer purchase or use Motorola products for any such
unintended or unauthorized application, Buyer shall indemnify and hold Motorola
and its officers, employees, subsidiaries, affiliates, and distributors harmless
against all claims, costs, damages, and expenses, and reasonable attorney fees
arising out of, directly or indirectly, any claim of personal injury or death associated
with such unintended or unauthorized use, even if such claim alleges that Motorola
was negligent regarding the design or manufacture of the part.
Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark
Office. digital dna is a trademark of Motorola, Inc. All other product or service
names are the property of their respective owners. Motorola, Inc. is an Equal
Opportunity/Affirmative Action Employer.
© Motorola, Inc. 2002
DRM004/D
For More Information On This Product,
Go to: www.freescale.com