Instruction cycles

12 Mar 2012

Hi all I am new to Mbed and programming in general, I am working on a little project where I am using a counter to calculate the time between pulses. TimerStop is assigned to a digital input pin and on reciving a logic high the counter will stop.

I am currently dividing the counter value by the clock frequency to work out the time but it doesn’t seem quite as it should be.

The question is how many cycles will it take to increment the timer?

Any help would be appreciated

Gary

hear is the code:

for (Timer=0; Timer <=Tmax; Timer++) { if (TimerStop) device.printf("%d\n", Timer);

break; }

12 Mar 2012

Hi,

I think what you want is a "Timer"

which you can start and stop, read and reset.

There's one that already comes with mBed. Have a look in the handbook under the timing functions. (scroll down a bit)

Cheers,

Dave.

12 Mar 2012

Hi Dave I have used the Timer, but it is not very accurate.

I require the time with us accuracy if not better.

Gary