Escolar Documentos
Profissional Documentos
Cultura Documentos
AN52678
Author: Archana Yarlagadda
Associated Project: Yes
Associated Part Family: CY8C21x34/ 21x24/ 24x33/
24x34A/ 24x94/ 27x43/ 29x66
Software Version: PSoC Designer™ 5.0
Associated Application Notes: AN2010, AN2352, AN2099
[+] Feedback
AN52678
Table 1. Accelerometer Types and Properties Figure 2. Functional Block Diagram of KXSC7-2050
Mobile Phones: Used for motion activated functions, Interface with PSoC
gaming, free-fall detection, and vibration control.
This document assumes that the reader is familiar with the
Vehicles: Used for crash testing, robotics, motion PSoC User Modules (UM). If you are new to PSoC, AN2010
control, and skid detection. Getting Started with PSoC is a good reference. The project
Computers: Used in computers and computer accompanying this application note uses CY8C24533. The
peripherals such as mouse, for motion activated following sections are based on the same PSoC family. The
functions, gaming, and tilt sensing. accelerometer project can also be implemented with other
Medical Appliances: Used in pacemaker and blood PSoC families.
pressure measurement applications.
Block Diagram and Working
Home Appliances: Used in appliances such as washing
The voltages on the X, Y, and Z axes are measured directly
machines for spin and vibration measurement.
with a single ADC by multiplexing the input ports. The
This application note focuses on the use of accelerometers accelerometer has an internal low pass filter and thus it is
in mobile phones; therefore, both tilt and vibration are not implemented in PSoC. The block diagram of the system
measured. Considering the analog benefits of PSoC and the is shown in Figure 3.
properties of capacitive sensing, an analog output capacitive
sensing accelerometer is ideal for this application. Examples Figure 3. Block Diagram of Accelerometer with PSoC
of analog accelerometers that can be used are BMA140,
KXSC7–1050/KXSC7–2050, MMA7360L, ADXL330, and PSoC
LIS344AL. KXSC7 series accelerometer is selected here X
P0[2]
based on the requirements. Accelerometer Y
MUX ADC I2C Display
(KXSC7-2050) P0[1]
Z
The KXSC7-2050 Accelerometer P0[0]
PSoC Internal
VDD GND Mode ST/MOT Enable
KXSC7-2050 is a tri-axis, analog voltage output device. The P1[7] P1[6] P1[5] P1[5] P1[3] PSoC Hardware Module
output range of this device is ±2g, or 19.9 m/s2. The voltage Control PSoC Software Module
on the three outputs change based on the static and External Devices
dynamic acceleration of the device. The functional block The output of the ADC block can be processed using digital
diagram of the accelerometer is shown in Figure 2. This blocks, displayed using an LCD module, or transmitted
diagram is reproduced from the data sheet of KXSC7 using the UART, I2C, or SPI digital communication modules
accelerometer on the Kionix website. available in this chip.
The example project makes use of I2C UM and transfers the
data via the external I2C-USB Bridge hardware. The output
is then plotted using the Cypress I2C-USB Bridge software.
For more details about I2C Bridge usage and working, refer
to AN2352.
[+] Feedback
AN52678
Analog Blocks
SRAM (Bytes)
Digital Blocks
I2C Controller
User Modules
Part Number
Flash (KB)
Decimator
this application note.
CY8C
Figure 4. Routing in PSoC with SAR8 as ADC
A U A U A U A U A U A U A=Available, U=Used
The same functionality can be achieved by using an 24x23A 4 1 6 2 4 0.5 256 14 1 1 1 1 ADCINC, PGA, EzI2C
ADCINC to get a higher resolution than SAR8. 21x34 4 1 4 2 8 0.8 512 17 0 0 1 1 ADC8, EzI2C
Many PSoC families can be used to implement this project.
21x23 4 1 4 2 4 0.8 256 17 0 0 1 1 ADC8, EzI2C
The benefit of using this PSoC chip over others is that this
chip family has the hardware SAR8 block and does not use
the Switched Capacitor (SC) analog block. The use of SAR8 Software Code and Control
not only saves analog blocks, but also digital blocks that are A software code is used to start all the user modules and
used by most ADC UMs in other PSoC chips. connect the appropriate inputs to the SAR8 UM and process
The SC block also requires the input to be buffered through the data obtained. The different functions performed are as
PGA for two reasons. Only Port-2 pins can be connected to follows:
the SC blocks directly and are limited by one pin to a Get_Acceleration Function
particular block. For example, ASC10 block in PSoC
For each axis connection, the ADC input is sampled and the
Designer can be connected to only Port2[3] and not other
ADC counts are converted to the voltage equivalent value in
pins of Port-2. Thus multiplexing to use one ADC is not
this function. The KXSC7-2050 has an offset voltage of
possible, if connected directly to the SC block. The second
1.65V and this is subtracted from the voltage measured.
problem with connecting the input directly to a SC block
Then voltage is converted to the “g” equivalent, based on
ADC is the loading that happens on the SC circuit when
the sensitivity of the accelerometer.
connected to a high impedance node.
For a higher resolution, use an SC ADC at the expense of IIR Filter
analog blocks. The routing when an ADCINC UM is chosen The acceleration obtained is filtered using software IIR
is shown in Figure 5 method by taking a part of the old value and adding to a part
of the new value. This method is explained in application
Figure 5. Routing in PSoC with ADCINC as ADC note AN2352, Single-Pole IIR Filter.
I2C Communication
The acceleration on each axis after converting to “g” is
stored in the I2C RAM buffer. The PSoC is configured as an
I2C slave using the EzI2Cs UM. These values are
transferred over the I2C Bridge and displayed using the I2C
Bridge software.
[+] Feedback
AN52678
fAccl_Volt = (float)bAccl_Count *
Code with SAR8 ADC_VOLTS_PER_COUNT;
#include <m8c.h> //Convert Volts to "g"
#include "PSoCAPI.h" fAccl_g = (fAccl_Volt-
ACCL_OFFSET)*ACCL_SENSITIVITY;
//Volts per count=(3.3V/2^8)=0.0128 return(fAccl_g);
#define ADC_VOLTS_PER_COUNT 0.0128 }
//KXSC7-2050 1/sensitivity=1.515 g/V
#define ACCL_SENSITIVITY 1.515 Code with ADCINC and PGA
//KXSC7-2050 Offset = 1.65 V
#define ACCL_OFFSET 1.65 The code for a 14 bit ADCINC ADC is given below.
#include <m8c.h>
BYTE bAccl_Count; #include "PSoCAPI.h"
float fAccl_Volt;
float fAccelarometer_g[3]; //Volts per count=(3.3V/2^14)=0.0002
float Get_Accelaration(void); #define ADC_VOLTS_PER_COUNT 0.0002
//KXSC7-2050 1/sensitivity=1.515 g/V
void main() #define ACCL_SENSITIVITY 1.515
{ //KXSC7-2050 Offset = 1.65 V
//Setting I2C data size and address #define ACCL_OFFSET 1.65
EzI2Cs_SetRamBuffer(sizeof(fAccelarometer_g)
,0,(BYTE *)&fAccelarometer_g); int iAccl_Count;
float fAccl_Volt;
//Set Enable=1,Vdd=1,GND=0 and Mode=1 float fAccelarometer_g[3];
PRT1DR = (PRT1DR|0xA8)&(~0x40); float Get_Accelaration(void);
//Enable Global Interrupts
M8C_EnableGInt; void main()
{
//Start all the UMs and initialize //Setting I2C data size and address
SAR8_Start(); EzI2Cs_SetRamBuffer(sizeof(fAccelarometer_g)
EzI2Cs_Start(); ,0,(BYTE *)&fAccelarometer_g);
while(1)
{ //Set Enable=1,Vdd=1,GND=0 and Mode=1
//SAR8 input to P0[2]and sample X data PRT1DR =(PRT1DR|0xA8)&(~0x40);
SAR8_SelectADCChannel(SAR8_P0_2); //Enable Global Interrupts
//IIR filter : New_Value M8C_EnableGInt;
=0.9*Old_Value+0.1*New_Value
fAccelarometer_g[0]=0.9*(fAccelarometer_g[0] //Start all the UMs and initialize
)+0.1*(Get_Accelaration()); ADCINC_Start(ADCINC_HIGHPOWER);
PGA_Start(PGA_HIGHPOWER);
//SAR8 input to P0[1]and sample Y data AMUX8_Start();
SAR8_SelectADCChannel(SAR8_P0_1); while(1)
fAccelarometer_g[1]=0.9*(fAccelarometer_g[1] {
)+0.1*(Get_Accelaration()); //Connect PGA to P0[2]and sample X
AMUX8_InputSelect(AMUX8_PORT0_2);
//SAR8 input to P0[0]and sample Z data //IIR filter : New_Value
SAR8_SelectADCChannel(SAR8_P0_0); =0.1*Old_Value+0.9*New_Value
fAccelarometer_g[2]=0.9*(fAccelarometer_g[2] fAccelarometer_g[0] =
)+0.1*(Get_Accelaration()); 0.1*(fAccelarometer_g[0]) +
0.9*(Get_Accelaration());
}
} //Connect PGA to P0[1]and sample Y
float Get_Accelaration(void) AMUX8_InputSelect(AMUX8_PORT0_1);
{ fAccelarometer_g[1] =
float fAccl_g; 0.1*(fAccelarometer_g[1]) +
bAccl_Count=0; 0.9*(Get_Accelaration());
fAccl_Volt=0;
fAccl_g=0; //Connect PGA to P0[0]and sample Z
AMUX8_InputSelect(AMUX8_PORT0_0);
SAR8_Trigger(); fAccelarometer_g[2] =
//Wait till the ADC data is available 0.1*(fAccelarometer_g[2]) +
while (0 == SAR8_fIsDataAvailable()); 0.9*(Get_Accelaration());
//get the ADC counts data }
bAccl_Count = SAR8_bGetData(); float Get_Accelaration(void)
//convert ADC counts to Volts {
[+] Feedback
AN52678
float fAccl_g; Figure 8. Board Inline with “g” and X=1g, Y=0g and Z=0g
iAccl_Count=0;
fAccl_Volt=0;
fAccl_g=0;
ADCINC_GetSamples(1);
//Wait till the ADC data is available
while (0 == ADCINC_fIsDataAvailable());
//get the ADC counts data
iAccl_Count = ADCINC_iClearFlagGetData();
//convert ADC counts to Volts
fAccl_Volt = (float)iAccl_Count *
ADC_VOLTS_PER_COUNT; Figure 9. Board Inline with “g” and X= 0g, Y= -1 g and Z= 0g
//Convert Volts to "g"
fAccl_g = (fAccl_Volt-
ACCL_OFFSET)*ACCL_SENSITIVITY;
return(fAccl_g);
}
Setup for Experiment
Results
The output in the graph is expressed in terms of “g”.
Because KXSC7-2050 is a 3-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. Some combinations are shown in Figure 7
through Figure 12. The orientation of the board is changed Figure 12. Accelerometer Chip Perpendicular to Earth and
manually. Therefore, the outputs slightly vary from the on Bottom
expected values.
Figure 7. Board Inline with “g” and X=0g, Y=1g and Z=0g
[+] Feedback
AN52678
The graph obtained when the board is changed from one Summary
position to another is shown in Figure 13.
The accelerometer type is selected based on the application
Figure 13. Accelerometer Moved Along Different Axes to be implemented. It is possible to interface both digital and
analog output accelerometers with PSoC. This application
note demonstrates the interface of an analog output
accelerometer. Many PSoC families can be used to
implement the same functionality. This application note
serves as the basic format of interface and the data
obtained can be used to generate control signals based on
the target application.
[+] Feedback
AN52678
Document History
Document Title: Accelerometer Interface using PSoC®
Document Number: 001-52678
Revision ECN Orig. of Submission Description of Change
Change Date
** 2683340 YARA 04/03/09 New application note.
PSoC is a registered trademark of Cypress Semiconductor Corp. "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: 408-943-2600
Fax: 408-943-4730
http://www.cypress.com/
© Cypress Semiconductor Corporation, 2009. 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 to 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 conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation 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 the application or
use of any product or circuit described herein. 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 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.
[+] Feedback