Is there a "timer macro"?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there a "timer macro"?

1,329 Views
frarugi87
Contributor I

Hello

I need a (hopefully) simple timer. BUT I'd prefer not to use an hardware timer.

 

I explain. I need to measure if a time interval elapsed. My ideal piece of code will be something that gives me the clock ticks since the power on and then divides them by the clock frequency.

 

In plain old C I'd write

 

clock_t tmr = clock();

... Operation

int elapsed_ms = (clock()- tmr*1000)*/CLOCKS_PER_SEC;

 

But... In Kinetis Design Studio (Processor Expert project, so no C++, and no RTOS) the "clock" function returns always 0 and CLOCKS_PER_SEC is equal to 100.

Do you know if there is something I can use? As already stated I'd prefer not to use some hardware timers, because this is just a part of the program and I'd like to limit interferences with other parts.

 

Thank you

 

 

 

BTW... I'm using a FRDM-K64F board

Labels (1)
Tags (3)
0 Kudos
4 Replies

646 Views
ndavies
Contributor V

You will need to configure a hardware timer. It's the best way to get an accurate time based clock on an embedded board. You need a hardware timer to drive the clocking software. The PE clock functions are returning 0 because they haven't been connected to a hardware timer. In processor expert you will have to configure a hardware timer and connect it to the clock software driver.

On the K64 you have several options to generate a clock/timer. There is the Systick interrupt in the base ARM core registers, there's the PITs (Peripheral interrupt timers)  and the previously mentioned RTC (Real Time clock). The real time clock can be battery backed up and can keep time when the device is powered down. You will have to pick a timer peripheral based on the timers accuracy and when it needs to run.

0 Kudos

646 Views
yasuhikokoumoto
Senior Contributor I

Hi Franceesco,

I have never used KSD, but I think you can use RTC. If you want not to use RTC, you can make a software timer by using RTC Time Seconds interrupt.

Best regards,
Yasuhiko Koumoto.

0 Kudos

646 Views
frarugi87
Contributor I

Hello

What do you mean by "RTC"? Is there a software component called RTC or yuo mean an external or internal piece of hardware?

As I wrote, I could use a timer to generate interrupts or to track time in another way, but I'd prefer not to use other peripherals...

Bye

0 Kudos

646 Views
yasuhikokoumoto
Senior Contributor I

Hi Francesco,

I mean the internal hardware module by RTC (Real Time Clock). RTC is a timer which is not reset under any resets other than power on. It can cause an alarm interrupt, an overflow interrupt and a time seconds interrupt. The time seconds interrupt is an interrupt by every second. The RTC is used to hold elapsed time.

Best regards,

Yasuhiko Koumoto.

0 Kudos