Page 1 of 1
Time measure
Posted: Thu Jul 03, 2014 3:25 pm
by Pask
How can I measure how much time the system is started
Re: Time measure
Posted: Thu Jul 03, 2014 3:29 pm
by Giovanni
chTimeNow()or you can use the RTC.
Giovanni
Re: Time measure
Posted: Mon Jul 07, 2014 9:38 am
by Pask
i am using chTimeNow():
if (chTimeNow()>0)
do something
Why if is never verified?
Re: Time measure
Posted: Mon Jul 07, 2014 9:47 am
by Giovanni
Because there is a problem somewhere not evident in the code you posted, the time should increase continuously.
Giovanni
Re: Time measure
Posted: Mon Jul 07, 2014 10:21 am
by fred
If granularity on the scale of a second is good enough, use the RTC_EVENT_SECOND :
Code: Select all
//seconds since boot tracker
uint32_t secondsSinceBoot = 0;
static void RTC_callback(RTCDriver *rtcp, rtcevent_t event) {
(void)rtcp;
switch (event) {
case RTC_EVENT_OVERFLOW: break;
case RTC_EVENT_SECOND: /* every second update code here */
secondsSinceBoot++;
break;
case RTC_EVENT_ALARM: break;
default: break;
}
}
//somewhere in your initialisation:
rtcSetCallback(&RTCD1, RTC_callback);
...
Re: Time measure
Posted: Mon Jul 07, 2014 3:15 pm
by Pask
Giovanni wrote:Because there is a problem somewhere not evident in the code you posted, the time should increase continuously.
Giovanni
i don't understand. How can i do
if(chTimeNow()>MS2ST(10))
do...
???
Re: Time measure
Posted: Mon Jul 07, 2014 3:58 pm
by Giovanni
chTimeNow() returns the value of a counter that is increased by a timer so:
1) Check that interrupts are enabled where you perform the check.
2) Make sure the timer is working.
If you want detailed help then give context, hint, 2 lines of code are not sufficient.
Giovanni