cancel
Showing results for 
Search instead for 
Did you mean: 

200 nano second timer

henryzhang
Associate II
Posted on November 07, 2003 at 12:35

200 nano second timer

13 REPLIES 13
henryzhang
Associate II
Posted on May 17, 2011 at 11:56

Hi friends,

I try to read/write bit through MDIO on the DK2000 board. Can anyone know how to define a 200ns timer on the DK2000 board?

I see examples of 10 ms timer.

Thanks.

----henry
neil2
Associate II
Posted on May 17, 2011 at 11:56

200nS is not much longer than one machine cycle.

(at 40MHz clock, a 6 cycle machine cycle takes 150nS) so one NOP takes 150nS, two NOPs take 300nS)
neil2
Associate II
Posted on May 17, 2011 at 11:56

not a good idea to use NOPs for a delay though, because if you receive an interrupt in the middle, the delay can be much longer.

henryzhang
Associate II
Posted on May 17, 2011 at 11:56

Thank you for reply.

What is NOP?

Why is 17 here, see following from an example of dk3200.

#define TIMER0_COUNT (0-((OSC/(12*TIMER0_PERIOD))-17))
danielh1
Associate II
Posted on May 17, 2011 at 11:56

200nsec resolution? easy: forget the DK3200 and switch to another technology.

The crystal frequency of the DK3200 is 36 Mhz, so that 1 NOP (shortest instruction) is 333nsec (12 crystal clocks). This is also the resolution of the CPU counters, and this is the best that you can get with this board.

The DK3200 examples use timer 0 to generate interrupts at a frequency of 1000Hz (1msec) and are absolutely not suited for your problem. Besides, the formula:

#define TIMER0_COUNT (0-((OSC/(12*TIMER0_PERIOD))-17))

is completely misleading: TIMER0_PERIOD is a frequency, not a period. The -17 should not be there at all; it was probably intended to compensate the interrupt latency, at the expense of the period accuracy. Anyway, for 1000Hz, there is no much difference between 3000 and (3000-17).

Do you really need a 200nsec resolution for MDIO?

henryzhang
Associate II
Posted on May 17, 2011 at 11:56

I need 400ns but I want 200 ns high and 200 ns low interval for my MDIO serial read/write.

How could I get 400ns timer?

I could not follow what examples say especially timer0_count values could not match what example gives based on the formular.

It also gives another formular that confuses me too,

//Calculate timer tollover based on FREQ_OSC to be 10ms periods (100hz)

timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);
bbbodekar
Associate II
Posted on May 17, 2011 at 11:56

Hi i had a similar problem for the factor 17L in the fromula and i hope my answer posted some time back on the forum should help you out.

''

Dear Friends,

Moderator gave me the link to the Keil app. note. And accordingly i contacted Keil support for the same.

They say that the factor 17L comes from the code overhead which is involved in the update of the timer registers. It is determined by executing the code in the uVision2 simulator, which provides accurate timing. To avoid such constants, try using the auto reload mode.

Regards,

Bhushan.

''

Well the formula, for timer count calcualtion is

timer count = 0x10000 - ( ( ( FREQ_OSC * TIME_PERIOD ) / 12L) - correction_fator ) ;

where

FREQ_OSC = in KHZ,

TIME_PERIOD = the timer value you want , in msec

correction_factor = time spent in the timer routine to do the other functions, apart from loading the timer reload value.

Now, in the example given, they had taken the timer for 10msec,

so, the factor 5L/6L ( 10 / 12 ) comes.

Actually, it is, as i said, TIMER_PERIOD / 12L

and for the timer to execute the rest of the code in timer0 ISR, in the given exmple, after the timer is restarted, needs 17 machine cycles, giving you the factor of 17L.

Hope this explanation should help you out.

Regards,

Bhushan.

henryzhang
Associate II
Posted on May 17, 2011 at 11:56

Bhushan,

Your explanation is great. Is the formular good for nano second timer?

For example, may I use TIME_PERIOD = 500ns=0.5us=0.00005ms to get time_count?

Regards,

---henry
neil2
Associate II
Posted on May 17, 2011 at 11:56

200nS is too short for this timer, as it is only a couple of instruction cycles.