Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer problem

Status
Not open for further replies.

electroRF

Member
Hi,

I got the following problem.

Many Tasks in the uC use the LogPrint Function I wrote, to print logs into memory.

Every time the LogPrint function is called, it reads a 5MHz Counter, in order to attach a time-stamp to each message.

The problem is that there's a certain Task A, which sometimes turns off that Counter for some-time, and then turn it on again.

Therefore, while the 5MHz Timer is Off, I read wrong values (Zeros, or same Value again and again).

I got other 32KHz Timer I could use while the 5MHz Timer is Off.

My question is, how to neatly notify the LogPrint Function that Task A turned-off the 5MHz Timer and hasn't turned it on yet?

Additionally, it'd mean that the LogPrint Function would have to have an 'if (5MHz_Timer == ON)', which would cost me 'Branch' Cycles each time the LogPrint Function is called, even when the 5MHz Timer is turned on.

Can it be done without this Cycle cost?
 
Hi Mike,
I'd rather use the 5MHz Timer when it's ON, because it provides me with higher resolution.

The 32KHz is too low than the Core Frequency.
 
I don't know which chip you're using but most can't write to flash faster than 500 bytes per second and so your 5MHz sounds like overkill.

Mike.
 
Hi Mike,

I'm working with a DSP that has a Core Frequency that can reach 400MHz @ Max Product point, and 100-200MHz at lower Product Points.

Of course that Tasks don't always print messages at this Core Frequency, but 32KHz it too slow.
 
Because I've seen it before that "stealing" a few Cycles can cause a problem.

But you may be right on that.

How would you suggest that Task A would notify the LogPrint Function that the 5MHz Timer is Off?

Is a global variable 5MHz_Timer_Mode, that would be set/cleared whenever Task A enables/disables the Flag, considered a good option?
 
Hi,
I'd love to hear your comments :)

The question is how to neatly notify the LogPrint Function that Task A turned-off the 5MHz Timer and hasn't turned it on yet?

LogPrint
is called by many tasks, and each time LogPrint is called, it reads the 5MHz Timer and attaches its time-stamp to the print.

I'd like to know when That 5MHz Timer was turned off by Task A, so the LogPrint will read another Timer during the period in which 5MHz Timer is OFF.

Thank you.
 
Just read the timer at the beginning of your routine. If it hasn't changed by the time you need a timestamp, it is not running.

However, what you're saying sounds like a total nonsense to me. If timer is turned off, the time that it is keeping is lost and cannot be restored unless you have some other equally accurate time source. Using such timer for timekeeping is like storing water in a colander.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top