This blog was originally published by David Munsinger, software manager in the Sensors Division at Freescale, in the Embedded Beat.
In his previous entries on mining sensor data, Mike Stanley has introduced the concepts of using raw sensor data to tease useful characteristics for Sensor Data Analytics. The Embedded Data Logger is an application created to gather data for further analysis and investigation of aggregate sensor characteristics towards the purpose of developing smart sensor algorithms.
This month, Freescale’s sensor division released the Intelligent Sensing Framework (ISF 2.1). This version of ISF uses Processor Expert technology to make creating embedded sensor applications simple by removing the need to delve into the mundane details of extracting raw sensor data and allowing the user to program at the embedded application level. In this blog, I will outline how we’ve used the features of ISF to create this Embedded Data Logger application. While I will show the screen shots for the resulting changes, it is best to view the ISF training videos to get a complete idea of the steps involved.
Building Embedded Data Logger from an Example Project
You can view the complete Embedded Data Logger project. This project is preconfigured and would allow you to follow along as we explain the steps to build this embedded application.
As with most Kinetis MCU projects, we start by launching the Kinetis Design Studio (KDS). I’m using KDS 2.0 for this example. I also assume that ISF 2.1 has been installed in the standard directory on my local machine and the PEupd file for ISF 2.1 has been imported into the Processor Expert Component Library (the PEupd file is a collection of Processor Expert technology components in a format for easy import into the Component Library).
Creating the KDS 2.0 Workspace and Project
For this example, the target is a FRDM-K64F development board. The FRDM-K64F contains an on-board FXOS8700CQ 6-Axis Combo Accelerometer/Magnetometer which we will use for measuring acceleration.
First I create a workspace directly inside the Example Apps directory of ISF 2.1 and browse and import the ISF_K64F_KDS_PROJ example application into the workspace.
Configuring the Processor Expert Components and Generating the Code
At this point, we begin using the ISF Processor Expert components to build the structures for the embedded application. We add the ISF_Core component from the Processor Expert Component Library to the project. We need means to communicate to the Host PC and to the I2C sensors. This is done by configuring the CommChannelConfig1 component which is underneath ISF_Core (this component was automatically inherited by ISF_Core) to add I2C_CH1 (sensors) and UART_CH1 (host).
At a sample rate of 800 Hz, we need to bump up the baud rate on the serial interface to 230400.
Since we are using the on-board FXOS8700CQ, we need to change the I2C configuration slightly to use I2C Channel I2C0, SDA pin PTE25, and SCL pin PTE24.
Back to the ISF_Core, we need an accelerometer to measure vibration. Change the System Sensor Configuration to add the FXOS8700CQ as the only sensor. We will use the accelerometer from this combo Accelerometer/Magnetometer device. The toolwill ask you for a Comm Channel, so select I2C_CH1.
Also, we need to modify the Device Address for the FXOS8700_1 component (inside Referenced_Component) to 0x1D.
We now have the ISF Core configured, but we need to add an Embedded Application environment. We get this by adding the ISFEmbApp component from the PEx Component Library into the project.
In the ISFEmbApp, change the Initial State to STARTED_SUBSCRIBED, which causes the embedded application to initialize the sensors and begin collecting raw sensor data immediately upon startup.
Then in the Subscription List tab, add a subscription to the FXOS87000 for Fixed Point, Raw Acceleration 3D data at 800 Hz (1250 µsec). This provides high speed raw accelerometer samples across three axes (X,Y,Z) in a 32-bit fixed point generic data format for the host PC to log.
We now can receive the raw sensor data, but we want to do some customization of the embedded application, so we need to add the hooks to do that. Access the Host Interface tab and add three User Defined Host Commands and number them 7, 8, and 9. These will be attached to custom subroutines below.
Finally, we also want to use Processor Expert components to set up the RGB LEDs on the FRDM-K64F development board. These interfaces use the BitIO_LDD from the Processor Expert Component Library. We add three of these components to the project and configure them.
LED_RED uses PTB22 (Port B, Pin 22), which LED_GREEN uses PTE26 and LED_BLUE uses PTB21. Also, make sure to set the Auto Initialization property to “yes”.
We are now ready to generate the code. Select the “Generate Processor Expert Code” icon.
Attaching Custom User Code to the Generated Code inside Project
Once we have generated the ISF Embedded Application Framework, we can attach our application code to the generated code in order to respond to the Host Interface commands that we have defined and to attach functionality associated with each raw sample. In general, Processor Expert technology provides user defined function “landing pads” for this purpose. One example a “landing pad” is the App1_ProcessData function inside App1_Functions.c below
/** =================================================================== ** Event : App1_ProcessData (module App1_Functions) ** ** Component : App1 [ISFEmbApp] ** @brief ** ** Parameters : ** NAME - DESCRIPTION ** @param ** void* pProcessedDataBuffer - ** @param ** int32_t signalledEvents - ** @return ** Returns : Nothing ** =================================================================== */ voidApp1_ProcessData(void* pProcessedDataBuffer, int32_t signalledEvents) { // Cast the void * pointer to the specific embedded application data type. // This new pointer should be used to access sensor data and deliver results to insure type safety. App1SensorData_t *pProcessedData = (App1SensorData_t *)pProcessedDataBuffer; /******Write your code here*******/ }
While the function itself is generated by the tool, the code inside the function (after /******Write your code here*******/) can be modified by the user and will be preserved during subsequent code generation.
ISF Embedded Application Landing Pads
For the Embedded Data Logger, we’ve added our user code in /Sources/sensor_data_logger.c and .h files. The Embedded Data Logger makes use of the Embedded Application main loop “landing pads” to support tailored processing of the raw sensor data. These areas are generated in the main loop inside /Generated_Code/App1.c which in turn call functions supplied by the user in /Sources/App1_Functions.c. The Embedded Data Logger inserts calls into these functions as follows:
void App1_Initialization() { sensor_data_logger_init(&sensor_data_logger_handle, &sensor_data_logger_descriptor); }
The sensor_data_logger_init function sets up the Accelerometer data limits (MIN/MAX) and the length of the duty_cycle for flashing the LED to indicate activity.
void App1_ProcessData(void* pProcessedDataBuffer, int32_t signalledEvents) { App1SensorData_t *data = (App1SensorData_t *) pProcessedDataBuffer; sensor_data_logger_process(&sensor_data_logger_handle, data->rawAccelData_Sub0[0].accel); }
The sensor_data_logger_process function applies the MIN/MAX limits on the accelerometer data and then cycles the LED on/off as the activity indicator.
Host Command Interface Landing Pads
Inside /Sources/Events.c the three custom Host Command Interface (HCI) function are modified as follows:
void HCICB1_Callback(void* pHostPacket, void* pAppPacket) { sensor_data_logger_connection_test_off(&sensor_data_logger_handle); } void HCICB2_Callback(void* pHostPacket, void* pAppPacket) { sensor_data_logger_connection_test_on(&sensor_data_logger_handle); }
sensor_data_logger_connection_test_on/off simply turn on and off the green LED on the FRDM-K46F Freedom development board. This allows the user to easily identify one of several boards in a test setup to ensure that the logging designation corresponds to the correct position on the Embedded.
void HCICB3_Callback(void* pHostPacket, void* pAppPacket) { sensor_data_logger_get_property(&sensor_data_logger_handle, pHostPacket, pAppPacket); }
Sensor_data_logger_get_property returns a packet with a string of the properties that describes the embedded app version, target board identifier, and sensor identifier.
After these modifications are complete, the resulting embedded application project can be compiled and loaded on to the FRDM-K64F Freedom development board. Debugging and integration with the PC application can proceed in a normal fashion.
Conclusion
ISF 2.1 allows the user to quickly develop the embedded application frameworks for useful sensor data applications. This allows our customers to spend time on creating useful application for the raw sensor data instead of spending time just trying to get the raw sensor data for their application. The Embedded Data Logger is a good example of how the features of ISF can be used for these types of applications.
In the next blog in this series, my colleague Maureen Helm will explain how the Windows PC host application captures raw sensor data and experiment metadata to a file in order to provide the upstream files for Sensor Data Analytics.