Discussion:
STM32 timer implementation
(too old to reply)
wjasmin93@yahoo.com [nuttx]
2018-01-16 08:18:59 UTC
Permalink
Hy,


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,
Jasmin
spudarnia@yahoo.com [nuttx]
2018-01-16 13:52:50 UTC
Permalink
The STM32 timers are described in arch/arm/stm32/stm32_tim.h, but you probably won't want to work at such a low level. You will probably want to use a free-running timer such as described in arch/arm/stm32/stm32_freerun.h

Those are intended only for use inside of the OS and cannot be used by application code (at least not without violating the portable POSIX interface). Applications should standard POSIX interfaces like clock_gettime() or clock_systimer() as prototyped in time.h

Those have the resolution of the system time. If that resolution is insufficient, you probably should consider using the tickless mode of operation as described in http://www.nuttx.org/doku.php?id=wiki:nxinternal:tickless
Michael Smith drziplok@gmail.com [nuttx]
2018-01-16 14:11:39 UTC
Permalink
Jasmin,

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...

= Mike
Post by ***@yahoo.com [nuttx]
Hy,
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,
Jasmin
Continue reading on narkive:
Loading...