Hello.
I'm using a custom board for charging and testing batteries. Its 'brain' is an STM32F407VGT6 microcontroller. I'm developing in Ubuntu (14.04.2 LTS), using ChibiStudio (ChibiOS/RT 3.0 development branch and Eclipse Kepler). While in charge mode, I need to see how much time has passed since I initially started charging the battery. I'm having trouble with writing the necessary steps required for the time measurement. The microcontroller has an internal real-time clock (RTC). It also has timers. And ChibiOS has a time measurement function. However, I went through the documentation, researched online, but I still cannot make it work. Any help or guidance would be appreciated. Thank you.
Alex Dumitrescu
Measuring time using an STM32F407VGT6
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Measuring time using an STM32F407VGT6
Time Measurement is for small intervals to be measured with high accuracy, this does not seem to be your case.
Just read the system time using chVTGetSystemTimeX(), perform the operation, read the system time again. The difference between the two system times is your interval, the accuracy is the one of the system tick.
Giovanni
Just read the system time using chVTGetSystemTimeX(), perform the operation, read the system time again. The difference between the two system times is your interval, the accuracy is the one of the system tick.
Giovanni
-
ulikoehler
- Posts: 71
- Joined: Tue Mar 17, 2015 2:32 am
- Been thanked: 3 times
Re: Measuring time using an STM32F407VGT6
I'd use the RTC. Do not use the LSI oscillator, it has horrific frequency tolerances (+-50%, depends on the part). Either use HSEDIV RTC clock source or use an external oscillator. Then use the chrtclib.h library to get the unix timestamp if desired.
Using this strategy I believe you are more flexible and do not have to deal with systick overflows etc.
In one project I use a 32-bit timer to count the microseconds plus the RTC to count everything down to milliseconds. I don't think you need microsecond precision for battery charging applications and the F4 already has a millisecond-resolution RTC.
Best regards, Uli
Using this strategy I believe you are more flexible and do not have to deal with systick overflows etc.
In one project I use a 32-bit timer to count the microseconds plus the RTC to count everything down to milliseconds. I don't think you need microsecond precision for battery charging applications and the F4 already has a millisecond-resolution RTC.
Best regards, Uli