AN3258 Application note

Similar documents
AN5058 Application note

76-81GHz MMIC transceiver (4 RX / 3 TX) for automotive radar applications. Table 1. Device summary. Order code Package Packing

AN3101 Application note

AN4507 Application note

I-NUCLEO-SX1272D. SX1272 LoRa technology and high-performance FSK/OOK RF transceiver modem. Features

AN3300 Application note

UM0791 User manual. Demonstration firmware for the DMX-512 communication protocol receiver based on the STM32F103Zx. Introduction

AN3332 Application note

ALTAIR05T W wide range CV-CC optoless adapter evaluation board

UM1082 User manual. The STPM10 single-phase meter evaluation boards. Introduction

ESDLIN03-1BWY. Automotive single-line Transil, transient voltage suppressor (TVS) for LIN bus. Application. Description. Features

Emergency lighting LED Voltage regulation SOT-89. Description. Order code Marking Package Packaging. 2STF SOT-89 Tape and reel

AN4392 Application note

ULN2801A, ULN2802A, ULN2803A, ULN2804A

ESDCAN03-2BWY. Automotive dual-line Transil, transient voltage suppressor (TVS) for CAN bus. Application. Description. Features

Description. Table 1: Device summary Order code Package Packing STWLC33JR CSP (3.97x2.67 mm) 400 μm pitch 52 balls Tape and reel

AN4014 Application Note Adjustable LED blinking frequency using a potentiometer and STM8SVLDISCOVERY Application overview

ULQ2801, ULQ2802, ULQ2803, ULQ2804

STPSC6H V power Schottky silicon carbide diode. Description. Features

AN4819 Application note

STPS3170. Power Schottky rectifier. Description. Features

STPS4S200. Power Schottky rectifier. Description. Features

AN2581 Application note

BAT30. Small signal Schottky diodes. Description. Features

AN2780 Application note

Automotive Transil, transient voltage suppressor (TVS) for LIN bus. Description

DSL04. Low capacitance TVS for high speed lines such as xdsl. Description. Features. Complies with the following standards

ST1S A, 1.5 MHz adjustable, step-down switching regulator. Description. Features

BZW06. Transil. Description. Features

STPS60170C. High voltage power Schottky rectifier

STBR3012. High voltage rectifier for bridge applications

AN5008 Application note

AN5009 Application note

FERD20H60C. 60 V field-effect rectifier diode. Description. Features

EVAL6472H-DISC. L6472 Discovery: development tool to explore L6472 motor driver. Description. Features

TL = 140 C 2 A. Table 3: Thermal parameters Symbol Parameter Max. value Unit Rth(j-l) Junction to lead 20 C/W

AN1449 Application note

STEVAL-XPLM01CPL. Power line communication AC coupling circuit. Description. Features

ESDCANxx-2BLY. Automotive dual-line TVS in SOT23-3L for CAN bus. Datasheet. Features. Applications. Description

Description. Table 1. Device summary. Order codes. SOT23-5L Marking SOT323-5L Marking DFN8 (3x3 mm) Marking

STPS200170TV1. High voltage power Schottky rectifier

AN4999 Application note

AN1756 Application note

Description. Table 1. Device summary (1) Quality level. EPPL Package I F(AV) V RRM V F (max) T j(max)

STTH4R02. Ultrafast recovery diode. Description. Features

Features. Description. Table 1. Device summary. Quality level. Package I F (AV) V RRM T j (max) V F (max) Engineering model TO x

Firmware plugin for STSW-ESC001V1 board with ST Motor Control FOC SDK

STTH1003S. High efficiency rectifier. Description. Features

AN3252 Application note

EVAL-RHF310V1. EVAL-RHF310V1 evaluation board. Features. Description

STPSC10H065-Y. Automotive 650 V power Schottky silicon carbide diode. Description. Features

Description. consumption lower than 1 µa. The device also Input voltage from 2.4 to 5.5 V

STPS15L60C. Power Schottky rectifier. Description. Features

STPS1045HR. Aerospace 2 x 10 A - 45 V Schottky rectifier. Description. Features

AN2979 Application note

Features. Description. Table 1: Device summary Order code Marking Package Packing BU931T BU931T TO-220 Tube

STTH1R02-Y. Automotive ultrafast rectifier

EVAL6235N. Demonstration board for L6235 DMOS driver for 3-phase brushless DC motor. Description. Features

ESDALC6V1-5M6. 5-line low capacitance Transil arrays for ESD protection ESDALC6V1-5M6. Applications. Description. Features

STPS1150-Y. Automotive power Schottky rectifier. Datasheet. Features. Description

STPSC10H12C V power Schottky silicon carbide diode

STPS3045DJF. Power Schottky rectifier. Description. Features

CBTVS2A16-1F3. Circuit breaker with transient voltage suppressor. Description. Features. Complies with the following standards:

LDP01-xxAY. Automotive TVS for load dump protection. Description. Features. Complies with the following standards:

L4949ED-E L4949EP-E. Automotive multifunction very low drop voltage regulator. Description. Features

STPS160H100TV. High voltage power Schottky rectifier. Description. Features

Features. Description. Table 1: Device summary Order code Marking Package Packing BU931P BU931P TO-247 Tube

LD3985. Ultra low drop and low noise BiCMOS voltage regulators. Features. Description

STPS1L40-Y. Automotive low drop power Schottky rectifier

Sub-1GHz transceiver development kit based on S2-LP. Description

Description. Table 1. Device summary. Order codes Output voltage

PM8841D. 1 A low-side gate driver. Description. Features. Applications

STPSC30H12C V power Schottky silicon carbide diode. Description. Features

STPSC20H V power Schottky silicon carbide diode. Description. Features

UM1763 User manual. Description of STLUX385A examples kit. Introduction. Reference documents

STPS20LCD80CB. High voltage power Schottky rectifier

STPS80170C. 170 V power Schottky rectifier. Datasheet. Features. Applications. Description

STPSC2H V power Schottky silicon carbide diode. Description. Features

ESDCAN01-2BLY, ESDCAN24-2BLY

1N6642U. Aerospace 0.3 A V switching diode. Description. Features

BALF-NRG-01D3. 50 Ω nominal input / conjugate match balun to BlueNRG transceiver, with integrated harmonic filter. Description. Features.

STPS10170C. High voltage power Schottky rectifier. Description. Features

STTH2R02-Y. Automotive ultrafast recovery diode. Description. Features

TSM1013. Constant voltage and constant current controller for battery chargers and adapters. Description. Features. Applications

STPSC20H12C V power Schottky silicon carbide diode

STGB20NC60V, STGP20NC60V, STGW20NC60V

AN4949 Application note

150 ma low quiescent current and low noise voltage regulator. Description

AN5029 Application note

Features. Description. Table 1. Device summary. Order code Marking Package Packing. MJD32CT4-A MJD32C DPAK Tape and reel

TS4061. Precision micropower shunt voltage reference. Description. Features. Applications

STPSC10065-Y. Automotive 650 V power Schottky silicon carbide diode. Description. Features

Automotive dual-line Transil, transient voltage suppressor (TVS) for CAN bus

BAT54-Y. Automotive small signal Schottky diodes. Description. Features

STPSC20H065C-Y. Automotive 650 V power Schottky silicon carbide diode. Description. Features

STBR3012-Y. Automotive high voltage rectifier for bridge applications. Datasheet. Features. Applications. Description

UM2068 User manual. Examples kit for STLUX and STNRG digital controllers. Introduction

N-channel 30 V, 2.5 mω typ., 120 A STripFET H6 Power MOSFET in a TO-220 package. Features. Description

LCP154DJF. Programmable transient voltage suppressor for SLIC protection. Description. Features. Benefits

FERD15S50S. 50 V field-effect rectifier diode. Description. Features

Transcription:

Application note STM8AF and STM8S series HSI oscillator calibration using LIN automatic resynchronization Introduction Local interconnect network (LIN) is a widely used standard for communication between various nodes present inside the electronic control unit (ECU) of a vehicle. LIN sync frame, which is defined by LIN standard, is used as a reference by the LIN slave nodes for clock synchronization. Using this technique, LIN slave nodes can calibrate the variable internal RC oscillator and use it as the system clock source. Therefore, the LIN slave node application can save the cost of using crystal or resonator oscillators. This application note describes a method to calibrate the STM8AF and STM8S series highspeed internal (HSI) oscillator using the LIN automatic resynchronization feature of the LINUART peripheral. The calibration method is also provided with a software routine. It can be downloaded from www.st.com. The user must be familiar with the LIN bus standard, STM8AF and STM8S series architecture, and the basics of C language. Detailed information about the STM8AF and STM8S series microcontroller peripheral features, hardware registers, and electrical characteristics are available in STM8S series and STM8AF series 8-bit microcontrollers reference manual (RM0016) and the product datasheets. September 2015 DocID17825 Rev 2 1/16 www.st.com 1

Contents AN3258 Contents 1 HSI calibration.............................................. 5 1.1 HSI trimming bits............................................ 5 1.2 LIN automatic resynchronization................................ 6 1.3 HSI calibration method........................................ 8 1.4 HSI calibration routine........................................ 9 1.5 LIN header error handling.....................................11 1.6 LIN divider update method.....................................11 1.7 LIN clock deviation.......................................... 13 2 Conclusion................................................ 14 3 Revision history........................................... 15 2/16 DocID17825 Rev 2

List of tables List of tables Table 1. CLK_HSITRIMR values and binary two s complement representation................. 6 Table 2. Document revision history................................................. 15 DocID17825 Rev 2 3/16 3

List of figures AN3258 List of figures Figure 1. STM8AF and STM8S series HSI trimming principle............................... 5 Figure 2. LIN header.............................................................. 7 Figure 3. LIN synch field measurement................................................ 7 Figure 4. HSI calibration routine flowchart............................................. 10 Figure 5. LDIV read/write operations when LDUM = 0................................... 12 Figure 6. LDIV read/write operations when LDUM = 1................................... 12 4/16 DocID17825 Rev 2

HSI calibration 1 HSI calibration 1.1 HSI trimming bits STM8AF and STM8S series microcontrollers have an HSI oscillator with a nominal frequency (f HSI ) of 16 MHz which is factory calibrated at an ambient temperature (T A ) of 25 C and a supply voltage (V CC ) of 5 V. The accuracy for overall temperature and voltage range is ±5% (please refer to the device specific datasheet) which is sufficient for many applications. For a given voltage and temperature condition, the HSI oscillator frequency can be calibrated to ±1% or ± 0.5% by using calibration bits as described below and in Figure 1. After a device reset, the factory calibration value at T A = 25 C and V CC = 5 V is automatically loaded into the internal calibration register. The HSI frequency can be finetuned by writing the calibration bits present in the HSI clock calibration trimming register (CLK_HSITRIMR). The maximum number of calibration bits present is either three or four depending on the device. The calibration bits provide an additional trimming value which is added to the factory calibration value to fine-tune the HSI output frequency. The additional trimming value, written in the trimming bits, is interpreted as a signed value with two s complement representation (see Table 1). In the case of three trimming bits, this additional trimming value can vary from -4 (100b) to 3 (011b) and in the case of four trimming bits, this additional trimming value varies from -7 (1001b) to 7 (0111b). Thus, the additional trimming value can be added or subtracted to the factory calibration value. An increase in the trimming value causes a decrease in the HSI frequency. The frequency change per step is ±1% or ±0.5% depending on the device and number of trimming bits used (three or four). Some devices can use either three or four trimming bits which are programmable via the HSITRIM option byte. Figure 1. STM8AF and STM8S series HSI trimming principle CLK_HSITRIM + DECODER RC OSCILLATOR INIT_TRIM HSI Clock Output DocID17825 Rev 2 5/16 15

HSI calibration AN3258 Table 1. CLK_HSITRIMR values and binary two s complement representation 3-bit trimming value 4-bit trimming value Decimal value Binary two s complement value Decimal value Binary two s complement value 3 011b 7 0111b 2 010b 6 0110b 1 001b 5 0101b 0 000b 4 0100b -1 111b 3 0011b -2 110b 2 0010b -3 101b 1 0001b -4 100b 0 0000b - - -1 1111b - - -2 1110b - - -3 1101b - - -4 1100b - - -5 1011b - - -6 1010b - - -7 1001b 1.2 LIN automatic resynchronization In the LIN standard, the master node initiates the communication by sending a LIN message header to the slave node. The LIN message header sent by the master node comprises three fields (see Figure 2): Break field Sync field Identifier field frame identifier parity The break field is at least 13 nominal bit times the dominant value followed by a break delimiter. The sync field is a byte with a data value of 0x55. The identifier field consists of two subfields: the frame identifier and the parity. Bits 0 to 5 are frame identifier and bits 6 to 7 are the parity. 6/16 DocID17825 Rev 2

HSI calibration Figure 2. LIN header Parity bits LIN break LIN synch Identifier field field Usually, the master node uses a crystal or resonator oscillator to generate the correct baud rate. The sync field byte is used by the slave node to synchronize with the master clock. The STM8AF and STM8S series LINUART peripheral has an automatic resynchronization feature which makes use of the sync byte field to synchronize with the master baud rate. The automatic resynchronization feature measures the sync byte field and automatically adjusts the slave baud rate generator after each LIN sync field reception from the master node (see Figure 3). Figure 3. LIN synch field measurement T BR LIN break Break delim. Start bit LIN synch field Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Stop bit Next start bit Measurement = 8.T BR = SM.T MASTER LDIV(n) LDIV(n+1) Note: After each LIN break reception, the time duration between five falling edges on the LIN Rx pin is sampled on the f MASTER clock. The result of this measurement is stored in an internal 19-bit register called SM which is not user accessible. Then, the LIN baud rate divider (LDIV) is automatically updated at the end of the fifth falling edge. f MASTER and T MASTER are the respective system clock frequency and time period of the STM8AF and STM8S series slave node (please refer to the clock tree figure in STM8S series and STM8AF series 8-bit microcontrollers reference manual (RM0016)) and should not be considered as the frequency of the master node. DocID17825 Rev 2 7/16 15

HSI calibration AN3258 1.3 HSI calibration method This section explains how to calibrate the HSI oscillator using the LIN automatic resynchronization feature described above. The automatic resynchronization feature updates the LIN baud rate divider (LDIV) after each LIN sync field reception. The calibration method uses the updated LDIV factor to calculate the HSI frequency variation, under current conditions, using the equations below. Equation 1 f HSIDIV"" = f HSI ------------------- HSIDIV Where, f HSI = nominal HSI frequency of 16 MHz and HSIDIV is the HSI prescaler factor programmed in the CLK_CKDIVR register. The LIN baud rate is programmed by software after writing the LDIV_NOM value into the BRR1 and BRR2 registers. Equation 2 Baudrate = f MASTER ----------------------------- LDIV_NOM As slave node uses the HSI clock as f MASTER, f MASTER = f HSIDIV. Equation 3 LDIV_NOM = f MASTER -------------------------- Baudrate Equation 4 f MESASURED = LDIV_MEAS Baudrate After the LIN sync field reception, the LIN baud rate divider is measured by the automatic resynchronization (LDIV_MEAS) and it is automatically loaded into the BRR1 and BRR2 registers. These actions keep the same baud rate under varying HSI oscillator frequency conditions. The LDIV_MEAS factor multiplied by the baud rate gives the current HSI frequency (f MEASURED ). Where, LDIV_MEAS = LDIV measured after automatic resynchronization. The difference between the f REFERENCE and f MEASURED gives the variation of HSI oscillator frequency. Equation 5 FREQUENCY = f MASTER f MEASURED Where, FREQUENCY is the HSI oscillator frequency variation. 8/16 DocID17825 Rev 2

HSI calibration 1.4 HSI calibration routine The calibration routines are written in C language. They include STM8S/AF standard peripheral library (STSW-STM8069) functions. The calibration routine starts with the configuration of the HSI clock prescaler value bits, HSIDIV[1:0], in the CLK_CKDIVR register. The value programmed in the software example is HSIDIV[1:0] = 00 which means, f HSIDIV = f HSI/1 = 16 MHz. The HSI trimming bits, HSITRIM[3:0] or HSITRIM[2:0], in the CLK_HSITRIMR register are kept at reset value. The LINUART peripheral is initialized at baud rate 19200 bps, 8 data bits, 1 stop bit and no parity. LINUART is configured in slave mode (LSLV bit =1) with the automatic resynchronization feature enabled (LASE bit = 1) and the LIN divider update method (LDUM) bit = 0. Both LIN header detection (LHDIEN) and LIN receiver (RIEN) interrupts are enabled. The LINEN bit is set to enable the LIN mode. When a valid LIN header is received by the LIN slave, the LIN receive interrupt is generated. Inside the interrupt service routine, if the LIN header detection flag (LHDF) is set, LDIV_MEAS is read from the BRR1 and BRR2 registers (see Figure 4). Using Equation 4, f MEASURED is calculated. The variation of the HSI oscillator frequency ( FREQUENCY ) is calculated by using Equation 5. Depending on whether the FREQUENCY is positive or negative, the trimming value (as described in Section 1.1: HSI trimming bits) is written to increase or decrease the HSI oscillator frequency by one trimming step. When the next sync frame is received, the procedure is repeated to check and calibrate the HSI oscillator until the trimming value reaches the upper/lower limit or until the measured FREQUENCY is greater than the value measured with the previous trimming value. The maximum number of valid LIN headers required to calibrate the HSI oscillator is four if three trimming bits are used and eight if four trimming bits are used. DocID17825 Rev 2 9/16 15

HSI calibration AN3258 Figure 4. HSI calibration routine flowchart 10/16 DocID17825 Rev 2

HSI calibration 1.5 LIN header error handling It is possible that slave node receives an invalid LIN header or a LIN header with an error. In this case, the LIN header detection flag (LHDF) is not set and the corresponding LIN header detection interrupt does not occur but, the LIN header error (LHE) flag is set. A LIN header error may occur under the following conditions: 1. The break delimiter is too short. 2. The sync field is not equal to 0x55 or the deviation error in the sync field is outside the LIN specification which allows a clock deviation of up to 14% between the slave and master oscillators. 3. The framing error occurs in the sync field or the identifier field. 4. A LIN header reception timeout occurs. In the case of a LIN header error detection (LHE bit set), the LHE bit is cleared inside the interrupt service routine and the software waits for the new valid LIN header. 1.6 LIN divider update method Three registers are managed internally by the LINUART peripheral for the automatic update of the LIN divider (LDIV). They are: 1. LDIV_NOM which stores the value written by software in the LINUART_BRR1 and LINUART_BRR2 registers. 2. LDIV_MEAS which stores the value of the LIN sync field measurement. 3. LDIV which stores the value which is used to generate the baud rate. The LDIV can be updated from the LDIV_MEAS register after the LIN sync field measurement or from the LDIV_NOM register after a software write in LINUART_BRR1. If LASE =1, the LDIV_MEAS is loaded automatically into LDIV after each LIN sync field measurement. The loading from LDIV_NOM into LDIV depends on the LDUM bit setting. If LDUM = 1, the LDIV_NOM value is loaded automatically into LDIV register at the end of character reception (RXNE =1). If LDUM =0, the LDIV_NOM value is loaded into LDIV after a software write into LINUART_BRR1. If the loading from LDIV_MEAS and LDIV_NOM into LDIV occurs at the same time, LDIV_NOM has the priority. DocID17825 Rev 2 11/16 15

HSI calibration AN3258 In Figure 5, the software example has been implemented with (LDUM = 0). After the LIN reception of the LIN header interrupt and the execution of the calibration routine, the LDIV is loaded with LDIV_NOM by writing the LINUART_BRR1. Figure 5. LDIV read/write operations when LDUM = 0 Write LINUART_BRR1 Write LINUART_BRR2 LDIV[11:4] LDIV[15:2] LDIV[3:0] LDIV_NOM LIN sync field measurement Write LINUART_BRR1 LDIV[11:4] LDIV[15:12] LDIV[3:0] Update at end of synch field LDIV_MEAS LDIV[7:0] LDIV[15:12] LDIV[3:0] LDIV Baud rate generation Read LINUART_BRR1 Read LINUART_BRR2 In the case of LDUM = 1 (see Figure 6), the LDUM bit has to set by software before the LIN checksum reception. In this way, the LDIV_NOM is loaded into LDIV at the end of character reception. Figure 6. LDIV read/write operations when LDUM = 1 Write LINUART_BRR1 Write LINUART_BRR2 LDIV[11:4] LDIV[15:12] LDIV[3:0] LDIV_NOM LIN sync field measurement RXNE=1 LDIV[11:4] LDIV[15:12] LDIV[3:0] LDIV_MEAS Update at end of synch field LDUM is reset LDIV[11:4] LDIV[15:12] LDIV[3:0] LDIV Baud rate generation Read LINUART_BRR1 Read LINUART_BRR2 12/16 DocID17825 Rev 2

HSI calibration 1.7 LIN clock deviation LIN clock deviations may be caused by the following sources: 1. Deviation due to transmitter error (DTRA): The transmitter can be either a master or a slave (in the case of a slave listening to the response of another slave). 2. Error due to the LIN synch measurement performed by the receiver (DMEAS). 3. Error due to the baud rate quantization of the receiver (DQUANT). 4. Deviation of the local oscillator of the receiver (DREC): This deviation can occur during the reception of one complete LIN message assuming that the deviation was compensated at the beginning of the message. 5. Deviation due to the transmission line (DTCL) which is generally due to the transceivers. Total clock deviation = DTRA + DMEAS + DQUANT + DREC + DTCL If the LINUART is to receive a character correctly, the total deviation should be <3.75%. For more details, please refer to STM8S series and STM8AF series 8-bit microcontrollers reference manual (RM0016). DocID17825 Rev 2 13/16 15

Conclusion AN3258 2 Conclusion The calibration method described in this application note allows the LIN slave nodes to calibrate and operate with the HSI internal oscillator (16 MHz) under variable temperature and voltage conditions. 14/16 DocID17825 Rev 2

Revision history 3 Revision history Table 2. Document revision history Date Revision Changes 05-Oct-2010 1 Initial release 11-Sep-2015 2 Extended the document applicability to STM8AF and STM8S series and updated the document references accordingly. Replaced LINUART/UART1 occurrences with LINUART. DocID17825 Rev 2 15/16 15

IMPORTANT NOTICE PLEASE READ CAREFULLY STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST s terms and conditions of sale in place at the time of order acknowledgement. Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of Purchasers products. No license, express or implied, to any intellectual property right is granted by ST herein. Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product. ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners. Information in this document supersedes and replaces information previously supplied in any prior versions of this document. 2015 STMicroelectronics All rights reserved 16/16 DocID17825 Rev 2