an4842, s12zvl lin enabled rgb led lighting application ... · rgb led d6 pin assignment rgb led...
TRANSCRIPT
Freescale SemiconductorApplication Note
Document Number: AN4842Rev. 1.0, 03/2014
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1RGB LED lighting application . . . . . . . . . . . . . . . . . . . . . 2
2.1 RGB LED application circuitry . . . . . . . . . . . . . . . . . 32.2 RGB LED control . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3 RGB LED diagnostics . . . . . . . . . . . . . . . . . . . . . . . 42.4 LIN Slave node position detection. . . . . . . . . . . . . . 5MC9S12ZVL32 modules configuration . . . . . . . . . . . . . . 6
3.1 Clock, Reset and Power Management Unit. . . . . . . 63.2 Timer Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.3 Pulse Width Modulator . . . . . . . . . . . . . . . . . . . . . . 73.4 Analog-to-Digital Converter . . . . . . . . . . . . . . . . . . . 73.5 Port Integration Module . . . . . . . . . . . . . . . . . . . . . . 73.6 Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8RGB LED lighting application demo . . . . . . . . . . . . . . . . 9
4.1 Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.3 Demo set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Acronyms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
ppendix AX-S12ZVL32-USLED board schematic . . . . . . . . 15
S12ZVL LIN Enabled RGB LED Lighting ApplicationBased on the MC9S12ZVL32 MagniV Deviceby: Petr Cholasta
1 IntroductionThis application note introduces the MC9S12ZVL32 device in an RGB LED lighting application, capable of RGB LED control and diagnostics.
The MC9S12ZVL32 integrates a 16-bit microcontroller built on proven S12 technology, an automotive voltage regulator, a LIN interface, a VSUP module to sense automotive battery voltage and an HVI pin [1].
The RGB LED lighting application is controlled using the FreeMASTER tool [2].
Part of this document is the AN4842SW.zip file containing X-S12ZVL32-USLED hardware and software files.
12
3
4
56A
© Freescale Semiconductor, Inc., 2014. All rights reserved.
RGB LED lighting application
2 RGB LED lighting applicationFigure 1 shows the RGB LED lighting application block diagram. The blue boxes represent MC9S12ZVL32 modules and the light brown boxes represent the software modules.
Figure 1. Application block diagram
The RGB LED is controlled using the FreeMASTER tool control page [2]. The RGB LED voltage is sensed using the ADC and recalculated to the LED average current using the AMMCLIB modules [3] to enable LED diagnostics.
The RGB LED control and diagnostics can be monitored by the LIN.
For a detailed description, see the following sections.
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor2
RGB LED lighting application
2.1 RGB LED application circuitryThe RGB LED is controlled by the MCU PWM1, PWM3 and PWM5 outputs, see Figure 2. The RGB LED voltage is sensed using resistors R6, R7, R8 by the MCU AN3, AN4 and AN5 inputs, see Table 1.
The MCU +5 V regulator is using the external ballast transistor Q3. The Q3 helps to reduce MCU power dissipation and extends the regulator current capability as well. The module reverse battery protection is guaranteed by diode D5.
Figure 2. RGB LED application circuitry
Table 1. RGB LED D6 pin assignment
RGB LEDpins
RGB LED color
RGB LED control
RGD LED diagnostic
A1, C1 Blue PWM3 AN3
A2, C2 Red PWM1 AN4
A3, C3 Green PWM5 AN5
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 3
RGB LED lighting application
2.2 RGB LED controlThe PWM module drives the LED with a 16-bit resolution. Due to the high PWM resolution, the RGB LED color is changed smoothly.
2.3 RGB LED diagnosticsThe RGB LED diagnostic module reports actual LED average current calculated using the LED diode voltage values and applied PWM duty cycle.
The actual LED voltage is sampled by the ADC when the LED is turned ON, approximately 2 µs for red, 4 µs for green, and 6 µs for the blue diode after the PWM signal falling edge. The sampled value is used to calculate the diode resistor voltage. As the resistor voltage and its resistance is known, the diode peak current is calculated. The average current value is calculated using the known PWM duty cycle value and diode peak current.
The calculation is carried out in 16-bit fractional arithmetic using the AMMCLIB [3].
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor4
RGB LED lighting application
2.4 LIN Slave node position detection The on-board LIN switch hardware is designed to support LIN Slave node auto-addressing and daisy-chaining, see Figure 3. The LIN_IN and LIN_OUT LIN signal lines are either connected or disconnected based on the MCU PS0 output pin logic level, see Table 2.
Figure 3. LIN signal line switch
When the system is powered-up, the LIN_IN (J1) and LIN_OUT (J2) LIN signal lines (pin 4) are disconnected. The LIN Master unit communicates to the closest LIN Slave unit only. The LIN Master unit sends the LIN configuration frame. Once the LIN Slave address is configured, the LIN_IN and LIN_OUT node LIN signal lines are connected and the LIN Slave configuration is repeated for the following node in the line. The cycle is repeated until the configuration of the LIN network slaves is not finished.
Table 2. LIN signal line switch control
MCU PS0 pin LIN_IN and LIN_OUT
High level Disconnected
Low level Connected
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 5
MC9S12ZVL32 modules configuration
3 MC9S12ZVL32 modules configurationThe RGB LED lighting application uses the following set of peripheral modules:
1. Clock, Reset and Power Management Unit (CMPU)
2. Timer module (TIM)
3. Pulse Width Modulator (PWM)
4. Analog-to-Digital Converter (ADC)
5. Port Integration Module (PIM)
6. Interrupt (INT)
The module’s configuration and usage is described in the following chapters. Detailed information on the MCU modules can be found in the MC9S12ZVL32 reference manual [1].
The application software is developed to meet the following specification:
• RGB LED control
• RGB LED diagnostics
• FreeMASTER enabled
For detailed info see Section 4, RGB LED lighting application demo
3.1 Clock, Reset and Power Management Unit The Clock, Reset and Power Management Unit (CMPU) sets the CPU clock to 64 MHz and the bus clock to 32 MHz using the Internal 1 MHz clock signal.
The Internal 1 MHz reference clock is selected as the source clock for the PLL (CPMUREFDIV_REFDIV = 0, CPMUREFDIV_REFFRQ = 0).
The PLL VCOCLK frequency is set to 64 MHz (CPMUSYNR_SYNDIV = 31):
Eqn. 1
The VCOCLK signal frequency is divided by 1 (CPMUPOSTDIV_POSTDIV = 0). This is used as the 64 MHz core clock ECLK2X signal and the 32 MHz bus clock ECLK signal.
3.2 Timer Module The TIM channel 0 is running as an application scheduler time base. The TIM channel 0 compare output is configured as no action on a channel compare event (TIM0TCTL2_OL0 = 0; TIM0TCTL2_OM0 = 0). The TIM channel 0 interrupt is enabled (TIM0TIE_C0I = 1).
The timer single tick is configured to 1 µs (TIM0TSCR2_PR = 5).
VCOCLK 2 SYNDIV 1+ 1MHz=
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor6
MC9S12ZVL32 modules configuration
3.3 Pulse Width ModulatorThe Pulse Width Modulator module controls the on-board RGB LED.
The PWM module channels operate in 16-bit resolution mode (PWMCTL_CON01 = 1, PWMCTL_CON23 = 1, PWMCTL_CON45 = 1, PWMCTL_CON67 = 1). The clock B is selected as PWM clock source. The PWM clock B equals 16 MHz (PWMPRCLK_PCKB = 1).
The channels PWM1, PWM3, PWM5 generate a 244 Hz PWM starting with low level polarity (PWMPOL1 = 0, PWMPOL3 = 0, PWMPOL5 = 0). The PWM1, PWM3, PWM5 channels are enabled (PWME_PWME1 = 1, PWME_PWME3 = 1, PWME_PWME5 = 1).
3.4 Analog-to-Digital Converter An Analog-to-Digital Converter is used to sample RGB LED voltage.
The ADC clock is set to 8 MHz (ADC0TIM = 1). The ADC module is configured to access mode via data bus (ADC0CTL_0_ACC_CFG = 2). The ADC is running in trigger mode (ADC0CTL_0_MOD_CFG = 1) with 8-bit resolution (ADC0FMT_SRES = 0). The end-of-list interrupt is enabled (ADC0CONIE_1_EOL_IE = 1).
The ADC module samples LED voltage using a single command sequence list (ADC0CTL_1_CSL_BMOD = 0) and single result value list (ADC0CTL_1_RVL_BMOD = 0). The LED voltage is recalculated to LED average current, see Section 2.3 ‚RGB LED diagnostics.
3.5 Port Integration ModuleThe Port Integration Module is used to drive the RGB LED, see Section 2.2 ‚RGB LED control, and control the LIN switch, see Section 2.4, LIN Slave node position detection.
The port pins PT3, PT4, PT5 can be used to debug the application by enabling the LED_APPLICATION_DEBUG macro, see Table 3. The pins share the SCI and TIM modules as well.
Table 3. Application debug
MCU pin LED_APPLICATION_DEBUG
PT3 TIM Ch0 interrupt
PT4 ADC end-of-list interrupt
PT5 PWM falling edge generated
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 7
MC9S12ZVL32 modules configuration
3.6 InterruptThe Interrupt module sets the interrupt priorities as follows, starting with the highest priority:
1. The ADC0 end-of-list - samples are ready for processing
2. The TIM channel 0 - 1 ms periodic interrupt used for application control
3. The PIM Port P - PWM module signal falling edge captured
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor8
RGB LED lighting application demo
4 RGB LED lighting application demo The RGB LED lighting application demo can be built using the attached AN4842SW.zip file containing X-S12ZVL32-USLED board hardware and software files.
4.1 HardwareThe X-S12ZVL32-USLED board, see Figure 4, is built using the AN4842SW.zip hardware files. These files include the board schematic, bill of materials, gerber files and an instruction for board manufacturing.
Figure 4. The X-S12ZVL32-USLED board
The X-S12ZVL32-USLED board contains, see Section Appendix A ‚X-S12ZVL32-USLED board schematic:
• MC9S12ZVL32 LQFP32 MCU, see [1]
• LIN Slave node position detection hardware
• RGB LED, including diagnostics hardware
• Reverse battery protection
• BDM enabled
• Ultrasonic sensing circuitry (not used, not populated)
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 9
RGB LED lighting application demo
4.2 SoftwareThe software files are packed as the MC9S12ZVL32_RGBLED_REV1.exe file available in AN4842SW.zip file. The application is developed using the CW10.3 environment. The MC9S12ZVL32_RGBLED_0N22G_AMMCLIB_v_1_0_0.elf file can be found in the project FLASH folder. For code download the P&E USB Multilink Interface is used.
The RGB LED lighting application demo shows:
• RGB LED color control
• RGB LED diagnostics
• FreeMASTER tool:
• RGB LED control
• RGB LED average current display
• Integrating the AMMCLIB [3].
4.3 Demo set-upThe demo set-up is depicted in Figure 5. The demo is designed to be able to run either with or without the FreeMASTER tool.
Figure 5. Demo set-up
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor10
RGB LED lighting application demo
Follow the instructions for a complete demo set-up:
1. Install the FreeMASTER tool [2] on the PC used
2. Connect the +12 V/100 mA DC power supply to the X-S12ZVL32-USLED board at J1, LIN_IN:
a GND to J1 pin 1
b +12 V to J1 pin 3
3. Turn ON the power supply
4. Connect the P&E USB Multilink Interface to the X-S12ZVL32-USLED board at J4
5. Open the ‚MC9S12ZVL32_RGBLED.pmp‚Äù file, available in the AN4842SW.zip file
6. Go to the FreeMASTER file Project/Options folder and check the settings as depicted in Figure 6 and Figure 7
7. Run FreeMASTER communication by File/Start Communication
8. Control the RGB LED using FreeMASTER, see Figure 8:
a RGBLED_OFF - RGB LED is OFF
b RGBLED_ON_MANUAL - RGB LED is controlled by FreeMASTER variables redLEDdutyCycle, greenLEDdutyCycle and blueLEDdutyCycle. Enter a number in the range of 0 to 65535.
c RGBLED_ON_DEMO - RGB LED color is changed automatically. This is the demo default mode after the module power-on.
9. The RGB LED average current is displayed on the FreeMASTER page, see Figure 8
Figure 6. FreeMASTER Communication configuration
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 11
RGB LED lighting application demo
Figure 7. FreeMASTER MAP Files configuration
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor12
RGB LED lighting application demo
Figure 8. FreeMASTER RGB LED control page
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 13
References
5 References1. MC9S12ZVL Family Reference Manual, available at freescale.com
2. FreeMASTER Run-Time Debugging Tool, available at freescale.com/freemaster
3. Automotive Math and Motor Control Library Set, available at freescale.com/AutoMCLib
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor14
Acronyms
6 AcronymsADC Analog-to-Digital Converter
BDM Background Debug Module
CMPU Clock, Reset and Power Management Unit
DC Direct Current
HVI High Voltage Input
INT Interrupt
ISR Interrupt Service Routine
LIN Local Interconnect Network
MCU Microcontroller Unit
PC Personal Computer
PIM Port Integration Module
PWM Pulse Width Modulation
RGB LED Red, Green, Blue Light Emitting Diode
TIM Timer Module
USB Universal Serial Bus
VSUP Voltage Supply
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
Freescale Semiconductor 15
S12ZVL LIN Enabled RGB LED Lighting Application, Rev. 1.0
X-S12ZVL32-USLED board schematic
Freescale Semiconductor16
Appendix A X-S12ZVL32-USLED board schematicFor this schematic, please refer to “LIN_Daisy_Chain_Switch_LEDs.pdf”, attached with the pdf of this Application Note.
Document Number: AN4842Rev. 1.003/2014
Information in this document is provided solely to enable system and software
implementers to use Freescale products. There are no express or implied copyright
licenses granted hereunder to design or fabricate any integrated circuits based on the
information in this document.
Freescale reserves the right to make changes without further notice to any products
herein. Freescale makes no warranty, representation, or guarantee regarding the
suitability of its products for any particular purpose, nor does Freescale assume any
liability arising out of the application or use of any product or circuit, and specifically
disclaims any and all liability, including without limitation consequential or incidental
damages. “Typical” parameters that may be provided in Freescale 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. Freescale
does not convey any license under its patent rights nor the rights of others. Freescale
sells products pursuant to standard terms and conditions of sale, which can be found
at the following address:
How to Reach Us:
Home Page: freescale.com
Web Support: freescale.com/support
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc.,
Reg. U.S. Pat. & Tm. Off. MagniV is trademark of Freescale Semiconductor, Inc. All
other product or service names are the property of their respective owners.
© 2014 Freescale Semiconductor, Inc.
5
5
4
4
3
3
2
2
1
1
D D
C C
B B
A A
BDM
/50V
I/O
BLUEREDGREEN
LIN OUTLIN IN
+12V Board Power Supply (-50V, +42V)
/50V
/50V
/50V
/50V
/6.3V
/6.3V
BKGD/RST
LIN_IN
/RST BKGD
PWM5PWM1PWM3
PWM1
PWM3
PWM5
PS0
LIN_IN
PS0
+5V
+5V
+5V
PT2PT1PT0
PWM7
AN0
Drawing Title:
Size Document Number Rev
Date: Sheet of
Page Title:
Designer:
Drawn by:
Approved:
Automotive, Industrial & Multi-
6501 William Cannon Drive WestAustin, TX 78735-8598
This document contains information proprietary to Freescale and shall not be used for engineering design,procurement or manufacture in whole or in part without the express written permission of Freescale.
ICAP Classification: FCP: FIUO: PUBI:
market Solutions Group
SCH-27825 PDF: SPF-27825 0.2
X-S12ZVL32-USLED
B
Monday, June 17, 2013
02 MCU, LIN Daisy Chain Switch and LEDs
PCh
CA, WB
PCh
2 3
X________Drawing Title:
Size Document Number Rev
Date: Sheet of
Page Title:
Designer:
Drawn by:
Approved:
Automotive, Industrial & Multi-
6501 William Cannon Drive WestAustin, TX 78735-8598
This document contains information proprietary to Freescale and shall not be used for engineering design,procurement or manufacture in whole or in part without the express written permission of Freescale.
ICAP Classification: FCP: FIUO: PUBI:
market Solutions Group
SCH-27825 PDF: SPF-27825 0.2
X-S12ZVL32-USLED
B
Monday, June 17, 2013
02 MCU, LIN Daisy Chain Switch and LEDs
PCh
CA, WB
PCh
2 3
X________Drawing Title:
Size Document Number Rev
Date: Sheet of
Page Title:
Designer:
Drawn by:
Approved:
Automotive, Industrial & Multi-
6501 William Cannon Drive WestAustin, TX 78735-8598
This document contains information proprietary to Freescale and shall not be used for engineering design,procurement or manufacture in whole or in part without the express written permission of Freescale.
ICAP Classification: FCP: FIUO: PUBI:
market Solutions Group
SCH-27825 PDF: SPF-27825 0.2
X-S12ZVL32-USLED
B
Monday, June 17, 2013
02 MCU, LIN Daisy Chain Switch and LEDs
PCh
CA, WB
PCh
2 3
X________
C51000PF
C40.01UF
R682
D2
BZT52C16T-7
AC
D3MMBZ27VCLT1
2
1
3
J3HDR_1X4
1234
L1600 OHM
D5S1A
A C
R222K
C710uF
J1CON PLUG 4
4321
J2CON PLUG 4
4321
C1220PF
D1MMBZ27VCLT1
2
1
3
C20.1UF E
B
C
Q3BCP53-10
1
3 24
D4BZT52C16T-7
A C
C910uF
R3140.0
R882
J4HDR 2X3
1 23 4
65
R51.0K
C8
0.22uF
R1
22K
D6
LTRB GFSF
A2
C2
A1
C1
C3
A3
Q1
BSS138LT1G
1
2 3
R4
22K
+ C333UF
PC9S12ZVL32U1
VSUP1
KWL0/PL02
EXTAL/ETRIG0/PE03
XTAL/PE14
AN9/KWAD9/PAD95 AN8/KWAD8/PAD86 AN7/KWAD7/PAD77 AN6/KWAD6/PAD68 AN5/ETRIG0/KWAD5/PAD59 AN4/KWAD4/PAD4
10 AN3/KWAD3/PAD311 AN2/KWAD2/PAD212 VRL/AN1/KWAD1/PAD113
VSSA14 VDDA15
VRH/AN0/KWAD0/PAD016
IOC1_0/PT617
PWM6/ETRIG0/KWP6/PP618
RXD1/IOC0_4/PT419 TXD1/IOC0_5/PT520
TEST21
LPTXD0/PWM2/RXD1/SDA0/IOC0_0/PT022
BCTL23
LIN24
LGND25
BKGD/MODC26
PT1/IOC0_1/SCL0/TXD1/PWM0/LPRXD027
PS0/KWS0/MISO0/PWM4/RXD0/IOC0_228
PT7/IOC1_129
PP0/KWP0/PWM030
PP2/KWP2/PWM231
PP4/KWP4/PWM432
PS1/KWS1/MOSI0/PWM6/TXD0/LPDC0/IOC0_333
PS2/KWS2/SCK0/IOC0_4/DBGEEV34
PS3/KWS3/SS0/IOC0_5/ECLK35
RESET36
PP3/IRQ/KWP3/PWM337
VSSX238
PP5/XIRQ/KWP5/PWM539
PT2/IOC0_240
PJ0/SDA0/PWM541
PJ1/SCL0/PWM742
PT3/IOC0_343
PP7/KWP7/PWM7/IOC1_044
VDDX45
VSSX146
PP1/KWP1/PWM1/IOC1_147
VSS48
Q2BSS138LT1G
1
23
C6
0.22uF
R7140.0