Time measure

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Time measure

Post by Pask »

How can I measure how much time the system is started
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time measure

Post by Giovanni »

chTimeNow()or you can use the RTC.

Giovanni
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: Time measure

Post by Pask »

i am using chTimeNow():

if (chTimeNow()>0)
do something

Why if is never verified?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time measure

Post by Giovanni »

Because there is a problem somewhere not evident in the code you posted, the time should increase continuously.

Giovanni
fred
Posts: 20
Joined: Wed Feb 27, 2013 4:32 pm

Re: Time measure

Post 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);
...
Pask
Posts: 47
Joined: Thu Jun 19, 2014 3:51 pm

Re: Time measure

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


???
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time measure

Post 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
Post Reply