Sensors Knowledge Base

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

Sensors Knowledge Base

Discussions

Sort by:
Hi Everyone,   As I am often asked for a simple bare metal example code illustrating the use of the embedded rate threshold detection function, I have decided to share here one of my examples I created for the FXAS21002C gyroscope while working with the NXP FRDM-KL25Z platform and FRDM-FXS-MULT2-B sensor expansion board.   The FXAS21002C is set for detection of an angular rate exceeding 96 dps for a minimum period of 20 ms on either the X or Y axes. Once an event is triggered, an interrupt will be generated on the INT1 pin:   void FXAS21002_Init (void) {     unsigned char reg_val = 0;                 I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1, 0x40);      // Reset all registers to POR values                 Pause(0x631);                                                   // ~1ms delay                             do                                                              // Wait for the RST bit to clear     {         reg_val = I2C_ReadRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1) & 0x40;     }    while (reg_val);                 I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_THS_REG, 0x05);     // Set threshold to 96 dps             I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_COUNT_REG, 0x02);   // Set debounce timer period to 20 ms    I2C_WriteRegister(FXAS21002_I2C_ADDRESS, RT_CFG_REG, 0x0B);     // Enable rate threshold detection for X and Y axis, latch enabled  I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG2, 0x30);      // Rate threshold interrupt enabled and routed to INT1    I2C_WriteRegister(FXAS21002_I2C_ADDRESS, CTRL_REG1, 0x0E);      // ODR = 100 Hz, Active mode    }     In the ISR, only the interrupt flag is cleared and the RT_SRC register (0x0F) is read in order to clear the EA status bit and deassert the INT1 pin, as shown on the screenshot below. 0x4C in the RT_SRC register indicates that the rate threshold event has been detected on the Y-axis and was negative.   void PORTA_IRQHandler() {    PORTA_PCR5 |= PORT_PCR_ISF_MASK;                                   // Clear the interrupt flag     IntSource = I2C_ReadRegister(FXAS21002_I2C_ADDRESS, RT_SRC_REG);   // Read the RT_SRC register to clear the EA flag and deassert the INT1 pin EventCounter++;       }       Attached you can find the complete source code. If there are any questions regarding this simple example code, please feel free to ask below. Your feedback or suggestions are also welcome.   Regards, Tomas Original Attachment has been moved to: FRDM-KL25Z-FXAS21002-Angular-rate-detection-using-interrupts.rar
View full article
Hello community, This time, I would like to share a simple bare metal example code using the MAG3110 , the digital Magnetometer from NXP. I created this example code with the FRDM-KL25Z  platform and the FRDM-FXS-MULT2-B sensor expansion board. The complete source code is written in the Kinetis Design Studio V3.2.0  in collaboration with the FreeMASTER  tool in order to visualize the magnetic data. This document guides you through the initialization process and how to appreciate the demonstration. Section 1: Initialization of the MKL25Z128 MCU. Section 2: Initialization of the MAG3110. Section 3: Simple magnetic hard-iron offset calibration. Section 4: Output data reading using an interrupt technique. Section 5: Conversion of the output values. Section 6: FreeMASTER tool. 1. Initialization of the MKL25Z128 MCU Based on the figure below, the SCL and SDA signals, from the I2C Module, are connected to the PTC1 and PTC2 pins respectively. The INT1 output of the MAG3110 is connected to the PTD4 pin of the KL25Z. Please make sure the 2&3 pins of the J3 are connected together using a jumper at the FRDM-FXS-MULT2-B. The RGB LED from the FRDM-KL25Z is also set using the PTB18 and PTB19 pins as GPIOs. //I2C1 module initialization SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK;         // Turn on clock to I2C0 module SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;        // Turn on clock to Port C module PORTC_PCR1 = PORT_PCR_MUX(2);             // PTC1 pin is I2C0 SCL line PORTC_PCR2 = PORT_PCR_MUX(2);             // PTC2 pin is I2C0 SDA line I2C1_F  = 0x14;                           // SDA hold time = 2.125us, SCL start hold time = 4.25us, SCL stop hold time = 5.125us I2C1_C1 = I2C_C1_IICEN_MASK;              // Enable I2C0 module //Configure the PTD4 pin (connected to the INT1 of the MAG3110) for rising edge interrupts SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;        // Turn on clock to Port D module PORTD_PCR4  |= (0|PORT_PCR_ISF_MASK|      // Clear the interrupt flag                   PORT_PCR_MUX(0x1)|      // PTD4 is configured as GPIO                   PORT_PCR_IRQC(0x09));   // PTD4 is configured for rising edge interrupts (MAG3110 generates low to high signal) //Configure RGB LED SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;        // Turn on clock to Port B module PORTB_PCR19 = PORT_PCR_MUX(1);            // PTB19 is configured as GPIO GPIOB_PDDR |= (1 << 19);                  // Configure pin as output GPIOB_PSOR |= (1 << 19);                  // Turn OFF GREEN LED PORTB_PCR18 = PORT_PCR_MUX(1);            // PTB18 is configured as GPIO GPIOB_PDDR |= (1 << 18);                  // Configure pin as output GPIOB_PCOR |= (1 << 18);                  // Turn ON RED LED //Enable PORTD interrupt on NVIC NVIC_EnableIRQ(PORTD_IRQn);               // Enable interrupts NVIC_ClearPendingIRQ(PORTD_IRQn);         // Clear pending interrupts ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 2. Initialization of the MAG3110 The MAG3110 is capable of measuring magnetic fields with an output data rate (ODR) up to 80 Hz. In this case, the ODR of the MAG3110 is set at 20Hz. The automatic resets are enabled. When new measurement data is available, the INT1 pin triggers a software interrupt. The WHO_AM_I register is read in order to verify the correct communication with the magnetometer. I2C_WriteRegister(MAG3110_I2C_ADDRESS, CTRL_REG2, 0x80);  // Enable automatic resets WhoAmI = I2C_ReadRegister(MAG3110_I2C_ADDRESS, WHO_AM_I); // Read WHO_AM_I Register I2C_WriteRegister(MAG3110_I2C_ADDRESS, CTRL_REG1, 0x11);  // ODR 20Hz (0.05s), Active mode ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 3. Simple magnetic hard-iron offset calibration. Please note that the magnetometer readings must be corrected for Hard-Iron and Soft-Iron effects. If you are interested in more complex algorithms you may refer to the NXP E-Compass Software. As an alternative, a method to calibrate the hard iron offset is rotating the MAG3110 in a figure of eight twisting motions for a few seconds, record the minimum and maximum magnetometer readings, compute the corresponding offset values by using the min/max averaging and then either subtract these offset values from the current magnetometer measurements or write them in the user offset registers with CTRL_REG2[RAW] = 0. The hard iron offset calibration is done as follow: short Xout_16_bit_avg, Yout_16_bit_avg, Zout_16_bit_avg; short Xout_16_bit_max, Yout_16_bit_max, Zout_16_bit_max; short Xout_16_bit_min, Yout_16_bit_min, Zout_16_bit_min; short i=0; while (i < 200) // Calibration process ~10s (200 samples * 1/20Hz) {     if (DataReady)         {             DataReady= 0;             I2C_ReadMultiRegisters(MAG3110_I2C_ADDRESS, OUT_X_MSB, 6, MagData);        // Read data output registers 0x01-0x06             Xout_16_bit = ((short) (MagData[0]<<8 | MagData[1]));        // Compute 16-bit X-axis output value             Yout_16_bit = ((short) (MagData[2]<<8 | MagData[3]));        // Compute 16-bit Y-axis output value             Zout_16_bit = ((short) (MagData[4]<<8 | MagData[5]));        // Compute 16-bit Z-axis output value             if (i == 0)             {                 Xout_16_bit_max = Xout_16_bit;                 Xout_16_bit_min = Xout_16_bit;                 Yout_16_bit_max = Yout_16_bit;                 Yout_16_bit_min = Yout_16_bit;                 Zout_16_bit_max = Zout_16_bit;                 Zout_16_bit_min = Zout_16_bit;             }             // Check to see if current sample is the maximum or minimum X-axis value             if (Xout_16_bit > Xout_16_bit_max) {Xout_16_bit_max = Xout_16_bit;}             if (Xout_16_bit < Xout_16_bit_min) {Xout_16_bit_min = Xout_16_bit;}             // Check to see if current sample is the maximum or minimum X-axis value             if (Yout_16_bit > Yout_16_bit_max) {Yout_16_bit_max = Yout_16_bit;}             if (Yout_16_bit < Yout_16_bit_min) {Yout_16_bit_min = Yout_16_bit;}             // Check to see if current sample is the maximum or minimum X-axis value             if (Zout_16_bit > Zout_16_bit_max) {Zout_16_bit_max = Zout_16_bit;}             if (Zout_16_bit < Zout_16_bit_min) {Zout_16_bit_min = Zout_16_bit;}             i++;         } } Xout_16_bit_avg = (Xout_16_bit_max + Xout_16_bit_min) / 2;    // X-axis hard-iron offset Yout_16_bit_avg = (Yout_16_bit_max + Yout_16_bit_min) / 2;    // Y-axis hard-iron offset Zout_16_bit_avg = (Zout_16_bit_max + Zout_16_bit_min) / 2;    // Z-axis hard-iron offset // Left-shift by one as magnetometer offset registers are 15-bit only, left justified Xout_16_bit_avg <<= 1; Yout_16_bit_avg <<= 1; Zout_16_bit_avg <<= 1; I2C_WriteRegister(MAG3110_I2C_ADDRESS, CTRL_REG1, 0x00);  // Standby mode // Set Offset I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_X_LSB, (char)(Xout_16_bit_avg & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_X_MSB, (char)((Xout_16_bit_avg >>8) & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_Y_LSB, (char)(Yout_16_bit_avg & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_Y_MSB, (char)((Yout_16_bit_avg >>8) & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_Z_LSB, (char)(Zout_16_bit_avg & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, OFF_Z_MSB, (char)((Zout_16_bit_avg >>8) & 0xFF)); I2C_WriteRegister(MAG3110_I2C_ADDRESS, CTRL_REG1, 0x11);  //  Active mode again ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 4. Output data reading using an interrupt technique. At the ISR, the interrupt flag is clear and the DataReady variable is set in order to know that a new magnetic measurement is ready. void PORTD_IRQHandler() {     PORTD_PCR4 |= PORT_PCR_ISF_MASK;            // Clear the interrupt flag     DataReady= 1; } ‍‍‍‍‍‍‍‍‍‍‍ 5. Conversion of the output values The output values from magnetometer are converted to signed 16-bit integer values and afterwards to real values in microtesla (µT). for(;;){    if (DataReady)    {            DataReady= 0;            I2C_ReadMultiRegisters(MAG3110_I2C_ADDRESS, OUT_X_MSB, 6, MagData);        // Read data output registers 0x01-0x06            // 16-bit magnetometer data            Xout_16_bit = ((short) (MagData[0]<<8 | MagData[1]));        // Compute 16-bit X-axis output value            Yout_16_bit = ((short) (MagData[2]<<8 | MagData[3]));        // Compute 16-bit Y-axis output value            Zout_16_bit = ((short) (MagData[4]<<8 | MagData[5]));        // Compute 16-bit Z-axis output value            // Magnetometer data converted to microteslas           Xout_uT = (float)Xout_16_bit / SENSITIVITY;     // Compute X-axis output magnetic value in uT            Yout_uT = (float)Yout_16_bit / SENSITIVITY;     // Compute Y-axis output magnetic value in uT           Zout_uT = (float)Zout_16_bit / SENSITIVITY;     // Compute Z-axis output magnetic value in uT    } }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 6. FreeMASTER FreeMASTER is a user-friendly real-time debug monitor and data visualization tool that you can use for any application development and information management. In this case, it is used in order to visualize the magnetic data. In case you have problems with the communication port, please go to Project / Options… Select Plug-in Module and choose the FreeMASTER BDM Communication Plug-in option. Select configure and make sure the P&E Kinetis is selected. Select OK and Start the communication. Please find attached the complete source code, including the FreeMASTER project. You are invited to take part of the NXP community where you can post all your questions and you may find useful material for your projects. I hope you find useful and funny this sample project. Any suggestion will be appreciated. Best Regards, David
View full article
Hi Everyone, In this document I would like to present a simple example code I created for the FRDMKL25-P3115 kit using the KDS 3.0.2 and KSDK 2.0. I will not cover the Sensor Toolbox – CE and Intelligent Sensing Framework (ISF) which primarily support this kit. The FreeMASTER tool is used to visualize both the pressure/altitude and temperature data that are read from the MPL3115A2 using an interrupt technique through the I 2 C interface. This example illustrates: 1. Initialization of the MKL25Z128 MCU (mainly PORT and I 2 C modules). 2. I 2 C data write and read operations. 3. Initialization of the MPL3115A2. 4. Output data reading using an interrupt technique. 5. Conversion of the output values from registers 0x01 – 0x05 to real values in Pascals/meters and °C 6. Visualization of the calculated values in the FreeMASTER tool. 1. As you can see in the FRDMSTBC-P3115 schematic and the image below, with jumpers J7 and J8 in their default position (2-3), the I 2 C signals are routed to the I2C1 module (PTC1 and PTC2 pins) of the KL25Z MCU. The INT1 output is connected to the PTA5 pin and configured as push-pull active-low output, so the corresponding PTA5 pin configuration is GPIO with an interrupt on falling edge. The configuration is done in the BOARD_InitPins() function. void BOARD_InitPins(void) {     CLOCK_EnableClock(kCLOCK_PortC);                                            /* Port C Clock Gate Control: Clock enabled */     CLOCK_EnableClock(kCLOCK_I2c1);                                             /* I2C1 Clock Gate Control: Clock enabled */     PORT_SetPinMux(PORTC, PIN1_IDX, kPORT_MuxAlt2);                             /* PORTC1 (pin 56) is configured as I2C1_SCL */     PORT_SetPinMux(PORTC, PIN2_IDX, kPORT_MuxAlt2);                             /* PORTC2 (pin 57) is configured as I2C1_SDA */     CLOCK_EnableClock(kCLOCK_PortA);                                            /* Port A Clock Gate Control: Clock enabled */     PORT_SetPinMux(PORTA, PIN5_IDX, kPORT_MuxAsGpio);                           /* PORTA5 (pin 31) is configured as PTA5 */     PORT_SetPinInterruptConfig(PORTA, PIN5_IDX, kPORT_InterruptFallingEdge);    /* PTA5 is configured for falling edge interrupts */     NVIC_EnableIRQ(PORTA_IRQn);                                                 /* Enable PORTA interrupt on NVIC */ } 2. The 7-bit I 2 C address of the MPL3115A2 is a fixed value 0x60 (defined in the MPL3115A2.h file) which translates to 0xC0 for a write and 0xC1 for a read. As mentioned before, the SCL line is connected to the PTC1 pin and SDA line to the PTC2 pin. The I 2 C clock frequency is 100 kHz. The I2C_Init() function is used to enable and configure the I2C1 module. void I2C_Init(void) {     i2c_master_config_t config = {     .enableMaster = true,     .enableStopHold = false,     .enableHighDrive = false,     .baudRate_Bps = 100000,     .glitchFilterWidth = 0      };     I2C_MasterInit(I2C1, &config, 24000000U);     I2C_MasterTransferCreateHandle(I2C1, &p_handle, i2c_master_callback, NULL); } The screenshot below shows the write operation which writes the value 0x39 to the CTRL_REG1 register (0x26). Here is a burst read of 5 bytes from registers 0x01 to 0x05. It also shows how the INT1 pin is automatically deasserted by reading the output registers. 3. At the beginning of the initialization, all MPL3115A2 registers are reset to their default values by setting the RST bit of the CTRL_REG1 register. The DRDY interrupt is enabled and routed to the INT1 pin that is configured to be a push-pull, active-low output. Further, the OSR ratio of 128 is selected and finally the part goes into Active barometer (eventually altimeter) mode. void MPL3115A2_Init (void) {     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x04);               /* Reset all registers to POR values */     Pause(0xC62);          // ~1ms delay     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, PT_DATA_CFG_REG, 0x07);         /* Enable data flags */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG3, 0x00);               /* Push-pull, active low interrupt */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG4, 0x80);               /* Enable DRDY interrupt */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG5, 0x80);               /* DRDY interrupt routed to INT1 - PTA13 */     I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0x39);               /* Active barometer mode, OSR = 128 */     //I2C_WriteRegister(I2C1, MPL3115A2_I2C_ADDRESS, CTRL_REG1, 0xB9);             /* Active altimeter mode, OSR = 128 */ } 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(void) {     PORT_ClearPinsInterruptFlags(PORTA, 1<<5);                /* Clear the interrupt flag */     DataReady = 1; } 5. In the main loop, the DataReady variable is periodically checked and if it is set, both pressure (eventually altitude) and temperature data are read and then calculated. if (DataReady)                  /* Is a new set of data ready? */ {     DataReady = 0;     I2C_ReadMultiRegisters(I2C1, MPL3115A2_I2C_ADDRESS, OUT_P_MSB_REG, RawData, 5);                      /* Read data output registers 0x01-0x05 */     /* Get pressure, the 20-bit measurement in Pascals is comprised of an unsigned integer component and a fractional component.     The unsigned 18-bit integer component is located in OUT_P_MSB, OUT_P_CSB and bits 7-6 of OUT_P_LSB.     The fractional component is located in bits 5-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are not used. */     Pressure = (float) (((RawData[0] << 16) | (RawData[1] << 8) | (RawData[2] & 0xC0)) >> 6) + (float) ((RawData[2] & 0x30) >> 4) * 0.25;     /* Get temperature, the 12-bit temperature measurement in °C is comprised of a signed integer component and a fractional component.     The signed 8-bit integer component is located in OUT_T_MSB. The fractional component is located in bits 7-4 of OUT_T_LSB.     Bits 3-0 of OUT_T_LSB are not used. */     Temperature = (float) ((short)((RawData[3] << 8) | (RawData[4] & 0xF0)) >> 4) * 0.0625;     /* Get altitude, the 20-bit measurement in meters is comprised of a signed integer component and a fractional component.     The signed 16-bit integer component is located in OUT_P_MSB and OUT_P_CSB.     The fraction component is located in bits 7-4 of OUT_P_LSB. Bits 3-0 of OUT_P_LSB are not used */     //Altitude = (float) ((short) ((RawData[0] << 8) | RawData[1])) + (float) (RawData[2] >> 4) * 0.0625; } 6.  The calculated values can be watched in the Debug perspective or in the FreeMASTER application. To open and run the FreeMASTER project, install the FreeMASTER 2.0 application and FreeMASTER Communication Driver. Attached you can find the complete source code written in the KDS 3.0.2 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. Best regards, Tomas
View full article
The FRDM33772BSPIEVB serves as a 6-channel and FRDM33771BSPIVB as a 14 channel battery cell controller with a passive cell balancing. A FRDM-KL25Z evaluation board is used for communication with FRDM3377xBSPIEVB and a computer through SPI interface. The kit together with BATT-6EMULATOR 6-cell battery emulator  for the FRDM33772BSPIEVB and BATT-14EMULATOR 14-cell battery emulator for FRDM33771BSPIVB or a battery pack BATT-14AAAPACK for either of them is dedicated to support customer development and evaluation. For a status reading and settings an MC3377x EvalGUI is used. Figure 1. FRDM33771SPI evaluation board Figure 2. BATT-14AAAPACK battery pack Figure 3. BATT-14EMULATOR to supply MC33771 EVBs MC3377x EvalGUI The Graphic User Interface MC3377x EvalGUI is intended to use for evaluation of MC3377x cell controllers. Figure 4. MC3377x Evaluation GUI version 4.02 Hardware setup The GUI supports two types of BMS architectures. Central, only one cluster and distributed, up to 15 clusters. For the central BMS architecture an MC33771 EVB or MC33772 EVB must be stacked on top of an FRDM-KL25Z board. One of the battery emulators or the battery pack is connected through a 34-pin cells connector. For the distributed BMS architecture a MC33664 evaluation board stacked on top of a FRDM-KL25Z is used. The MC3377x evaluation boards are connected to the MC33664 EVB through a twisted pair TPL bus. Connection to a computer is made through OpenSDA port on FRDM-KL25Z and USB on the computer side. Figure 5. FRDM-33771SPIEVB stacked on top of FRDM-KL25Z and BATT-14AAAPACK connected as central BMS architecture After hardware setup is done start the MC3377x EvalGUI and follow instructions for Initial Configuration in MC33771/772 Evaluation GUI Documentation. For access click info->Open docu in MC33771/772 Evaluation GUI. Figure 6. Access to MC33771/772 Evaluation GUI document When the initial configuration is done, voltage reading of every battery cell and overall voltage of all connected batteries in series is enabled. However current measurement is disabled by default. Figure 7. Battery cells measurement with current measurement disabled Enablement of current measurement is done in Cluster view by setting a Bit9 (IMeasEn) in in SYS_CFG1 register to logic 1. The field changes from dark green to  light green and the current measurement is enabled. Figure 8. Enablement of the current measurement Figure 9. Current measurement enabled Current in the GUI is displayed in mV and for the current consumption has to be calculated. Because shunt resistor is Rshunt=100mΩ and measured voltage 1.243mV, thus for this case the current consumption is I=Ushunt/Rshunt = 12.43mA. The shunt resistor has to be chosen so the voltage doesn’t exceed +/-150mV. The voltage is sensed on SENSE_P and SENSE_N pins of the MC3377x controller. Figure 10. Shunt resistor R1 on the BATT-14AAAPACK It’s also possible to use a resistor in the battery pack as a load. The resistor is not populated. Recommended value is 1kΩ, 3W , SMT 2512. The resistor can be connected and disconnected with SW3 switch. Figure 11. Recommended load resistor R7 and toggle switch SW3
View full article
************************************************************************************************************* * This simple example code has been written for the NXP FRDM-KL25Z + FRDMSTBC-A8471 * boards and demonstrates how to use the embedded transient detection function * in conjunction with the auto-wake/sleep mode for reducing current consumption * of the FXLS8471Q. * * The transient threshold is set to 312.5mg (5 counts) on the X and Y axis. * Once this threshold is exceeded, the FXLS8471Q is waken up and an interrupt * is generated on the INT1 pin. If the acceleration is below this threshold * within the 1s period, the FXLS8471Q goes back to sleep mode and also * generates an interrupt on the INT1 pin. *************************************************************************************************************
View full article
This time, I would like to share with you an example project using the MPL115A1, the NXP digital barometer.   The MPL115A1 is a simple barometer with digital output for cost-effective applications. It employs a MEMS pressure sensor with a conditioning integrated circuit to provide accurate pressure data. An integrated analog-to-digital converter (ADC) provides digitized temperature and pressure sensor outputs via serial peripheral interface (SPI), with bus speeds up to 8 Mbps.   You may find more information at: MPL115A: 50 to 115kPa, Absolute Digital Pressure Sensor.   I created this project using the FRDM-KL25Z platform and the MPL115A1 absolute digital pressure sensor. The complete source code is written in KDS IDE. You may find the complete project attached to this post.   This document gives you an introduction of the MPL115A1 pressure sensor as well as the different configurations and guides you through the initialization process and how to appreciate the demonstration.   Introduction to the example project This example is based on the application note AN3785 -How to Implement the Freescale MPL115A Digital Barometer. I recommend using it as a reference.   Through this example project, the MCU is configured to use the SPI interface and the PIT module. The local pressure is read every second.   There are MPL115A1 SPI commands to read coefficients, execute Pressure and Temperature conversions, and to read Pressure and Temperature data. The sequence of the commands for the interaction is given as an example to operate the MPL115A1. Initialization of the MKL25Z128 MCU.   Sequence flow chart. The MPL115A1 interfaces to a host (or system) microcontroller in the user’s application. All communications are via SPI. A typical usage sequence is as follows: Every stage of the flow chart is applied on this example and explained below.   Reading coefficient data These are MPL115A2 SPI commands to read coefficients. The coefficients are usually stored in the host microcontoller local memory but can be re-read at any time.   Reading of the coefficients may be executed only once and the values stored in the host microcontroller. It is not necessary to read this multiple times because the coefficients within a device are constant and do not change.   Read Coefficients: [CS=0], [0x88], [0x00], [0x8A], [0x00], [0x8C], [0x00], [0x8E], [0x00], [0x90], [0x00], [0x92], [0x00], [0x94], [0x00], [0x96], [0x00], [0x00], [CS=1] Once the coefficients are obtained, they are computed inside the MPL115A1_Read_Preassure function.     Data conversion This is the MPL115A2 SPI commands to start conversion.   This is the first step that is performed each time a new pressure reading is required which is initiated by the host sending the CONVERT command. The main system circuits are activated (wake) in response to the command and after the conversion completes, the result is placed into the Pressure and Temperature ADC output registers.   Start conversion: [CS=0], [0x24], [0x00], [CS=1], [13 ms Delay]     This is the MPL115A2 SPI commands to read raw temperature and pressure data.     Start Read raw data: [CS=0], [0x80], [0x00], [0x82], [0x00], [0x84], [0x00,] [0x86], [0x00], [0x00], [CS=1]   Compensated pressure reading Once the raw rata is obtained, the compensation procedure is applied as follow:     Local pressure   Once the steps mentioned above are followed, the MPL115A1_Read_Preassure function returns the local pressure value into the local_pressure variable. I recommend evaluating this variable in order to know the final result.     I hope you find the information useful and funny.   Regards, David  
View full article
Posted here in response to a query by Michael Smorto. Regards, Mike Stanley
View full article
Hi Everyone, In my previous tutorial, I demonstrated how to import an ISSDK based example project into MCUXpresso IDE, build and run it on the Freedom board (FRDM-KL27Z). If you want to visualize/log sensor data, easily change sensor settings (ODR, Range, Power Mode) or directly read and write sensor registers, you can use the Freedom Sensor Toolbox-Community Edition (STB-CE) as described below or in the STBCEUG. 1. Connect the SDA port (J13) on the FRDM-KL27Z board to a USB port on your computer. 2. Open STB-CE GUI by double clicking the Freedom Sensor Toolbox (CE) shortcut located on your desktop. 3. Select "Out of Box Sensor Demonstration". 4. Select the Project to be launched and click on Continue. Base Board Name – FRDM-KL27Z Shield Board Name – OnBoard Project Name – MMA8451 Accelerometer Demo 5. The ISSDK-based MMA8451 Accelerometer Demo firmware is loaded to the KL27Z MCU and the MMA8451 Accelerometer Demo v1.0 GUI launched. 6. In the Main screen you can change basic MMA8451Q accelerometer settings (ODR, Range, Power Mode), enable embedded functions (Landsacpe/Portrait, Pulse/Tap, Freefall, Transient), start/stop accelerometer data streaming and/or logging.   7. The Register screen (MMA8451) provides low-level access (R/W) to the MMA8451Q registers along with a detailed description of the selected register. 8. To change the bit value, simply click on the corresponding cell (make sure you selected the Standby mode before writing a new value to the selected register). I hope you find this simple document useful. f there are any questions, please feel free to ask below.  Regards, Tomas
View full article
Hi Everyone, This tutorial is a detailed guide on how to import an ISSDK based example project (e.g. mma845x_interrupt) into MCUXpresso IDE, build and run it on the Freedom board (e.g. FRDM-KL27Z). If you intend to use another ISSDK example project/board, you can always follow this guide. A complete list of MCU boards, sensor kits and sensors supported by ISSDK is available in the ISSDK Release notes. 1. Download the FRDM-KL27Z SDK Open a web browser, navigate to the MCUXpresso homepage and select “Login to view configurations” to start a new configuration. You will be redirected to login to nxp.com. Enter your account information or register for a new account. Back on the MCUXpresso homepage, select the drop-down box to create a New Configuration. Select the board (FRDM-KL27Z) from the list and provide a name for the configuration. Select “Specify Additional Configuration Settings” to choose the Host OS, Toolchain (MCUXpresso IDE) and Middleware (ISSDK). Select Configuration Settings: Host OS (example: Windows) Toolchain/IDE (MCUXpresso IDE) Middleware (ISSDK) Once the configurations are set, select “Go to SDK Builder”.   Select “Request Build” to download the SDK. Once the build request is completed, download the SDK. Agree to Software Terms and Conditions. Unzip SDK to a folder (e.g. SDK_2.2.1_FRDM-KL27Z). 2. Import the SDK_2.1.1_FRDM-KL27Z into MCUXpresso IDE Open MCUXpresso IDE. Set the workspace directory of your choice and click on OK. Switch to the Installed SDKs view within the MCUXpresso IDE window. Open Windows Explorer, and drag and drop the SDK_2.2.1_FRDM-KL27Z (unzipped) file into the installed SDKs view. You will get the following pop-up so click on OK to continue the import.   The installed SDK will appear in the Installed SDKs view. 3. Import and build the ISSDK based mma845x_interrupt example project Find the Quickstart Panel in the lower left hand corner and select Import SDK example(s) Click on the FRDM-KL27Z board and then click on Next. Use the arrow button to expand the issdk_examples category, and then click the checkbox next to mma845x_interrupt to select that project. Then, click on Next. On the next screen, click the checkbox to Redirect printf/scanf to UART so that the terminal output gets sent out the UART instead of using semi-hosting through the debugger. Then click on Finish. Now build the project by clicking on the project name in the Project Explorer view and then click on the Build icon in the Quickstart Panel. You can see the status of the build in the Console view. 4. Run the mma845x_interrupt example project   Now that the project has been compiled, we can flash it to the board and run it. Make sure the FRDM-KL27Z board is plugged in, and click on Debug ‘frdmkl27z_issdk_examples_sensors_mma8451q_mma845x_interrupt’ [Debug] MCUXpresso will probe for connected boards and should find the OpenSDA debug probe that is part of the integrated OpenSDA circuit on the FRDM-KL27Z board. Click on OK to continue. The firmware will be downloaded to the board and the debugger started. Open a Terminal program (e.g. Tera Term) and connect to the FRDM-KL27Z COM port that it enumerated as. Use 115200 baud, 8 data, 1 stop, no parity. Start the application in the MCUXpresso IDE by clicking the "Resume" button. The application is now running and signed 14-bit accelerometer output values are displayed on the terminal. To modify the initial register settings of the MMA8451 accelerometer, find the mma845x_Config_Isr[] structure and change it according to your needs. Well done if you managed to follow along and get it all working. If there are any questions, do not hesitate to ask below. Your feedback or suggestions are also welcome. Regards, Tomas
View full article
This is a standalone project generated via the Kinetis Project Generator tool for SF Version 7.1 operating on K64F/MULT2B shield with FreeRTOS.
View full article
Attached is an LPCExpresso project for LPC1549.  It is compatible with the latest version of the Sensor Fusion Toolbox for Windows (the version targeted at Version 6.00 and 7.00 sensor fusion).  This project is a variant on the Sensor Fusion Version 6.00 library.  Algorithmically this is virtually identical to Version 7.00.
View full article
All, Drop the attached into SDK_2.0_FRDM-KL25Z/boards/frdmkl25z_virtual_shield/issdk_examples/algorithms/sensorfusion/baremetal_sensor_fusion. Apologies for both the delay in posting and the fact that even though I thought I was linking to files elsewhere in the system, I ended up getting local copies built into this project.  Some of you may like that.  I don't particularly.  But as I've noted elsewhere, KDS and I have our differences... Regards, Mike
View full article
All, The attached was put together in response to the posting by Andrew Hartnett.  It contains a bare-metal IAR project for 9-axis sensor fusion V7.00 on the KL25Z.  You need to have built KSDK for the KL25Z to include the ISSDK option.  Then unzip this file into your SDK_2.0_FRDM-KL25Z/boards directory.  The sample project is then located at SDK_2.0_FRDM-KL25Z/boards/frdmkl25z_virtual_shield/issdk_examples/algorithms/sensorfusion/baremetal_sensor_fusion/iar. There is also an included freertos_sensor_fusion project.  Ignore that for now.  It compiles and links, but needs more RAM than the KL25Z supplies.  I'm looking at ways to decrease the RAM requirements to fit. Regards, Mike
View full article
This this shows how to implement the power cycling feature described in Section 4.8, Fusion Standby mode, of the Version 7.00 Sensor Fusion User Guide.  It will power down the gyro when the board is stationary, and also suspend sensor fusion.   Last computed results continue to be sent until new motion is detected.  One nice side effect is that 6-axis yaw drift is almost eliminated.
View full article
Here's a zip file which incorporates the patch I outlined in my previous posting.
View full article
Hello Community,   One of the main features of the NXP accelerometers is the Auto-WAKE/SLEEP mode.   I would like to share this project in order to demonstrate the feasibility of using the Low-power and auto-WAKE/SLEEP modes for reducing current consumption in the different NXP accelerometers such as the MMA845x and MMA865x series.   I created this project using the FRDM-KL25Z platform and the MMA8652FC accelerometer (You may find the breakout board files here). The complete source code is written in CodeWarrior v10.x IDE.   This document gives you an introduction of the MMA8652FC accelerometer as well as the different power consumptions and guides you through the initialization process and how to appreciate the demonstration:   Initialization of the MKL25Z128 MCU. Initialization of the MMA8652FC. Auto-WAKE/SLEEP mode. MMA8652FC Embedded functions. Interrupt handlers. Evaluation of the interrupt source. Summarizing the application and Macros definition. Visualization of the current consumption.   1. As you can see in the FRDM-KL25Z schematic and the image below, the I2C signals are routed to the I2C1 module (PTC1 and PTC2 pins) of the KL25Z MCU and the INT1 and INT2 outputs are connected to the PTD5 and PTA5 pins. The INT1 and INT2 outputs of the MMA8652FC are configured as a push-pull active-low outputs, so the corresponding PTD5 and PTA5 pins configuration are GPIOs with an interrupt on falling edge.   The MCU is, therefore, configured as follows:          /* I2C1 module initialization */      SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK;        // Turn on clock to I2C1 module      SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;       // Turn on clock to Port C module      PORTC_PCR1 |= PORT_PCR_MUX(0x2);         // PTC1 pin is I2C1 SCL line      PORTC_PCR2 |= PORT_PCR_MUX(0x2);         // PTC2 pin is I2C1 SDA line      I2C1_F  |= I2C_F_ICR(0x14);              // SDA hold time = 2.125us, SCL start hold time = 4.25us, SCL stop hold time = 5.125us      I2C1_C1 |= I2C_C1_IICEN_MASK;            // Enable I2C1 module        /*Configure the PTD5 and PTA5 pin (connected to the INT1 and INT2 of the MMA8652FC) for falling edge interrupts */      SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;       // Turn on clock to Port D module      PORTD_PCR5 |= (0|PORT_PCR_ISF_MASK|      // Clear the interrupt flag                           PORT_PCR_MUX(0x1)|  // PTD5 is configured as GPIO                           PORT_PCR_IRQC(0xA));// PTD5 is configured 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 PORTD interrupt on NVIC */      NVIC_ICPR |= 1 << ((INT_PORTD - 16)%32);      NVIC_ISER |= 1 << ((INT_PORTD - 16)%32);      /* Enable PORTA interrupt on NVIC */      NVIC_ICPR |= 1 << ((INT_PORTA - 16)%32);      NVIC_ISER |= 1 << ((INT_PORTA - 16)%32);     2. The MMA8652FC is an intelligent, low-power, three-axis, capacitive micromachined accelerometer with 12 bits of resolution.   At the beginning of the initialization, all registers are reset to their default values by setting the RST bit of the CTRL_REG2 register. The Normal and Low Power modes are set in the same register. The MODS[1:0] bits select which Oversampling mode is to be used. The Oversampling modes are available in both WAKE Mode MOD[1:0] and also in the SLEEP Mode SMOD[1:0].   Then the MMA8652FC is initialized as shown below:        I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, 0x40);        // Reset all registers to POR values      Pause(0x631);        // ~1ms delay      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x00); // +/-2g range with ~0.977mg/LSB              /* Power Mode Configuration */      If LOW power mode is selected:      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, 0x1B);        // Low Power mode        If NORMAL power mode is selected:      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, 0x00);        // Normal mode     3. As I mentioned, one of the main features of the MMA8652FC is the Auto-WAKE/SLEEP mode.   The advantage of using the Auto-WAKE/SLEEP is that the system can automatically transition to a higher sample rate (higher current consumption) when needed, but spends the majority of the time in the SLEEP mode (lower current) when the device does not require higher sampling rates.   • Auto-WAKE refers to the device being triggered by one of the interrupt functions to transition to a higher sample rate. This may also interrupt the processor to transition from a SLEEP mode to a higher power mode. • SLEEP mode occurs after the accelerometer has not detected an interrupt for longer than the user-definable timeout period.       At the ASLP_COUNT register, you can set the minimum time period of inactivity required to switch the part between Wake and Sleep status, in this case, 5 seconds.   The Auto-WAKE/SLEEP mode, therefore, is configured as follow:        read_reg = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2);      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, read_reg|0x04);  // Auto-SLEEP enable      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, ASLP_COUNT_REG, 0x10);      // 5 seconds (16 * 320ms)      read_reg = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG4);      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG4, read_reg|0x80);  // Enable AutoSleep interrupt, INT2 - PTD5      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG1, 0xC1);           // ODR=800Hz and Sleep mode ODR=1.56Hz, Active mode     4. The device can be configured to generate inertial wake-up interrupt signals from any combination of the configurable embedded functions, enabling the MMA8652FC to monitor inertial events while remaining in a low-power mode during periods of inactivity.   The Interrupts that can WAKE the device from SLEEP are: Tap Detection, Orientation Detection, Motion/Freefall, and Transient Detection.       In this project, the TAP (Pulse) or Transient interrupts are used to wake up the device from the SLEEP. In order to get more information about the TAP detection, please click here.   The MMA8652FC is configured as below:        If Transient interrupt is selected:      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, TRANSIENT_THS_REG, 0x84);         // Set threshold to 252mg (4 x 63mg )      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, TRANSIENT_COUNT_REG, 0x02);       // Set debounce timer period to 40ms (low power mode) / 2.5ms (normal mode)-Table 66      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, TRANSIENT_CFG_REG, 0x17);         // Enable transient detection for X and Y axis, latch enabled         I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG3, 0x40);                 // Wake from Transient interrupt, Push-pull, active low interrupt      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG4, 0x20);                 // Enable Transient detection interrupt      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG5, 0x20);                 // Transient interrupt routed to INT1 - PTA5          If TAP interrupt is selected:      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_CFG_REG, 0x15);             // Enable X, Y and Z Single Pulse      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_THSX_REG, 0x20);            // Set X Threshold to 2.016g      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_THSY_REG, 0x20);            // Set Y Threshold to 2.016g      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_THSZ_REG, 0x2A);            // Set Z Threshold to 2.646g      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_TMLT_REG, 0x28);            // Set Time Limit for Tap Detection to 25 ms      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, PULSE_LTCY_REG, 0x28);            // Set Latency Time to 50 ms. During this time interval, all pulses are ignored          I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG3, 0x10);                 // Wake from Pulse interrupt, Push-pull, active low interrupt      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG4, 0x08);                 // Pulse detection interrupt enabled      I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG5, 0x08);                 // Pulse interrupt routed to INT1 - PTA5     5. As I mentioned above, the TAP (Pulse) or Transient interrupts are used to wake up the device from the SLEEP. Besides, if Auto-SLEEP interrupt is enabled, then transitioning from ACTIVE mode to Auto-SLEEP mode (or vice versa) generates an interrupt.   In this project, the Auto-SLEEP, the TAP (Pulse) or the Transient interrupts are enable. The MKL25Z128 responds to these interrupts reading the INT_SOURCE (0x0C) register, in order to determine the appropriate sources of the interrupt.   Every source of interrupt has its own way to clear the interrupt flag. Please refer to the comments of each ISR:        Transient interrupt handler      void PORTA_IRQHandler()      {         PORTA_PCR5 |= PORT_PCR_ISF_MASK;                // Clear the PTC interrupt         int_source = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, INT_SOURCE_REG); // Clear interrupt Source Register           if(int_source&0x20)  // Transient interrupt ?         {            i = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, TRANSIENT_SRC_REG); // Read the TRANSIENT_SRC register to clear the SRC_TRANS flag in the INT_SOURCE register             transient_int = 1;         }      }        TAP interrupt handler      void PORTA_IRQHandler()      {         PORTA_PCR5 |= PORT_PCR_ISF_MASK;                // Clear the PTC interrupt flag         int_source = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, INT_SOURCE_REG); // Clear interrupt Source Register            if(int_source&0x08)  // Pulse interrupt ?         {            i = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, PULSE_SRC_REG); // Read the PULSE_SRC register to clear the SRC_TRANS flag in the INT_SOURCE register             pulse_int = 1;         }      }        Auto WAKE/SLEEP interrupt handler      void PORTD_IRQHandler()      {          PORTD_PCR5 |= PORT_PCR_ISF_MASK;                // Clear the PTD interrupt flag             int_source = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, INT_SOURCE_REG); // Clear interrupt Source Register             if (int_source&0x80) // Auto Sleep/Wake interrupt ?          {             i = I2C_ReadRegister(MMA8652FC_I2C_ADDRESS, SYSMOD_REG);      // Read the SYSMOD register to clear the SRC_ASLP flag in the INT_SOURCE register             sleep_int = 1;          }      }     6. At this point, the configuration of the MCU and the accelerometer is done. The RGB LED contained on the FRDM-KL25Z board is configured in order to help showing the behavior of the application. This behavior is configured as follow:        #if TRANSIENT_DETECTION                    if (transient_int){                             transient_int = 0;                 TURN_BLUE_ON(); TURN_RED_OFF();}      #elif TAP_DETECTION                    if (pulse_int){                 pulse_int = 0;                 TURN_BLUE_ON(); TURN_RED_OFF();}      #endif                    if (sleep_int){                  sleep_int = 0;                  TURN_RED_ON(); TURN_BLUE_OFF();}     7. In summary, the FRDM-KL25Z will be interfacing with the MMA8652FC. The power mode will be set and the interrupts will be enabled. The macros at the top of the source code will allow us to select between the different power modes, the different embedded functions and to select the Auto-WAKE/SLEEP function.   If the Auto-WAKE/SLEEP function is enabled, the MMA8652FC will go into the SLEEP mode (ODR=1.56Hz) after 5 seconds of inactivity. The RED LED will be set. When an interrupt from the embedded functions is generated, the MMA8652FC will be awakened (ODR=800Hz) and so on. The BLUE LED will be set.        /* Select the Power Mode - Table 101 from datasheet */      #define NORMAL_MODE        1      #define LOW_POWER_MODE     0         /* Select the Embedded Function */      #define TRANSIENT_DETECTION       1      #define TAP_DETECTION             0        /* Auto-WAKE/SLEEP Function */      #define AUTO_SLEEP   1     8. The Table 5 from the datasheet shows the expected current consumption in regard with the power mode and ODR selected:   As I mentioned before, the Sleep mode allow us to change between different Output Data Rates (ODR) dynamically so we can reduce the current consumption.   In order to verify if the accelerometer is consuming the current mentioned on the datasheet, I measured the MMA8652FC current consumption using the project mentioned.   Please refer to the results below:           9. The advantage of using the Auto-WAKE/SLEEP mode is that the system can automatically transition to a higher sample rate (higher current consumption) when needed, but spends the majority of the time in the SLEEP mode (lower current) when the device does not require higher sampling rates.   In the manner we have come to expect of the MMA8652FC, the current consumption decreases when the ODR is changed from 800Hz to 1.56Hz, in both normal and low power mode.   The information mentioned on the datasheet is now confirmed.     Please find attached the complete source code.   I hope you find useful and funny this sample project. Any suggestion will be appreciated.   You are invited to take part of the NXP community where you can post all your questions and you may find useful material for your projects.   Best Regards, David
View full article
As requested in a prior posting...
View full article
All, We are busily working to integrate Version 7.00 of the sensor fusion library into the Kinetis Expert (KEX) ecosystem.  ETA is early August.  I have attached here a preview copy of the user manual for that release.  This is subject to the usual disclaimers: content subject to change, no liability, yada yada yada.  There are a LOT of changes.    These are documented ad nauseum in the user guide.  I've also added a lot of our old blog content into the user guide, as I keep getting requests for them.  Please take a look and give me your feedback.   FYI, Here is a sample main() for the new fusion, running on FreeRTOS:   /* FreeRTOS kernel includes. */ #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "timers.h" #include "event_groups.h" // KSDK and ISSDK Headers #include "fsl_debug_console.h"  // KSDK header file for the debug interface #include "board.h"              // KSDK header file to define board configuration #include "pin_mux.h"            // KSDK header file for pin mux initialization functions #include "clock_config.h"       // KSDK header file for clock configuration #include "fsl_port.h"           // KSDK header file for Port I/O control #include "fsl_i2c.h"            // KSDK header file for I2C interfaces #include "Driver_I2C_SDK2.h"    // ISSDK header file for CMSIS I2C Driver #include "fxas21002.h"          // register address and bit field definitions #include "mpl3115.h"            // register address and bit field definitions #include "fxos8700.h"           // register address and bit field definitions // Sensor Fusion Headers #include "sensor_fusion.h"      // top level magCal and sensor fusion interfaces #include "control.h"           // Command/Streaming interface - application specific #include "status.h"            // Sta:tus indicator interface - application specific #include "drivers.h"           // NXP sensor drivers OR customer-supplied drivers // Global data structures SensorFusionGlobals sfg;                ///< This is the primary sensor fusion data structure ControlSubsystem controlSubsystem;      ///< used for serial communications StatusSubsystem statusSubsystem;        ///< provides visual (usually LED) status indicator PhysicalSensor sensors[3];              ///< This implementation uses three physical sensors EventGroupHandle_t event_group = NULL; static void read_task(void *pvParameters);              // FreeRTOS Task definition static void fusion_task(void *pvParameters);            // FreeRTOS Task definition /// This is a FreeRTOS (dual task) implementation of the NXP sensor fusion demo build. int main(void) {     ARM_DRIVER_I2C* I2Cdrv = &I2C_S_DRIVER_BLOCKING;       // defined in the <shield>.h file     BOARD_InitPins();                   // defined in pin_mux.c, initializes pkg pins     BOARD_BootClockRUN();               // defined in clock_config.c, initializes clocks     BOARD_InitDebugConsole();           // defined in board.c, initializes the OpenSDA port     I2Cdrv->Initialize(NULL);                                 // Initialize the KSDK driver for the I2C port     I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);      // Configure the I2C bus speed     initializeControlPort(&controlSubsystem);                           // configure pins and ports for the control sub-system     initializeStatusSubsystem(&statusSubsystem);                        // configure pins and ports for the status sub-system     initSensorFusionGlobals(&sfg, &statusSubsystem, &controlSubsystem); // Initialize sensor fusion structures     // "install" the sensors we will be using     sfg.installSensor(&sfg, &sensors[0], FXOS8700_I2C_ADDR, 1, (void*) I2Cdrv, FXOS8700_Init,  FXOS8700_Read);     sfg.installSensor(&sfg, &sensors[1], FXAS21002_I2C_ADDR, 1, (void*) I2Cdrv, FXAS21002_Init, FXAS21002_Read);     sfg.installSensor(&sfg, &sensors[2], MPL3115_I2C_ADDR, 2, (void*) I2Cdrv, MPL3115_Init, MPL3115_Read);     sfg.initializeFusionEngine(&sfg);         // This will initialize sensors and magnetic calibration     event_group = xEventGroupCreate();     xTaskCreate(read_task, "READ", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);     xTaskCreate(fusion_task, "FUSION", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);     sfg.setStatus(&sfg, NORMAL);                // If we got this far, let's set status state to NORMAL     vTaskStartScheduler();                      // Start the RTOS scheduler     sfg.setStatus(&sfg, HARD_FAULT);            // If we got this far, FreeRTOS does not have enough memory allocated     for (;;) ; } static void read_task(void *pvParameters) {     uint16_t i=0;                       // general counter variable     portTickType lastWakeTime;     const portTickType frequency = 1;   // tick counter runs at the read rate     lastWakeTime = xTaskGetTickCount();     while (1)     {         for (i=1; i<=OVERSAMPLE_RATE; i++) {             vTaskDelayUntil(&lastWakeTime, frequency);             sfg.readSensors(&sfg, i);              // Reads sensors, applies HAL and does averaging (if applicable)         }         xEventGroupSetBits(event_group, B0);     } } static void fusion_task(void *pvParameters) {     uint16_t i=0;  // general counter variable     while (1)     {         xEventGroupWaitBits(event_group,    /* The event group handle. */                             B0,             /* The bit pattern the event group is waiting for. */                             pdTRUE,         /* BIT_0 and BIT_4 will be cleared automatically. */                             pdFALSE,        /* Don't wait for both bits, either bit unblock task. */                             portMAX_DELAY); /* Block indefinitely to wait for the condition to be met. */         sfg.conditionSensorReadings(&sfg);  // magCal is run as part of this         sfg.runFusion(&sfg);                // Run the actual fusion algorithms         sfg.applyPerturbation(&sfg);        // apply debug perturbation (testing only)         sfg.loopcounter++;                  // The loop counter is used to "serialize" mag cal operations         i=i+1;         if (i>=4) {                         // Some status codes include a "blink" feature.  This loop                 i=0;                        // should cycle at least four times for that to operate correctly.                 sfg.updateStatus(&sfg);     // This is where pending status updates are made visible         }         sfg.queueStatus(&sfg, NORMAL);      // assume NORMAL status for next pass through the loop         sfg.pControlSubsystem->stream(&sfg, sUARTOutputBuffer);      // Send stream data to the Sensor Fusion Toolbox     } } /// \endcode
View full article
        The FXTH87xx is a sensor for use in applications that monitor tire pressure and temperature. It contains the pressure and temperature sensors, an X-axis and a Z-axis accelerometer, a microcontroller, an LF receiver and an RF transmitter all within a single package.        Recently a customer requests help to connect FXTH87xx with Infineon TPMS receiver. We connect them each other through some testing and verification finally. The target of this document description is to replace external emitter with FXTH87xx. This document take an example to offer the users a method how to detect and decode an unknown sensor Emitter Packets using instrument provided by R&S or Anritsu, then duplicate this Emitter packets into FXTH87xx to form 315MHz, 433.92MHz TPMS emitter and receiver solution. Customer who adapts FXTH87xx can easily connect it with any external receiver using the similiar concept.
View full article
         The FXTH87XXX is a sensor for use in applications that monitor tire pressure and temperature. It contains the pressure and temperature sensors, an X-axis and a Z-axis accelerometer, a microcontroller, an LF receiver and an RF transmitter all within a single package.          NCK2912 is a fully integrated single-chip receiver for use in an automotive environment. The device incorporated several commonly used building blocks including a crystal stabilized oscillator, a fractional-N based Phase Locked Loop(PLL) for a accurate frequency selection, Low Noise Amplifier(LNA), attenuator for Automatic Gain Control(AGC), I/Q down-mixer and two high resolution Analog to Digital Converters(ADC). By transforming signals in the digital domain in an early phase, one highly configurable RX channel is available including channel filter, ASK/FSK demodulator, clock-data recovery, bit processor and a micro-controller memory interface(DMA) allowing the micro-controller to complete the data handling and handshaking. NCK2912 has an embedded RISC micro-controller optimized for high performance and low power as well as an EROM for customer application.         
View full article
clicktaleID