With this sort of application, itâs important to know the time at which the sensor captured the data, not the time at which software noticed it.
Ideally you will have the sensorâs data-ready signal (which correlates fairly closely with the time at which the data was read, but obviously with some lag) connected to an input on the SoC that can be mapped to a timerâs Input Catpure function. Then you need to arrange for the timer to run at a rate that you can in turn correlate with your timebase.
If you canât do this and you are forced to poll the sensor, you need to disable interrupts while youâre checking the data-ready signal and then fetching the timestamp to avoid being interrupted between the two, and then you need to account for the possibility that your reading is late by (on average) half the time between your poll calls. If you track this time for long enough, you can estimate the skew between the sensor output rate and your poll rate, but this will never be as precise as the first method.
As for where to implement; the STM32 timer driver should have all the necessary pieces to set up an input capture, but if not itâs pretty straightforward to reach around it and control the hardware directly...
Post by ***@yahoo.com [nuttx]
I'm pretty new to nuttX and programming at all. Therefore, please excuse my lack of knowledge I try to gain experience.
I'm currently working on a project using a STM32 board and several sensors. The main program is working and also all the drivers are implemented. One of the sensors is a gyroscope (BMG160) which I analyzed precisley due to the demanded high accuracy. I recognized that the frequency is not constant over time, especially if the temperature changes (Deviation of about 0.3 Hz). At the moment, I use a constant frequency for calculating the angle which leads to a too imprecise output.
I think about using a microcontroller timer (stm32_tim) to calculate the passed time between the last and new measurement but I'm not sure about how and where to implement (also regarding the hierarchy structure of the different files and drivers). I wanna avoid measuring other calculations or activities.
Does anyone have experience with that topic or ideas?
Many thanks in advance,