AN52678 PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt.pdf

AN52678
PSoC® 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Author: Archana Yarlagadda
Associated Part Family: CY8C21x34/21x24/24x33/
24x34A/24x94/27x43/29x66
Associated Code Examples: None
Related Application Notes: AN2010, AN2099
AN52678 describes how to measure orientation and tilt with PSoC® 1 using the KXSC7/KXTC9 triaxial analog
accelerometer. Additional information is provided to help you interface other triaxial accelerometers to PSoC 1
devices.
Contents
1
2
3
4
5
6
7
A
1
Introduction ............................................................1
PSoC Resources....................................................2
Types of Accelerometers ........................................2
Interface with PSoC................................................2
4.1
User Modules and Routing .............................3
4.2
Resources Used in Different PSoC Families ...5
4.3
Firmware Code and Control............................5
4.4
Interface with Other Analog Accelerometers....6
Setup for Testing and Graphical Interface ...............6
Results ..................................................................7
Summary ...............................................................9
Appendix A .......................................................... 10
A.1
Accelerometer Types and Applications ......... 10
A.2
Applications ................................................. 10
B
Appendix B .......................................................... 11
B.1
KXSC7-2050 Accelerometer ........................ 11
Document History ......................................................... 12
Worldwide Sales and Design Support ........................... 13
Products ...................................................................... 13
PSoC® Solutions .......................................................... 13
Cypress Developer Community..................................... 13
Technical Support ........................................................ 13
Introduction
Accelerometers are electromechanical devices that change output based on dynamic (force from an external source)
and static acceleration (earth’s gravitational force: “g”). This facilitates measurement of orientation, tilt, inclination,
vibration, rotation, and other parameters. Different types of accelerometers and algorithms are suited for each of
these parameters. This application note shows the interface with Programmable System-on-Chip™ (PSoC) to obtain
the orientation and tilt with respect to earth (static acceleration). You can use this interface technique with other
accelerometers and algorithms to suit your application.
www.cypress.com
Document No. 001-52678 Rev.*E
1
PSoC® 1 Interface
2
with
Triaxial Analog Accelerometer for Measuring Tilt
PSoC Resources
Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device for your design,
and quickly and effectively integrate the device into your design. In this document, PSoC refers to the PSoC 1 family
of devices. To learn more about PSoC 1, refer to the application note AN75320 - Getting Started with PSoC 1.
The following is an abbreviated list for PSoC 1:
3


Overview: PSoC Portfolio, PSoC Roadmap

Datasheets: Describe and provide electrical
specifications for the PSoC 1 device family.

Application Notes and Code Examples:
Cover a broad range of topics, from basic to
advanced level. Many of the application
notes include code examples.

Technical Reference Manuals (TRM):
Provide detailed descriptions of the internal
architecture of the PSoC 1 devices.

Product Selectors: PSoC 1, PSoC 3,
PSoC 4, or PSoC 5LP. In addition, PSoC
Designer includes a device selection tool.

Development Kits:

CY3215A-DK In-Circuit Emulation Lite
Development Kit includes an in-circuit
emulator (ICE). While the ICE-Cube is
primarily used to debug PSoC 1 devices,
it can also program PSoC 1 devices
using ISSP.

CY3210-PSOCEVAL1 Kit enables you to
evaluate and experiment Cypress's
PSoC 1 programmable system-on-chip
design methodology and architecture.

CY8CKIT-001 is a common development
platform for all PSoC family devices.
The MiniProg1 and MiniProg3 devices
provide an interface for flash programming.
Types of Accelerometers
Accelerometers are divided based on their output type, sensing method, manufacturing technology, and other
properties. Appendix A provides the types of accelerometers based on different parameters. One of the parameters
considered for differentiating accelerometers is its output type. Accelerometers can have either analog or digital
output. The analog output accelerometers often have voltage as the output, while digital output accelerometers have
PWM waveform, I2C, or SPI. Analog accelerometers output the most raw data form and data processing is highly
flexible. Digital PWM output accelerometers involve computation and timing analysis to get the acceleration.
Accelerometers with digital communication output (I 2C/SPI) have ADCs and digital communication modules
integrated into the chip along with the basic analog output accelerometer. This added hardware increases the cost of
the accelerometer. PSoC, with its programmability and analog capability, can interface with all three types.
As analog output type provides raw data and is cost effective, this application note focuses on the interface of analog
accelerometers with PSoC.
Appendix A gives details of the analog output accelerometers for different applications. Examples of triaxial analog
accelerometers are KXTC9, MMA7360L, MMA7260Q, ADXL330, BMA140, and LIS344AL. The KXSC7/KXTC9
series accelerometer is selected to show the interface in this application note; the same technique can be applied to
other accelerometers.
4
Interface with PSoC
This document assumes that you are familiar with the PSoC User Modules (UM). If you are new to PSoC, refer to the
PSoC 1 training modules on the Cypress website. The projects accompanying this application note use the
CY8C24533 device. The accelerometer interface can also be implemented with other PSoC families, based on the
same technique. The resources required in different PSoC families are provided in a later section.
Figure 1 shows the block diagram of the system. The voltages on the accelerometer outputs (X, Y, and Z) change
based on the acceleration. These inputs are multiplexed into ADC and converted into a digital value. The measured
voltage on the three axes can be processed based on your application. For example, the output voltages Vx, Vy, and
Vz on X, Y, and Z outputs can be used to measure tilt.
The voltages measured are converted into acceleration in the respective axes. The voltage to acceleration
conversion is based on the sensitivity index and offset of the accelerometers, as shown in the following equation.
www.cypress.com
Document No. 001-52678 Rev.*E
2
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Acceleration (gx) = (Vx – Offset) × Sensitivity
The acceleration in Y and Z directions are obtained using the above equation based on the respective output
voltages. These values are used to measure tilt.
Figure 1. Block Diagram of Accelerometer with PSoC
PSoC
Accelerometer
(KXSC7-2050)
X
P0[2]
Y
P0[1]
Z
P0[0]
MUX
ADC
I2C
USBI2C
Bridge
PC
PSoC Internal
VDD GND Mode ST/MOT Enable
P1[7] P1[6] P1[5] P1[5]
P1[3]
PSoC Hardware Module
Control
PSoC Software Module
External Devices
Tilt of an element is given by its angle of X, Y, and Z axes relative to ground. These angles of tilt: pitch (φ), roll (ρ),
and theta (θ) can be calculated in firmware from the measured voltages with the following equations:
tan
1
gX
g Y2
tan
1
gY
g X2
tan
1
g Z2
g Z2
g Y2 g X2
gZ
The example project converts the ADC counts into the corresponding voltages, and obtains the acceleration in each
axis by considering the offset and sensitivity of the considered accelerometer. If you want to interface with any other
triaxial accelerometer, change the offset and sensitivity values to values provided in the accelerometer datasheet.
2
2
The example project makes use of the I C UM and transfers data via the external I C-USB Bridge hardware. The
output is then plotted using the Bridge Control Panel software for graphical interface. Instead of transmitting to a
graphical interface, you can use the orientation/tilt of the device to implement other functions in your project.
4.1
User Modules and Routing
The modules required to implement the accelerometer interface are an analog multiplexer and an ADC. The value
obtained from the ADC can be processed as desired for your application. Thus all other modules such as the EzI2Cs
(I2C communication) UM, used in the example project for GUI interface, are optional.
4.1.1
Im pl em e nt a ti on wi t h ADCI NC
The Accelarometer_Project_ADCINC example provided with this application note uses an incremental ADC for the
analog to digital conversion of the accelerometer data. The incremental ADC, ADCINC UM, is built using the
programmable analog blocks present in PSoC. The ADCINC UM is available in all PSoC families and is thus chosen
to show the accelerometer interface. The UM placement and routing is shown in Figure 2.
www.cypress.com
Document No. 001-52678 Rev.*E
3
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Figure 2. Routing in PSoC with ADCINC as ADC
Because the ADCINC UM is a switched capacitor block, an additional buffer is required between the pin and ADC, as
shown in Figure 2. This is to avoid impedance loading on the SC circuit when connected to a high-impedance node.
The three inputs from the triaxial accelerometer are multiplexed to the ADC UM with analog multiplexers. The port
and pin numbers are changed to match the port and pin numbers to which X, Y, and Z inputs are connected.
AMUX8_InputSelect(AMUX8_PORT0_2);
The resolution in ADCINC can be set from 6 bit to 14 bit, as shown in Figure 3. For the accelerometer chosen
(KXSC7), the typical supply voltage is 2.8 V and its sensitivity is 560 mV/g. The resolution of acceleration due to
gravity that can be achieved with a 14-bit ADC is as follows:
“g” per ADC count
2.8
560 10
3
0.3 mg
(214 1)
Figure 3. ADCINC Configuration
4.1.2
Im pl em e nt a ti on wi t h SAR ADC
The Accelerometer_SAR8_Project example provided with this application note uses SAR ADC to convert the analog
output from the accelerometer to digital data for processing. The project is implemented using the CY8C24x33 device
family. This PSoC family has an additional SAR ADC along with ADCs such as ADCINC. This ADC only has 8-bit
resolution, but is a standalone UM. It does not need any additional digital or analog blocks for its implementation.
Unlike the ADCINC UM, SAR8 does not need buffer between the pins and ADC. Thus, when you are using the
CY8C24x33 device and have limited resources, you can use the SAR ADC as shown in this section. The routing in
PSoC Designer for SAR ADC implementation is shown in Figure 4. Multiplexing ports into the SAR8 block is done in
firmware, by changing the contents of registers, as follows.
SAR8_SelectADCChannel(SAR8_P0_2);
www.cypress.com
Document No. 001-52678 Rev.*E
4
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Figure 4. Routing in PSoC with SAR8 as ADC
The SAR8 is an 8-bit ADC, and the configuration for the ADC is shown in Figure 5.
Figure 5. Configuration of SAR ADC
4.2
Resources Used in Different PSoC Families
Different UMs can be used to implement the same project in different PSoC families.
Table 1 shows the resources required when you use other PSoC families.
Table 1. Resources Used for Accelerometer Project
Part Number
CY8C
4.3
Digital
Bocks
Analog
Blocks
2
Flash (KB)
SRAM (Bytes) Decimator
IC
Controller
User Modules
A
U
A
U
A
U
A
U
A
U
A
U
A=Available, U=Used
24x33
4
0
4
0
8
0.5
256
6
1
0
1
1
SAR8, EzI2C
29x66
16
1
12
2
32
0.5
2048
14
1
1
1
1
ADCINC, PGA, EzI2C
27x43
8
1
12
2
16
0.5
256
14
1
1
1
1
ADCINC, PGA, EzI2C
24x94
4
1
6
2
16
0.5
1024
14
1
1
1
1
ADCINC, PGA, EzI2C
24x23A
4
1
6
2
4
0.5
256
14
1
1
1
1
ADCINC, PGA, EzI2C
21x34
4
1
4
2
8
0.8
512
17
0
0
1
1
ADC8, EzI2C
21x23
4
1
4
2
4
0.8
256
17
0
0
1
1
ADC8, EzI2C
Firmware Code and Control
All the UMs are started and the appropriate inputs are connected to the ADC in firmware. The output of the ADC can
then be processed based on the end application. In the example project, the acceleration and tilt in each axis is
2
calculated and transmitted through an I C bridge and plotted on a GUI.
www.cypress.com
Document No. 001-52678 Rev.*E
5
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
4.3.1
M e a s ur e Ac c e l e r at i on
For each axis connection, the ADC input is sampled and the ADC counts are converted to the voltage equivalent
value in this function. The KXSC7-2050 has an offset voltage of 1.65 V and this is subtracted from the voltage
measured. Then, voltage is converted to the “g” equivalent based on the sensitivity of the accelerometer. When other
accelerometers are used, the offset and sensitivity parameters must be changed to the respective accelerometer
values. The code change required is provided in the Interface with Other Analog Accelerometers section.
The results are plotted as acceleration in each direction, but they can also be plotted as the angle of tilt in each
direction. Similarly, other data processing can also be done in firmware.
4.3.2
M e a s ur e Til t
The tilt in each axis is obtained from the acceleration on each axis, using the equations provided earlier.
4.3.3
I I R Fil t e r
The acceleration obtained is filtered using the software IIR method by taking a part of the old value and adding to a
part of the new value. This method is explained in application note AN2099, PSoC 1, PSoC 3, PSoC 4, and
PSoC 5LP - Single-Pole Infinite Impulse Response (IIR) Filters.
4.3.4
I 2 C Com m uni c at i on
The acceleration on each axis after converting to “g” is stored in the I 2C RAM buffer. The PSoC is configured as an
I2C slave using the EzI2Cs UM. These values are transferred over the I2C-USB Bridge and displayed using the
Bridge Control Panel software.
4.4
Interface with Other Analog Accelerometers
The project provided with this application note can be adapted to interface with other triaxial accelerometers by
changing the following parameters in the “main.c” code:
//Volts per count=(3.3V/2^8)=0.0128
#define ADC_VOLTS_PER_COUNT 0.0128
//KXSC7-2050 1/sensitivity=1.515 g/V
#define ACCL_SENSITIVITY 1.515
//KXSC7-2050 Offset = 1.65 V
#define ACCL_OFFSET 1.65
When other triaxial accelerometers are used, the sensitivity and offset corresponding to the accelerometer, should be
modified. If a different ADC resolution or supply voltage is used, “ADC_VOLTS_PER_COUNT” should be changed.
5
Setup for Testing and Graphical Interface
The Kionix KXSC7-2050 is interfaced with PSoC using the CY3210-PSoCEval1 board as shown in Figure 6. Table 2
shows the PSoC connections. The KXTC9-2050 accelerometer can also be interfaced with PSoC using the same
2
project. The PSoC port pins and the accelerometer pins are connected. The results are observed using the I C-USB
bridge. Refer to AN50987 - Getting Started with I2C in PSoC 1 for details on using the I 2C-USB Bridge. Either the
acceleration or tilt on each axis can be displayed on the GUI. The Results section displays the acceleration.
www.cypress.com
Document No. 001-52678 Rev.*E
6
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Figure 6. Board Setup to Test Accelerometer Interface
Table 2. CY3210 Evaluation Board Setup
PSoC 1 Pins CY3210 Connections
6
Description
P0[2]
-
X-axis output from KXSC7-2050/KXTC9-2050
P0[1]
-
Y-axis output from KXSC7-2050/KXTC9-2050
P0[0]
-
Z-axis output from KXSC7-2050/KXTC9-2050
P1[3]
-
Enable signal for KXSC7-2050/KXTC9-2050
P1[4]
-
ST/MOT signal for KXSC7-2050/KXTC9-2050
P1[5]
-
Mode signal for KXSC7-2050
-
ISSP header (J11)
Connect MiniProg1 or MiniProg3 for programming
-
ISSP header (J11)
Connect MiniProg3 for I2C communication to PC; P1[0] and P1[1] are routed in CY3210
Results
The acceleration on each axis is displayed in the graph and is expressed in terms of “g”. KXSC7-2050/KXTC9-2050
is a three-axis, 2g accelerometer, the g values for the X, Y, and Z axes are between –1 and +1.
Different orientation of the board leads to different “g” values on the output. Figure 7 through Figure 12 show some
combinations. The board orientation is changed manually; therefore, the outputs vary slightly from the expected
values.
Figure 7. Board Inline with “g” and X = 0g, Y = 1g, and Z = 0g
www.cypress.com
Document No. 001-52678 Rev.*E
7
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Figure 8. Board Inline with “g” and X = 1g, Y = 0g, and Z = 0g
Figure 9. Board Inline with “g” and X = 0g, Y = –1g, and Z = 0g
Figure 10. Board Inline with “g” and X = –1g, Y = 0g, and Z = 0g
Figure 11. Accelerometer Chip Perpendicular to Earth and on Top
www.cypress.com
Document No. 001-52678 Rev.*E
8
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Figure 12. Accelerometer Chip Perpendicular to Earth and on Bottom
The graph obtained when the board is changed from one position to another is shown in Figure 13.
Figure 13. Accelerometer Moved Along Different Axes
When there is a free fall, X, Y, and Z have 0g acceleration.
7
Summary
An accelerometer type can be selected based on your application. It is possible to interface both digital and analog
output accelerometers with PSoC. This application note demonstrates the interface of a triaxial analog output
accelerometer to obtain acceleration and tilt. This application note also provides the simple changes required to
interface other triaxial accelerometers.
About the Author
www.cypress.com
Name:
Archana Yarlagadda
Title:
Applications Engineer
Background:
Masters in Analog VLSI, University of Tennessee,
Knoxville
Document No. 001-52678 Rev.*E
9
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
A
Appendix A
A.1
Accelerometer Types and Applications
All accelerometers have a mechanical mass that converts vibration into displacement. This displacement is sensed
using a sensor. The classification of accelerometers based on sensor type is listed in Table 3.
Table 3. Accelerometer Types and Properties
Accelerator Type
Properties
Measurement
Capacitive
Good DC accuracy, low noise, good temperature performance
Tilt, Vibration
Piezoelectric
AC response only
Vibration, Shock
Piezoresistive
Good DC accuracy, poor temperature performance
Tilt, Vibration
Electromechanical Servo
Good DC accuracy, low frequency only, fragile
Tilt
The choice of accelerometer depends on the type of application in which it is used.
A.2
Applications
Some applications in which accelerometers are used are as follows:



Mobile Phones: Used for motion activated functions, gaming, free-fall detection, and vibration control.


Medical Appliances: Used in pacemaker and blood pressure measurement applications.
Vehicles: Used for crash testing, robotics, motion control, and skid detection.
Computers: Used in computers and computer peripherals such as mouse, for motion activated functions,
gaming, and tilt sensing.
Home Appliances: Used in appliances such as washing machines for spin and vibration measurement.
www.cypress.com
Document No. 001-52678 Rev.*E
10
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
B
Appendix B
B.1
KXSC7-2050 Accelerometer
KXSC7-2050 is a tri-axis, analog voltage output device. The output range of this device is ±2g, or 19.9 m/s2. The
voltage on the three outputs change based on the static and dynamic acceleration of the device. The functional block
diagram of the accelerometer is shown in Figure 14. This diagram is reproduced from the datasheet of the KXSC7
accelerometer.
Figure 14. Functional Block Diagram of KXSC7-2050
The sensor element in the accelerometer works on the principle of differential capacitance. Here, the acceleration
causes displacement in the silicon structure, resulting in a change in capacitance. The ASIC is included inside the
package to convert change in capacitance into analog voltage, which is proportional to acceleration. It also features a
programmable low-pass filter. Thus the output voltages can be read directly by the ADC and processed accordingly.
The KXTC9 is a high-performance, tri-axis accelerometer with analog outputs, a factory-programmable low-pass
filter, and g-range from ±1.5g to ±6g. The functional block diagram of the KXTC9-2050 accelerometer is provided in
Figure 15.
Figure 15. Functional Block Diagram of KXTC9-2050
www.cypress.com
Document No. 001-52678 Rev.*E
11
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Document History
®
Document Title: AN52678 - PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Document Number: 001-52678
Revision
ECN
Orig. of
Change
Submission
Date
Description of Change
**
2683340
YARA
04/03/2009
New application note.
*A
3170736
YARA
02/15/2011
1. Change of title, abstract, and introduction.
2. Figure and description about ADC configurations, as per customer feedback.
3. Information required for interfacing with other three-axis analog accelerometers.
4. Update of projects from PSoC Designer 5.0 to 5.1.
*B
3271365
YARA
06/01/2011
Updated title as per template.
*C
4368577
MSUR
05/02/2014
Updated in new template.
Completing Sunset Review.
*D
4635405
DIMA
01/22/2015
Updated the document as per new template.
Updated the Software Version to “PSoC Designer™ 5.4 CP1” in page 1.
Removed reference to obsolete AN2352 in Interface with PSoC.
Updated the hyperlink AN2352 to AN2099 in IIR Filter.
Included support for KXTC9-2050 accelerometer in Appendix B.
*E
4756504
www.cypress.com
MSUR
05/06/2015
Added the PSoC Resources section. Updated Figure 1 and added Table 2.
Document No. 001-52678 Rev.*E
12
®
PSoC 1 Interface with Triaxial Analog Accelerometer for Measuring Tilt
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Interface
cypress.com/go/interface
Cypress Developer Community
Lighting & Power Control
cypress.com/go/powerpsoc
Memory
cypress.com/go/memory
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Community | Forums | Blogs | Video | Training
Technical Support
cypress.com/go/support
PSoC is a registered trademark and Programmable System-on-Chip and PSoC Designer are trademarks of Cypress Semiconductor Corp. All other
trademarks or registered trademarks referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2010-2015. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury t o the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conj unction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or rep resentation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of t he application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical comp onents in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
www.cypress.com
Document No. 001-52678 Rev.*E
13