Application Notes

Freescale Semiconductor
Application Note
Document Number: AN4841
Rev. 1.0, 3/2014
S12ZVL LIN Enabled Ultrasonic
Distance Measurement
Based on the MC9S12ZVL32 MagniV Device
by:
1
Petr Cholasta
Introduction
This application note introduces the MC9S12ZVL32
device in ultrasonic sonar application, capable of
detecting an object as well as measuring the object
distance.
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.
The measured object distance is displayed in the
FreeMASTER tool. The on-board RGB LED color is
smoothly changed based on the actual object distance.
The application includes the RGB LED diagnostics as
well.
The AMMCLIB [6] functions are used for mathematical
operations.
Parts of this document is the AN4841SW.zip file
containing X-S12ZVL32-USLED hardware and
software files.
© Freescale Semiconductor, Inc., 2014. All rights reserved.
Contents
1
2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Ultrasonic based measurement overview . . . . . . . . . . . . 2
2.1 Ultrasonic sensing principle. . . . . . . . . . . . . . . . . . . 2
2.2 Required compensation. . . . . . . . . . . . . . . . . . . . . . 3
2.3 Transducer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3
Ultrasonic sensing application . . . . . . . . . . . . . . . . . . . . . 6
3.1 Scheduling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Burst generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Echo receiver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4 Echo signal sampling and processing . . . . . . . . . . 11
3.5 Object distance calculation . . . . . . . . . . . . . . . . . . 11
3.6 RGB LED control and diagnostics . . . . . . . . . . . . . 12
3.7 LIN Slave node position detection . . . . . . . . . . . . . 13
4
MC9S12ZVL32 modules configuration . . . . . . . . . . . . . 14
4.1 Clock, Reset and Power Management Unit. . . . . . 14
4.2 Timer Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.3 Pulse Width Modulator . . . . . . . . . . . . . . . . . . . . . 15
4.4 Analog-to-Digital Converter . . . . . . . . . . . . . . . . . . 15
4.5 Port Integration Module . . . . . . . . . . . . . . . . . . . . . 16
4.6 Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5
Ultrasonic sensing application demo . . . . . . . . . . . . . . . 17
5.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.3 Demo set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7
Acronyms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Appendix AX-S12ZVL32-USLED board schematic . . . . . . . . 25
Ultrasonic based measurement overview
2
Ultrasonic based measurement overview
An ultrasonic based measurement is a key part of applications dealing with non-contact object distance
measurement and object detection:
• Automotive safety systems
— Parking distance sensor
— Blind spot detection
— Object detection
• Level measurement (e.g. fuel)
• Alarm systems
• Automatic door opener
• Electronic tape measures
• Robotics
2.1
Ultrasonic sensing principle
The ultrasonic waves are sounds of frequencies above 20 kHz, which can not be heard by humans.
The applied methodology is based on measuring the pulse reflection time [2]. The ultrasonic transducer
emits an ultrasonic wave pulse, see Figure 1. Once the pulse is emitted, the transducer becomes quite in
order to receive object echoes. When the wave pulse reaches an object, the reflected wave, called an echo,
is bounced back to the transducer.
Figure 1. Ultrasonic sensing principle [1]
The object distance is calculated by the following formula:
tc
d = ---------2
Eqn. 1
where:
• d — object distance [m]
• t — time delay between wave emission and echo reception [s]
• c — ultrasonic sound velocity [m/s]
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
2
Freescale Semiconductor
Ultrasonic based measurement overview
Metal, wood, concrete, glass, rubber and paper objects reflect the majority of the ultrasonic waves back to
transducer. These objects can be easily detected. Cloth, cotton and wool absorb the majority of ultrasonic
waves, so it may be difficult to detect these objects [2].
2.2
Required compensation
The ultrasonic sound velocity is dependent on the air temperature, see Figure 2, for the following formula
[1]:
c = 331 3 + 0 606T
Eqn. 2
where:
• c — ultrasonic sound velocity [m/s]
• T— air temperature [°C]
It is necessary to measure the air temperature to keep the object distance calculation precise enough.
!
Figure 2. Sound velocity dependency on temperature in dry air [1]
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
3
Ultrasonic based measurement overview
The strength of ultrasonic waves attenuates proportionally with object distance [2], see Figure 3. During
echo processing, the attenuation needs to be compensated for to properly detect the object echo.
!
"#$
"#$
%
"#$
"#$
Figure 3. Ultrasonic waves strength attenuation with distance and wave frequency [2]
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
4
Freescale Semiconductor
Ultrasonic based measurement overview
2.3
Transducer
The transducer turns the electric pulses into mechanical vibration, and vice versa, using piezoelectric
ceramics [2]. The transducer’s sensitivity is the highest at the piezoelement resonant frequency. The
transducer’s pattern directivity allows detection of the object position in space. When the object hits the
transducer lobe, the echo is received. The transducer directivity can be sharpened by an attached horn, see
Figure 4.
" " " !
!
#$%&
()
()
!
!
!
"
'
!
#$%&
"
'
" Figure 4. MA40S4R transducer receiver lobe variation with horn length and angle [2]
Transducers called “combined use types” integrate both an ultrasonic sender and receiver. These devices
are used in automotive applications for object detection, e.g. parking distance sensor, blind spot detection.
There are the sender and receiver transducers available separately, called “dual use types”, e.g. in alarm
systems and robotics.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
5
Ultrasonic sensing application
3
Ultrasonic sensing application
The Figure 5 shows the Ultrasonic sensing application block diagram. The green boxes represent modules
external to the MC9S12ZVL32 MCU, the blue boxes are MCU modules and the light brown boxes
represent the software modules.
Figure 5. Application block diagram
The ultrasonic sonar unit uses dual use type transducers MA40S4S and MA40S4R operating at 40 kHz,
see [3]. These transducers allow detection of an object at a distance of 20 cm to 4 m. The MA40S4S
ultrasonic sender is driven by the PWM7 signal amplified by the burst signal generator. The object echo
signal is received by the MA40S4R receiver transducer and amplified by the programmable gain amplifier.
The band pass filter improves the echo signal to noise ratio.
The echo signal is sampled by the ADC module and processed in the digital domain. The echo signal
detection is based on the ADC sample value comparison with a preset threshold.
The object distance is calculated and averaged using the AMMCLIB [6] functions and visualized in the
FreeMASTER tool [5]. The measured object distance is compensated with temperature. The on-board
RGB LED color control is based on the actual object distance.
For a detailed description, see the following chapters.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
6
Freescale Semiconductor
Ultrasonic sensing application
3.1
Scheduling
The Table 1 shows an application scheduling. The application is running in five time slots. The time slots
from 0 ms to 30 ms are used for ultrasonic signal transmission and reception. The slot starting at 30 ms
and ending at 60 ms is used for data processing, object distance calculation and visualization.
Table 1. Application scheduling
Time [ms]
Burst
generator
Echo
receiver
Echo signal
sampling and
processing
Object
distance
calculation
Temperature
measurement
RGD LED
control
and
diagnostics
0 - 0,135
ON
-
-
-
-
-
0,135 - 1,135
-
-
-
-
-
ON
1,135 - 30
-
ON
ON
-
-
-
30 - 59
-
-
-
ON
ON
ON
59 - 60
-
-
-
-
ON
ON
Note: Symbol “-” represents a module not operating.
Transducers MA40S4S and MA40S4R [3] allow measurement of a maximal distance of 4 m. An echo
reception minimal period, see Eqn. 1, is given by the measured maximal distance and sound velocity, see
Eqn. 2, at the minimal air temperature, T = -40°C:
m
m
c = 331 3 ---- + 0 606T = 331 3 – 24 24 = 307 06 ---s
s
2d
2  4m
t = ------------ = ---------------------- = 26ms
c
m
307 06 ---s
Eqn. 3
Eqn. 4
Once the burst signal is transmitted, the echo receiver transducer is saturated for a 1ms period, see
Figure 6. The minimal measured distance using Eqn. 1, calculated at maximal air temperature T = 85°C:
m
1 135ms  382 81 ---t-------- cs
d =
= --------------------------------------------------- = 21 8cm
2
2
Eqn. 5
The Figure 6 shows the ultrasonic burst signal (yellow colored) waveform and the transducer receiver
signal amplified by the PGA (blue colored) waveform. The PGA gain is changed proportionally with time,
i.e. with object distance. The pink colored waveform displays the PGA gain change on the waveform
signal edge.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
7
Ultrasonic sensing application
In Figure 6 can be seen the object reflection at a distance of 2.2 m (blue colored waveform) at 25°C:
m
12 8ms  346 45 ---s
t-------- cd =
= ------------------------------------------------ = 2 2m
2
2
Eqn. 6
Figure 6. Signal overview
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
8
Freescale Semiconductor
Ultrasonic sensing application
3.2
Burst generator
The PWM module channel 7 generates the burst signal, see Figure 7, the pink colored signal.
Figure 7. Burst signal
The burst signal drives the ultrasonic burst circuitry to generate pulses with an amplitude of 20 Vpp, see
Figure 7, the yellow colored signal. The signal amplitude is given by the PWM signal duty cycle, set to
38%, and the L/C tank circuit ratio, see Figure 8. The MA40S4S ultrasonic transducer sender emits an
ultrasonic wave pulse into the air.
Figure 8. Burst generator
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
9
Ultrasonic sensing application
3.3
Echo receiver
When the ultrasonic wave hits the object, the echo is sent back to the MA40S4R transducer receiver, see
Figure 9. The echo signal is amplified using the Programmable Gain Amplifier (PGA) to compensate the
ultrasonic waves strength attenuation that is proportional to the object distance.
Figure 9. Programmable gain amplifier circuitry
The PGA gain control is based on the actual time measurement, see Table 2.
Table 2. Programmable gain amplifier gain control
Distance [cm]
Time [ms]
Gain [-]
PT0
PT1
PT2
0 - 20
0
184
Input
Input
Input
20 - 30
1,135
184
Input
Input
Input
30- 60
1,765
376
Output low level
Input
Input
60 - 80
2,941
600
Input
Output low level
Input
80 - 110
4,706
784
Output low level
Output low level
Input
110 - 140
6,471
1040
Input
Input
Output low level
140 - 170
8,235
1248
Output low level
Input
Output low level
170 - 400
10
1600
Output low level
Output low level
Output low level
The integrated band-pass filter improves the echo signal-to-noise ratio and acts as an ADC anti-aliasing
filter as well.
The band-pass filter design combines passive components and a relatively low U3 transition frequency to
obtain the required band pass filter characteristic, with a center frequency of 40 kHz, see Figure 9.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
10
Freescale Semiconductor
Ultrasonic sensing application
3.4
Echo signal sampling and processing
The object echo signal is sampled using the ADC module. The ADC module samples the data with an 8-bit
resolution and a sampling speed of 2.2 us per one sample. When using the 40 kHz ultrasonic transducer,
approximately eleven ADC samples are taken per single signal period, see Figure 10.
%!&#
#
!
"
!#
$
Figure 10. Echo signal sampling and processing
The ADC sampled data processing is software-based. The ADC data is compared with the ADC sample
threshold, which is set to 3.5 V. Where there is software comparator first match, the first pulse time is
captured (time stamp). From now on, each software comparator match increments the signal strength
counter (number of samples) and the signal maximal amplitude is worked out. When there is no software
comparator match for a maximum period of 68 us, the echo end is promoted.
The echoes parameters are sorted into a three dimensional array capturing:
• First sample time
• Number of samples
• Maximal amplitude
3.5
Object distance calculation
The echo reception is finished when a 30 ms period has expired, starting from the burst signal transition.
As the first step, the echo with the maximal amplitude is singled out. Echoes with an amplitude below 80%
of this maximal amplitude are discarded.
As the next step, the echo with the maximal number of samples is singled out. Echoes with a number of
samples below 25% of this maximal number of samples are discarded.
The described filtering process allows elimination of weak object reflections, that appear at the sides of
the transducer’s lobe and disturb the desired object distance measurement.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
11
Ultrasonic sensing application
As the last step, the echoes are sorted by value of the first sample time. The echo with the shortest period
is promoted as the desired object echo.
The object distance is calculated, see Eqn. 1, with sound velocity compensated for by the actual
temperature, see Eqn. 2. Calculation is proceed in 16-bit fractional arithmetic using AMMCLIB [6]. The
actual temperature is measured by the on-chip temperature sensor.
The calculated object distance value is then averaged using a digital 2nd order IIR low-pass filter with a 2
Hz transition frequency. The IIR filter is part of the AMMCLIB [6].
The object distance is measured in millimeters and reported, as depicted in Table 3.
Table 3. Object distance reporting
3.6
Object distance [mm]
Measured distance
RGB LED color
RG LED color
0 - 199
0
Red
Red
200 - 349
Object distance
Red and Green
Red and Green
350 - 499
Object distance
Green and Blue
500 - 4000
Object distance
Blue
more than 4000
65535 (0xFFFF)
Green
RGB LED control and diagnostics
The on-board RGB LED color control is based on the measured object distance, as depicted in Table 3.
The PWM module drives the LED with a 16-bit resolution, enabling a smooth change of the LED color.
The RGB LED diagnostics module reports the actual LED average current, calculated using the LED
voltage and applied PWM duty cycle.
The actual LED voltage is sampled by the ADC when the LED is turned ON, approximately 3 us for red,
6 us for green and 9 us 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, and the
diode peak current during a 1ms time slot from 0.135 ms to 1.135 ms, see Table 1.
The calculation is carried out in 16-bit fractional arithmetic using the AMMCLIB [6].
More information can be found in AN4842 [7].
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
12
Freescale Semiconductor
Ultrasonic sensing application
3.7
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 11. 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 4.
!
"
!
"
Figure 11. 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 4. LIN signal line switch control
MCU PS0 pin
LIN_IN and LIN_OUT
High level
Disconnected
Low level
Connected
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
13
MC9S12ZVL32 modules configuration
4
MC9S12ZVL32 modules configuration
The Ultrasonic sensing 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 modules’ configuration and usage is described in the following chapters. Detailed information on the
MCU modules can be found in the MC9S12ZVL32 reference manual [4].
The application software is developed to meet the following specification:
• Object distance ultrasonic measurement in the range of 20 cm to 4 m at 25°C
• Object distance measurement compensation for the temperature
• Echo signal processing in the digital domain
• RGB LED control and diagnostics
• FreeMASTER enabled
For detailed info, see Section 5, “Ultrasonic sensing application demo”
4.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):
VCOCLK =  2   SYNDIV + 1    1MHz
Eqn. 7
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.
The chip temperature sensor is enabled (CPMUHTCTL_HTE = 1).
4.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 1us (TIM0TSCR2_PR = 5).
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
14
Freescale Semiconductor
MC9S12ZVL32 modules configuration
4.3
Pulse Width Modulator
The Pulse Width Modulator module generates the ultrasonic sensor burst signal and 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 PWM clock A equals the
32MHz bus clock (PWMPRCLK_PCKA = 0) and the PWM clock B equals 16 MHz
(PWMPRCLK_PCKB = 1).
The channels PWM1, PWM3, PWM5 generate a 244 Hz PWM starting with a low-level polarity
(PWMPOL1 = 0, PWMPOL3 = 0, PWMPOL5 = 0) to control the RGB LED. As a clock source, clock B
is selected.
The channel PWM7 generates a 40 KHz PWM starting with a high-level polarity (PWMPOL7 = 1) and a
duty cycle of 38% to control the ultrasonic transducer sender. As a clock source, clock A is selected.
The PWM1, PWM3, PWM5 channels are enabled (PWME_PWME1 = 1, PWME_PWME3 = 1,
PWME_PWME5 = 1). The PWM7 channel is enabled only to generate the burst, see Section 3.1,
“Scheduling".
4.4
Analog-to-Digital Converter
The Analog-to-Digital Converter is used to sample the echo signal and LED voltage.
The ADC clock is set to 8MHz (ADC0TIM = 1). The ADC module is configured to access mode via the
data bus (ADC0CTL_0_ACC_CFG = 2). The ADC is running in trigger mode (ADC0CTL_0_MOD_CFG
= 1). The end-of-list interrupt is enabled (ADC0CONIE_1_EOL_IE = 1).
Based on the application scheduler described in Section 3.1, “Scheduling", the ADC module is
periodically reconfigured every 30 ms.
In the first 30 ms period, the ADC module samples the echo signal using the single command sequence
list (ADC0CTL_1_CSL_BMOD = 0) and the two result value list (ADC0CTL_1_RVL_BMOD = 1) with
8-bit resolution (ADC0FMT_SRES = 0). The command sequence list drives the ADC to convert 15
consecutive samples of the echo signal. With an ADC 8-bit resolution, an end-of-list interrupt arises every
34us and sampled data is processed. The double buffer mode allows a continuing echo signal sampling,
while the sampled data from the other list is processed.
The following 30 ms period, the ADC module samples LED voltage and on-chip temperature sensor
voltage using the single command sequence list (ADC0CTL_1_CSL_BMOD = 0) and the single result
value list (ADC0CTL_1_RVL_BMOD = 0) with 10-bit resolution (ADC0FMT_SRES = 2). The LED
voltage is recalculated to the LED average current, see Section 3.6, “RGB LED control and diagnostics".
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
15
MC9S12ZVL32 modules configuration
4.5
Port Integration Module
The Port Integration Module is used to drive the RGB LED, see Section 3.6, “RGB LED control and
diagnostics", control the PGA, see Section 3.3, “Echo receiver”, and control the LIN switch, see
Section 3.7, “LIN Slave node position detection”.
The port pins PT3, PT4 and PT5 can be used to debug the application by enabling either the
ULTRASONIC_APPLICATION_DEBUG or LED_APPLICATION_DEBUG macros, see Table 5. The
pins share SCI and TIM modules as well.
Table 5. Application debug
4.6
MCU pin
ULTRASONIC_APPLICATION_DEBUG
LED_APPLICATION_DEBUG
PT3
ADC end-of-list interrupt
-
PT4
PGA gain changed
ADC end-of-list interrupt
PT5
Time slot expired
PWM falling edge generated
Interrupt
The 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 - time slot expired
3. The PIM Port P - PWM module signal falling edge captured
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
16
Freescale Semiconductor
Ultrasonic sensing application demo
5
Ultrasonic sensing application demo
The ultrasonic sensing application demo can be build using attached AN4841SW.zip file containing
X-S12ZVL32-USLED board hardware and software files.
5.1
Hardware
The X-S12ZVL32-USLED board, see Figure 12, is built using the AN4841SW.zip hardware files. These
files include the board schematic, bill of materials, gerber files and an instruction for board manufacturing.
Figure 12. The X-S12ZVL32-USLED board
The X-S12ZVL32-USLED board contains, see Section Appendix A, “X-S12ZVL32-USLED board
schematic":
• MC9S12ZVL32 LQFP32 MCU, see [4]
• LIN Slave node position detection hardware
• Ultrasonic sensing circuitry:
— Burst module
— Programmable gain amplifier
— Sender and receiver transducers
• RGB LED with diagnostics hardware
• Reverse battery protection
• BDM enabled
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
17
Ultrasonic sensing application demo
5.2
Software
The software files are packed as the MC9S12ZVL32_UDSD_REV1.exe file available in AN4841SW.zip
file. The application is developed using the CW10.3 environment. The
MC9S12ZVL32_UDSD_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 ultrasonic sensing application demo shows:
• Object distance measurement in the range of 20cm to 4m at 25°C
• Object distance measurement compensation for the temperature
• Smooth RGB LED color control based on the actual object distance
• RGB LED diagnostics
• FreeMASTER tool displays:
— Actual object distance
— RGB LED average current
• Integrating the AMMCLIB [6].
5.3
Demo set-up
The demo set-up is depicted in Figure 13. The demo is designed to be able to run either with or without
the FreeMASTER tool. The demo user chooses the actual object distance visualization.
Figure 13. Demo Set-up
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
18
Freescale Semiconductor
Ultrasonic sensing application demo
Follow the instructions for a complete demo set-up:
1. Install the FreeMASTER tool [5] 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_UDSD_LED.pmp” file, available in the project AN4841SW.zip file
6. Go to the FreeMASTER file Project/Options folder and check the settings as depicted in Figure 14
and Figure 15
7. Run FreeMASTER communication by File/Start Communication
8. Put an object (e.g book, paper, etc.) in front of the ultrasonic transducers U2 and U4. The RGB
LED color will change smoothly based on the actual object distance, see Section 3.6, “RGB LED
control and diagnostics":
a) Red - object closer than 20 cm
b) Red and Green combination - object distance between 20 cm and 35 cm
c) Green - object distance 35 cm
d) Green and Blue combination - object distance between 35 cm and 50 cm
a) Blue – object distance more than 50 cm
9. The object distance is displayed on the FreeMASTER page, see Figure 16
10. The RGB LED average current is displayed on the FreeMASTER page, see Figure 17
11. The RGB LED can be controlled, see Figure 17:
a) OFF
b) Red and Green combination
c) Red, Green and Blue combination
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
19
Ultrasonic sensing application demo
Figure 14. FreeMASTER Communication configuration
Figure 15. FreeMASTER MAP Files configuration
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
20
Freescale Semiconductor
Ultrasonic sensing application demo
Figure 16. FreeMASTER object distance display
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
21
Ultrasonic sensing application demo
Figure 17. FreeMASTER RGB LED average current
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
22
Freescale Semiconductor
References
6
References
1.
2.
3.
4.
5.
6.
7.
Wikipedia, www.wikipedia.com
Ultrasonic Sensor Application Manual S15E-5, www.murata.com
MA40S4S and MA40S4R Datasheet, www.murata.com
MC9S12ZVL Family Reference Manual, available at freescale.com
FreeMASTER Run-Time Debugging Tool, available at freescale.com/freemaster
Automotive Math and Motor Control Library Set, available at freescale.com/AutoMCLib
AN4842, S12ZVL LIN Enabled RGB LED Lighting Application, available at freescale.com
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
23
Acronyms
7
Acronyms
ADC
Analog-to-Digital Converter
AMMCLIB Automotive Math and Motor Control Library Set
BDM
Background Debug Module
CMPU
Clock, Reset and Power Management Unit
DC
Direct Current
HVI
High Voltage Input
IIR Filter
Infinite Impulse Response Filter
INT
Interrupt
ISR
Interrupt Service Routine
LIN
Local Interconnect Network
MCU
Microcontroller Unit
PC
Personal Computer
PGA
Programmable Gain Amplifier
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 Ultrasonic Distance Measurement, Rev. 1.0
24
Freescale Semiconductor
X-S12ZVL32-USLED board schematic
Appendix A X-S12ZVL32-USLED board schematic
For this schematic, please refer to “X-S12ZVL32-USLED.pdf”, attached with the pdf of this
Application Note.
S12ZVL LIN Enabled Ultrasonic Distance Measurement, Rev. 1.0
Freescale Semiconductor
25
How to Reach Us:
Information in this document is provided solely to enable system and software
Home Page:
freescale.com
implementers to use Freescale products. There are no express or implied copyright
Web Support:
freescale.com/support
information in this document.
licenses granted hereunder to design or fabricate any integrated circuits based on the
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: http://www.reg.net/v2/webservices/Freescale/Docs/TermsandConditions.htm
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.
Document Number: AN4841
Rev. 1.0
3/2014