Sensors Knowledge Base

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sensors Knowledge Base

Discussions

Sort by:
The MMA8491Q is a low voltage, 3-axis low-g accelerometer housed in a 3 mm x 3 mm QFN package. The device can accommodate two accelerometer configurations, acting as either a 45° tilt sensor or a digital output accelerometer with I2C bus.      • As a 45° Tilt Sensor, the MMA8491Q device offers extreme ease of implementation by using a single line output per axis.      • As a digital output accelerometer, the 14-bit ±8g accelerometer data can be read from the device with a 1 mg/LSB sensitivity. The extreme low power capabilities of the MMA8491Q will reduce the low data rate current consumption to less than 400 nA per Hz. Here is a Render of the MMA8491 Breakout Board downloaded from OSH park: Layout Design for this board: If you're interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
View full article
The MMA690x, a SafeAssure solution, is a dual axis, Low g, XY, Sensorbased on Freescale’s HARMEMS technology, with an embedded DSP ASIC, allowing for additional processing of the digital signals. Here is a Render of the MMA690x Breakout Board downloaded from OSH park: Layout Design for this board: In the attachments section, you can find the Schematic Source File (SCH), Schematic PDF File, Layout Source File (BRD), Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN) and BOM files.   If you're interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
View full article
The FXLN83XX is a 3-axis, low-power, low-g accelerometer along with a CMOS signal conditioning and control ASIC in a small 3 x 3 x 1 mm QFN package. The analog outputs for the X, Y, and Z axes are internally compensated for zero-g offset and sensitivity, and then buffered to the output pads. The outputs have a fixed 0 g offset of 0.75 V, irrespective of the VDD supply voltage. The bandwidth of the output signal for each axis may be independently set using external capacitors. The host can place the FXLN83XXQ into a low-current shutdown mode to conserve power. Here is a Render of the FXLN83XX Breakout Board downloaded from OSH park: Layout Design for this board: In the attachments section, you can find the Schematic Source File (SCH), Schematic PDF File, Layout Source File (BRD), Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN) and BOM files.    If you're interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOMEFreescale Sensors Breakout Boards Designs – HOME
View full article
The MMA845xQ is a smart low-power, three-axis capacitive micromachined accelerometer up to 14 bits of resolution. This accelerometer is packed with embedded functions with flexible user-programmable options, configurable to two interrupt pins. Embedded interrupt functions allow for overall power savings relieving the host processor from continuously polling data. There is access to both low-pass filtered data as well as high-pass filtered data, which minimizes the data analysis required for jolt detection and faster transitions. The device can be configured to generate inertial wake-up interrupt signals from any combination of the configurable embedded functions allowing the MMA845xQ to monitor events and remain in a low-power mode during periods of inactivity. Here is a Render of the MMA845x Breakout- Board downloaded from OSH Park: And here is an image of the Layout Design for this board: In the Attachments section, you can find the Schematic Source File (.SCH), Schematic PDF File, Layout Source File (BRD), Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN) and BOM for this Breakout-board. If you are interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
View full article
Hi Everyone,   In this document I would like to present a simple bare-metal example code/demo for the FXLN8371Q Xtrinsic three axis, low-power, low-g, analog output accelerometer. I have created it while working with the Freescale FRDM-KL25Z development platform and FXLN8371Q breakout board. The FreeMASTER tool is used to visualize the acceleration data that are read from the FXLN8371Q through ADC.   This example illustrates:   1. Initialization of the MKL25Z128 MCU (mainly ADC, PORT and PIT modules). 2. Simple offset calibration. 3. Accelerometer outputs reading using ADC and conversion of the 10-bit ADC values to real acceleration values in g’s. 4. Visualization of the output values in the FreeMASTER tool.   1. The FXLN8371Q breakout board (schematic is attached below) needs to have the following pins connected to the FRDM-KL25Z board:   J4-1 (VDD) => J9-4 (P3V3) J4-2 (XOUT) => J10-2 (PTB0/ADC0_SE8) J4-3 (YOUT) => J10-4 (PTB1/ADC0_SE9) J4-4 (ZOUT) => J10-6 (PTB2/ ADC0_SE12) J4-6 (GND) => J9-14 (GND) J3-3 (ST) => J9-14 (GND) J3-4 (EN) => J9-4 (P3V3)   The PIT (Periodic Interrupt Timer) is used to read the output data periodically at a fixed rate of ~200Hz. The MCU is, therefore, configured as follows.   void MCU_Init(void) {      //ADC0 module initialization      SIM_SCGC6 |= SIM_SCGC6_ADC0_MASK;        // Turn on clock to ADC0 module      SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;       // Turn on clock to Port B module      PORTB_PCR0 |= PORT_PCR_MUX(0x00);        // PTB0 pin is ADC0 SE8 input      PORTB_PCR1 |= PORT_PCR_MUX(0x00);        // PTB1 pin is ADC0 SE9 input      PORTB_PCR2 |= PORT_PCR_MUX(0x00);        // PTB2 pin is ADC0 SE12 input      ADC0_CFG1 |= ADC_CFG1_ADLSMP_MASK | ADC_CFG1_MODE(0x02);             // Long sample time, single-ended 10-bit conversion                           //PIT module initialization      SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;         // Turn on clock to PIT module      PIT_LDVAL0 = 52400;                      // Timeout period = ~5ms (200Hz)      PIT_MCR = PIT_MCR_FRZ_MASK;              // Enable clock for PIT, freeze PIT in debug mode                               //Enable PIT interrupt on NVIC          NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);      NVIC_ISER |= 1 << ((INT_PIT - 16) % 32); }   2. The simplest offset calibration method consists of placing the board on a flat surface so that X is at 0g, Y is at 0g and Z is at +1g. 16 samples are recorded and then averaged. The known sensitivity needs to be subtracted from the +1g reading to calculate an assumed 0g offset value for Z.   void Calibrate(void) {      unsigned int Count = 0;                    do                   // Accumulate 16 samples for X, Y, Z      {         ADC0_SC1A = ADC_SC1_ADCH(0x08);               // Process ADC measurements on ADC0_SE8/XOUT                                                                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};         Xout_10_bit += ADC0_RA;                                                                                                      ADC0_SC1A = ADC_SC1_ADCH(0x09);               // Process ADC measurements on ADC0_SE9/YOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};         Yout_10_bit += ADC0_RA;                                                                                                            ADC0_SC1A = ADC_SC1_ADCH(0x0C);                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};    // Process ADC measurements on ADC0_SE12/ZOUT               Zout_10_bit += ADC0_RA;                                                         Count++;                        } while (Count < 16);                    X_offset = (float) Xout_10_bit / 16;                             // Compute X-axis offset by averaging all 16 X-axis samples      Y_offset = (float) Yout_10_bit / 16;                             // Compute Y-axis offset by averaging all 16 Y-axis samples      Z_offset = ((float) Zout_10_bit / 16) - SENSITIVITY_2G;          // Compute Z-axis offset by averaging all 16 Z-axis samples and subtracting the known sensitivity                      PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK;          // Enable PIT interrupt and PIT                                      }   3. Reading the FXLN8371Q datasheet, the output voltage when there is no acceleration is typically 0.75V and it should typically change by 229mV per 1g of acceleration in ±2g mode. The signal from a 10-bit ADC gives me a number from 0 to 1023. I will call these “ADC units”.  0V maps to 0 ADC units, VDDA (2.95V on the FRDM-KL25Z board) maps to 1023 ADC units and let’s assume it is linear in between. This means that zero acceleration on an axis should give me a reading of 260 ADC units (0.75V / 2.95V x 1023 ADC units) on the pin for that axis. Also, a change of 1 ADC unit corresponds to a voltage difference of 2.95V / 1023 ADC units = 2.884mV/ADC unit. Since the datasheet says a 1g acceleration typically corresponds to 229mV voltage difference, I can easily convert it to ADC units/g:   229 mV/g = 229 mV/g x (1023 ADC units) / 2.95V = 79.4 ADC units/g = SENSITIVITY_2g   Using this calculated sensitivity and measured offset, I convert the 10-bit ADC values to real acceleration values in g’s in the PIT ISR as follows.   void PIT_IRQHandler() {      ADC0_SC1A = ADC_SC1_ADCH(0x08);                    // Process ADC measurements on ADC0_SE8/XOUT                                                  while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Xout_10_bit = ADC0_RA;                                         ADC0_SC1A = ADC_SC1_ADCH(0x09);                    // Process ADC measurements on ADC0_SE9/YOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Yout_10_bit = ADC0_RA;                                               ADC0_SC1A = ADC_SC1_ADCH(0x0C);                    // Process ADC measurements on ADC0_SE12/ZOUT                while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)){};      Zout_10_bit = ADC0_RA;                    Xout_g = ((float) Xout_10_bit - X_offset) / SENSITIVITY_2G;         // Compute X-axis output value in g's      Yout_g = ((float) Yout_10_bit - Y_offset) / SENSITIVITY_2G;         // Compute Y-axis output value in g's      Zout_g = ((float) Zout_10_bit - Z_offset) / SENSITIVITY_2G;         // Compute Z-axis output value in g's                     PIT_TFLG0 |= PIT_TFLG_TIF_MASK;          // Clear PIT interrupt flag }   4. The calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER application and FreeMASTER Communication Driver.       I guess this is enough to let you start experimenting with the FXLN83xxQ family of analog accelerometers. Attached you can find the complete source code written in the CW for MCU's v10.6 including the FreeMASTER project.   If there are any questions regarding this simple application, do not hesitate to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FRDM-KL25Z-FXLN8371Q-Basic-read-using-ADC.zip Original Attachment has been moved to: FreeMASTER---FRDM-KL25Z-FXLN8371Q-Basic-read-using-ADC.zip
View full article
Hi, The MMA865x, 3-axis, 10-bit/12-bit accelerometer that has industry leading performance in a small 2 x 2 x 1 mm DFN package. This accelerometer is packed with embedded functions that include flexible user-programmable options and two configurable interrupt pins. Overall power savings is achieved through inertial wake-up interrupt signals that monitor events and remain in a low-power mode during periods of inactivity. Here is a Render of the MMA865x Breakout- Board downloaded from OSH park: Layout Design for this board: In the attachments section, you can find the Schematic Source File (SCH), Schematic PDF File, Layout Source File (BRD), Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN) and BOM files. If you're interested in more designs like this breakout board for other sensors, please go to Freescale Sensors Breakout Boards Designs – HOME
View full article
Hello Freescale Community, Most of the new Freescale Sensors in our portfolio come in very small packages, some of them as small as 2x2x1mm, which is awesome! However, one of the problems that we detected last year is that many customers struggle in the evaluation stage of the project due to the small packages. They should either, buy an evaluation board or spend valuable time designing and manufacturing a PCB just for testing our devices. Our goal with this project is to share with our community the Freescale Sensors Breakout Boards we designed for this specific purpose, so you can easily manufacture your own sensor boards or modify our designs to fit  your specific application. This way you can easily evaluate Freescale sensors. The boards were designed to be used in a prototype board (DIP style pins) and they can communicate to any MCU thru IIC or SPI (depending on the sensor). These designs were made using Eagle Layout 6.5, if you want to modify the designs you can do it with the free version of Eagle CAD (for non-commercial purposes), or you can send the gerber files (included in the zip files) to your preferred PCB manufacturer. The following designs are available: + Altimeter: MPL3115A2 Breakout Board + Accelerometer: MMA845x Breakout Board MMA865x Breakout Board MMA8491 Breakout Board FXLN83xx Breakout Board FXLS8471 Breakout Board MMA690x Breakout Board + Accelerometer + Magnetometer (6-DOF): FXOS8700 Breakout Board + Gyroscope: FXAS2100x Breakout Board The above .ZIP files, contains the following design information: - Schematic Source File (.SCH) - Schematic (.PDF) - Layout Source File (.BRD) - Layout Images (.jpg) - Gerber Files (GTL, GBL, GTS, GBS, GTO, GBO, GKO, XLN). - PCB Render Image (.png created in OSH park) - BOM (.xls) Additional content: If you want to modify our designs, please download the attached library file "Freescale_Sensors_v2.lbr" and add it to your Eagle Library repository. We'll be more than glad to respond to your questions and please, let us know what you think. -Freescale Sensor's Support team.
View full article
This is the 9 December 2014 build of Vibration Monitoring program written by Mark Pedley in the Sensors Solutions Division systems/algorithms team.  It is compatible with Freescale FRDM-KL25Z/KL26Z/KL46Z/K64F Freedom development platforms.  You can flash your board using the File->Flash pull-down menu.    The application contains an option for controlling motor bias and feedback via optional motor control shield to be discussed in an upcoming Freescale blog.  Use the View->Motor Controls pull-down to enable those functions.
View full article
Here is the Installer file for the revision 4.2.0.8 of the Sensor Toolbox GUI
View full article
The attached is a copy of a presentation given 24 June 2014 at the Sensors Expo Conference in Rosemont IL.
View full article
Hi Everyone, In this article I would like to describe a simple bare-metal example code for the new Xtrinsic FXLS8471Q digital accelerometer. I have used recently released FRDM-FXS-MULTI(-B) sensor expansion board, that features many of the Xtrinsic sensors introduced in 2013 including the FXLS8471Q, in conjunction with the  Freescale FRDM-KL25Z development platform. The FreeMASTER tool is used to visualize the acceleration data that are read from the FXLS8471Q using an interrupt technique through the SPI interface. This example illustrates: 1. Initialization of the MKL25Z128 MCU (mainly SPI and PORT modules). 2. SPI data write and read operations. 3. Initialization of the accelerometer to achieve the highest resolution. 4. Simple offset calibration based on the AN4069. 5. Output data reading using an interrupt technique. 6. Conversion of the output values from registers 0x01 – 0x06 to real acceleration values in g’s. 7. Visualization of the output values in the FreeMASTER tool. 1. As you can see in the FRDM-FXS-MULTI(-B)/FRDM-KL25Z schematics and the image below, SPI signals are routed to the SPI0 module of the KL25Z MCU and the INT1 output is connected to the PTA5 pin (make sure that pins 2-3 of J6 on the sensor board are connected together using a jumper). The PTD0 pin (Chip select) is not controlled automatically by SPI0 module, hence it is configured as a general-purpose output. The INT1 output of the FXLS8471Q is configured as a push-pull active-low output, so the corresponding PTA5 pin configuration is GPIO with an interrupt on falling edge.The core/system clock frequency is 20.97 MHz and SPI clock is 524.25 kHz. The MCU is, therefore, configured as follows. void MCU_Init(void) {      //SPI0 module initialization      SIM_SCGC4 |= SIM_SCGC4_SPI0_MASK;        // Turn on clock to SPI0 module      SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;       // Turn on clock to Port D module      PORTD_PCR1 = PORT_PCR_MUX(0x02);         // PTD1 pin is SPI0 CLK line      PORTD_PCR2 = PORT_PCR_MUX(0x02);         // PTD2 pin is SPI0 MOSI line      PORTD_PCR3 = PORT_PCR_MUX(0x02);         // PTD3 pin is SPI0 MISO line      PORTD_PCR0 = PORT_PCR_MUX(0x01);         // PTD0 pin is configured as GPIO (CS line driven manually)      GPIOD_PSOR |= GPIO_PSOR_PTSO(0x01);      // PTD0 = 1 (CS inactive)      GPIOD_PDDR |= GPIO_PDDR_PDD(0x01);       // PTD0 pin is GPIO output          SPI0_C1 = SPI_C1_SPE_MASK | SPI_C1_MSTR_MASK;     // Enable SPI0 module, master mode      SPI0_BR = SPI_BR_SPPR(0x04) | SPI_BR_SPR(0x02);     // BaudRate = BusClock / ((SPPR+1) * 2^(SPR+1)) = 20970000 / ((4+1) * 2^(2+1)) = 524.25 kHz                        //Configure the PTA5 pin (connected to the INT1 of the FXLS8471Q) for falling edge interrupts      SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;       // Turn on clock to Port A module      PORTA_PCR5 |= (0|PORT_PCR_ISF_MASK|      // Clear the interrupt flag                       PORT_PCR_MUX(0x1)|      // PTA5 is configured as GPIO                       PORT_PCR_IRQC(0xA));    // PTA5 is configured for falling edge interrupts                 //Enable PORTA interrupt on NVIC      NVIC_ICPR |= 1 << ((INT_PORTA - 16) % 32);      NVIC_ISER |= 1 << ((INT_PORTA - 16) % 32); } 2. The FXLS8471Q uses the ‘Mode 0′ SPI protocol, which means that an inactive state of clock signal is low and data are captured on the leading edge of clock signal and changed on the falling edge. The falling edge on the SA1/CS_B pin starts the SPI communication. A write operation is initiated by transmitting a 1 for the R/W bit. Then the 8-bit register address, ADDR[7:0] is encoded in the first and second serialized bytes. Data to be written starts in the third serialized byte. The order of the bits is as follows: Byte 0: R/W, ADDR[6], ADDR[5], ADDR[4], ADDR[3], ADDR[2], ADDR[1], ADDR[0] Byte 1: ADDR[7], X, X, X, X, X, X, X Byte 2: DATA[7], DATA[6], DATA[5], DATA[4], DATA[3], DATA[2], DATA[1], DATA[0] The rising edge on the SA1/CS_B pin stops the SPI communication. Below is the write operation which writes the value 0x3D to the CTRL_REG1 (0x3A). Similarly a read operation is initiated by transmitting a 0 for the R/W bit. Then the 8-bit register address, ADDR[7:0] is encoded in the first and second serialized bytes. The data is read from the MISO pin (MSB first). The screenshot below shows the read operation which reads the correct value 0x6A from the WHO_AM_I register (0x0D). Multiple read operations are performed similar to single read except bytes are read in multiples of eight SCLK cycles. The register address is auto incremented so that every eighth next clock edges will latch the MSB of the next register. A burst read of 6 bytes from registers 0x01 to 0x06 is shown below. It also shows how the INT1 pin is automatically cleared by reading the acceleration output data. 3. At the beginning of the initialization, all accelerometer registers should be reset to their default values by setting the RST bit of the CTRL_REG2 register. However, the software reset does not work properly in SPI mode as described in Appendix A of the FXLS8471Q data sheet. Therefore the following piece of the code performing the software reset should not be used. Instead, I have shortened R46 on the FRDM-FXS-MULTI-B board to activate a hardware reset. The dynamic range is set to ±2g and to achieve the highest resolution, the LNOISE bit is set and the lowest ODR (1.56Hz) and the High Resolution mode are selected (more details in AN4075). The DRDY interrupt is enabled and routed to the INT1 interrupt pin that is configured to be a push-pull, active-low output. void FXLS8471Q_Init (void) {      unsigned char reg_val = 0;          /* The software reset does not work properly in SPI mode as described in Appendix A         of the FXLS8471Q data sheet. Therefore the following piece of the code is not used.         I have shortened R46 on the FRDM-FXS-MULTI-B board to activate a hardware reset. */          /*FXLS8471Q_WriteRegister(CTRL_REG2, 0x40);     // Reset all registers to POR values          Pause(0x631);     // ~1ms delay                 do       // Wait for the RST bit to clear      {           reg_val = FXLS8471Q_ReadRegister(CTRL_REG2) & 0x40;      } while (reg_val); */                FXLS8471Q_WriteRegister(XYZ_DATA_CFG_REG, 0x00);          // +/-2g range with ~0.244mg/LSB      FXLS8471Q_WriteRegister(CTRL_REG2, 0x02);            // High Resolution mode      FXLS8471Q_WriteRegister(CTRL_REG3, 0x00);            // Push-pull, active low interrupt      FXLS8471Q_WriteRegister(CTRL_REG4, 0x01);            // Enable DRDY interrupt      FXLS8471Q_WriteRegister(CTRL_REG5, 0x01);            // DRDY interrupt routed to INT1 - PTA5       FXLS8471Q_WriteRegister(CTRL_REG1, 0x3D);            // ODR = 1.56Hz, Reduced noise, Active mode           } 4. A simple offset calibration method is implemented according to the AN4069. void FXLS8471Q_Calibration (void) {      char Xoffset, Yoffset, Zoffset;            DataReady = 0;                while (!DataReady){}      // Is a first set of data ready?      DataReady = 0;            FXLS8471Q_WriteRegister(CTRL_REG1, 0x00);     // Standby mode                   FXLS8471Q_ReadMultiRegisters(OUT_X_MSB_REG, 6, AccData);     // Read data output registers 0x01-0x06                                                      Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2;     // Compute 14-bit X-axis output value      Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2;     // Compute 14-bit Y-axis output value      Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2;     // Compute 14-bit Z-axis output value                                              Xoffset = Xout_14_bit / 8 * (-1);     // Compute X-axis offset correction value      Yoffset = Yout_14_bit / 8 * (-1);     // Compute Y-axis offset correction value      Zoffset = (Zout_14_bit - SENSITIVITY_2G) / 8 * (-1);     // Compute Z-axis offset correction value                                              FXLS8471Q_WriteRegister(OFF_X_REG, Xoffset);                FXLS8471Q_WriteRegister(OFF_Y_REG, Yoffset);         FXLS8471Q_WriteRegister(OFF_Z_REG, Zoffset);                   FXLS8471Q_WriteRegister(CTRL_REG1, 0x3D);     // Active mode again }      5. In the ISR, only the interrupt flag is cleared and the DataReady variable is set to indicate the arrival of new data. void PORTA_IRQHandler() {      PORTA_PCR5 |= PORT_PCR_ISF_MASK;     // Clear the interrupt flag      DataReady = 1;     } 6. The output values from accelerometer registers 0x01 – 0x06 are first converted to signed 14-bit values and afterwards to real values in g’s. if (DataReady)     // Is a new set of data ready? {                  DataReady = 0;                                                                                                                        FXLS8471Q_ReadMultiRegisters(OUT_X_MSB_REG, 6, AccData);     // Read data output registers 0x01-0x06                                                        Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2;     // Compute 14-bit X-axis output value      Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2;     // Compute 14-bit Y-axis output value      Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2;     // Compute 14-bit Z-axis output value                                            Xout_g = ((float) Xout_14_bit) / SENSITIVITY_2G;     // Compute X-axis output value in g's      Yout_g = ((float) Yout_14_bit) / SENSITIVITY_2G;     // Compute Y-axis output value in g's      Zout_g = ((float) Zout_14_bit) / SENSITIVITY_2G;     // Compute Z-axis output value in g's } 7. The calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER 1.4 application and FreeMASTER Communication Driver. Attached you can find the complete source code written in the CW for MCU's v10.5 including the FreeMASTER project. If there are any questions regarding this simple application, please feel free to ask below. Your feedback or suggestions are also welcome. Regards, Tomas
View full article
My friend Matt Muddiman of Freescale gave this presentation as part of the MEMS Education Series (hosted by Arizona Technology Council and MEMS Industry Group) in Scottsdale Arizona earlier this week.
View full article
Hi Everyone, As I am frequently asked for a simple bare metal example code for the Xtrinsic MMA8451Q digital accelerometer, I would like to share here one of my examples I have created for this part while working with the Freescale FRDM-KL25Z platform. This example illustrates: 1. Initialization of the MKL25Z128 MCU (mainly I2C and PORT modules). 2. Initialization of the accelerometer to achieve the highest resolution. 3. Simple offset calibration based on the AN4069. 4. Output data reading using an interrupt technique. 5. Conversion of the output values from registers 0x01 – 0x06 to real acceleration values in g’s. 6. Visualization of the output values in the FreeMASTER tool. 1. According to the schematic, the INT1 output of the MMA8451Q is connected to the PTA14 pin of the KL25Z MCU and both SCL and SDA lines are connected to the I2C0 module (PTE24 and PTE25 pins). The MCU is, therefore, configured as follows: void MCU_Init(void) {      //I2C0 module initialization      SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK;        // Turn on clock to I2C0 module      SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;       // Turn on clock to Port E module      PORTE_PCR24 = PORT_PCR_MUX(5);           // PTE24 pin is I2C0 SCL line      PORTE_PCR25 = PORT_PCR_MUX(5);           // PTE25 pin is I2C0 SDA line      I2C0_F  = 0x14;                          // SDA hold time = 2.125us, SCL start hold time = 4.25us, SCL stop hold time = 5.125us *      I2C0_C1 = I2C_C1_IICEN_MASK;             // Enable I2C0 module           //Configure the PTA14 pin (connected to the INT1 of the MMA8451Q) for falling edge interrupts      SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;       // Turn on clock to Port A module      PORTA_PCR14 |= (0|PORT_PCR_ISF_MASK|     // Clear the interrupt flag                        PORT_PCR_MUX(0x1)|     // PTA14 is configured as GPIO                        PORT_PCR_IRQC(0xA));   // PTA14 is configured for falling edge interrupts           //Enable PORTA interrupt on NVIC      NVIC_ICPR |= 1 << ((INT_PORTA - 16)%32);      NVIC_ISER |= 1 << ((INT_PORTA - 16)%32); } 2. At the beginning of the initialization, all accelerometer registers are reset to their default values by setting the RST bit of the CTRL_REG2 register. The dynamic range is set to ±2g and to achieve the highest resolution, the LNOISE bit is set and the lowest ODR (1.56Hz) and the High Resolution mode are selected (more details in AN4075). void Accelerometer_Init (void) {      unsigned char reg_val = 0;        I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x40);           // Reset all registers to POR values          do            // Wait for the RST bit to clear      {         reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, CTRL_REG2) & 0x40;      }  while (reg_val);        I2C_WriteRegister(MMA845x_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x00);    // +/-2g range -> 1g = 16384/4 = 4096 counts      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x02);           // High Resolution mode      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x3D);           // ODR = 1.56Hz, Reduced noise, Active mode   } 3. A simple offset calibration method is implemented according to the AN4069. At the end of the calibration routine, the DRDY interrupt is enabled and routed to the INT1 interrupt pin that is configured to be a push-pull, active-low output. void Calibrate (void) {      unsigned char reg_val = 0;            while (!reg_val)           // Wait for a first set of data               {         reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, STATUS_REG) & 0x08;      }               I2C_ReadMultiRegisters(MMA845x_I2C_ADDRESS, OUT_X_MSB_REG, 6, AccData);           // Read data output registers 0x01-0x06                                                 Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2;           // Compute 14-bit X-axis output value      Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2;           // Compute 14-bit Y-axis output value      Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2;           // Compute 14-bit Z-axis output value                                          Xoffset = Xout_14_bit / 8 * (-1);        // Compute X-axis offset correction value      Yoffset = Yout_14_bit / 8 * (-1);        // Compute Y-axis offset correction value      Zoffset = (Zout_14_bit - SENSITIVITY_2G) / 8 * (-1);          // Compute Z-axis offset correction value                                          I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x00);             // Standby mode to allow writing to the offset registers       I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_X_REG, Xoffset);              I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Y_REG, Yoffset);       I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Z_REG, Zoffset);       I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG3, 0x00);             // Push-pull, active low interrupt      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG4, 0x01);             // Enable DRDY interrupt      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG5, 0x01);             // DRDY interrupt routed to INT1 - PTA14      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x3D);             // ODR = 1.56Hz, Reduced noise, Active mode  } 4. In the ISR, only the interrupt flag is cleared and the DataReady variable is set to indicate the arrival of new data. void PORTA_IRQHandler() {      PORTA_PCR14 |= PORT_PCR_ISF_MASK;            // Clear the interrupt flag      DataReady = 1;      } 5. The output values from accelerometer registers 0x01 – 0x06 are first converted to signed 14-bit values and afterwards to real values in g’s. if (DataReady)             // Is a new set of data ready? {                 DataReady = 0;                                                                                                                      I2C_ReadMultiRegisters(MMA845x_I2C_ADDRESS, OUT_X_MSB_REG, 6, AccData);           // Read data output registers 0x01-0x06             Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2;           // Compute 14-bit X-axis output value      Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2;           // Compute 14-bit Y-axis output value      Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2;           // Compute 14-bit Z-axis output value                      Xout_g = ((float) Xout_14_bit) / SENSITIVITY_2G;              // Compute X-axis output value in g's      Yout_g = ((float) Yout_14_bit) / SENSITIVITY_2G;              // Compute Y-axis output value in g's      Zout_g = ((float) Zout_14_bit) / SENSITIVITY_2G;              // Compute Z-axis output value in g's                                   } 6. The calculated values can be watched in the "Variables" window on the top right of the Debug perspective or in the FreeMASTER application. To view both the 14-bit and real values in the FreeMASTER application, some USBDM drivers need to be first installed on your computer. They are available for download from SourceForge. Erich Styger described their installation in this tutorial. In addition to that, the USBDM_OpenSDA application that provides both debugging and a virtual serial port needs to be loaded into the MK20 debugger chip on the FRDM-KL25Z board. This installation follows the usual FRDM-KL25Z bootloader process: Unplug the FRDM-KL25Z board. Whilst holding the SW1/RST switch depressed plug in the FRDM-KL25Z board. The green LED should start blinking at a rate of about 1Hz. Open a file explorer and locate the USB drive that has now appeared. It will have the drive name "BOOTLOADER". Drag the file USBDM_OpenSDA.sx to the USB drive and wait a short while. The OpenSDA firmware on the FRDM-KL25Z board will program the USBDM firmware into the MK20 debugger chip on the board. Remove and re-plug the FRDM-KL25Z board. The board will now appear as a USBDM device. Attached you can find the complete source code written in the CW for MCU's v10.5 as well as the FreeMASTER project. So make it, test it and keep in touch... Regards, Tomas
View full article
Video clip associated with "Android as a Platform for Sensor Fusion Education and Evaluation" presented at 2013 Sensors Expo & Conference by Michael Stanley.
View full article
"Android as a Platform for Sensor Fusion Education and Evaluation" presented at 2013 Sensors Expo & Conference by Michael Stanley.
View full article
clicktaleID