This week's update is going to be short but sweet, as I have been working most on the firmware architecture and device driver development. So far, the code flow as below.
The intention is that the emission sensor board will be powered by the car's battery via 12V plug, ideally this will be wired through the ignition switch, so we can detect that the ignition is turned on or off. However, for a minimal design, we can determine the engine state through a vibration profile.
After the hardware has been initialised, the main loop for the firmware will sample the accelerometer at TBD rate. More research needs to be done on identifying the ideal sampling frequency, and vibration profile at different engine states. The sampled value is then stored to a buffer and filter out the noise. Again, as with the sampling frequency, the filter type and coefficients are yet to be determined, more of info will be provided in the coming posts about signal processing. At this stage, data acquisition is the more important part.
From the filtered data we will be able to deduce the engine state, i.e. off, idling, or running and send the updated state to a connected smartphone via Bluetooth LE. If the engine is running, CO2 emission is sampled and sent to a smartphone for further processing. CO2 emission, engine state and GPS data (as read from smartphone) will all be used to generate tangible information before being sent to AirVantage.
Translating the flowchart into code, we have the following (excerpt from main.c):
int main(void) { Acceleration_T raw_accel; Acceleration_T filtered_accel; EngineState_t engineState = Engine_Off; Hardware_Init(); while (1) { if (Accelerometer_IsSamplingCompleted() == false) continue; Accelerometer_GetRawAcceleration(&raw_accel); FilterNoise(raw_accel, &filtered_accel); if (EngineStateChanged(filtered_accel, &engineState)) { SendEngineState(&engineState); } if (engineState != Engine_Off) { /* Sample CO2 emission */ int32_t temperature = 0; int32_t humidity = 0; HDC1000_Measure(&HDC1000_Instance, &temperature, &humidity); MQ135_Read(&MQ135_Instance, temperature, humidity); SendEmissionInfo(&MQ135_Instance.ppm); } } }
Since time is ticking so fast, and I have a good working firmware framework in place, so I think its about time for me to switch my tasks and focus on hardware development.