Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/18/09 22:30
Read: times


 
#166231 - free-running counter/timer
Responding to: ???'s previous message
Per Westermark said:
On another note. You don't have to start/stop a timer to use it for timing. I often use a free-running timer. It may have an interrupt handler ticking every 1ms or 10ms or whatever. But I can also let a software delay read out the current value and then wait until it has ticked a specific number of steps or a specific number of turn-arounds or whatever is applicable.


I do this, too, although most recently on Xilinx MicroBlaze and PPC designs. The hardware includes a free-running 32-bit counter, and I make this counter available to both arbitrary FPGA logic as well as appearing to the micro as a read-only register.

Before going into the for(;;) loop I read and save the counter value. The main loop of the micro application reads that register once per run through the loop, and compares the difference between the saved value and the current value, and if it exceeds some constant, then I do whatever I needed to do at that interval, and I save the new count, and start it all again.

This works well for millisecond counts, and at 80 MHz, the counter rolls over every 53 seconds and anyways, my compare takes rollovers into account.

I suppose if I needed microsecond-level accuracy I'd consider something else, like perhaps having the counter interrupt.

-a


List of 30 messages in thread
TopicAuthorDate
s/w delay function            01/01/70 00:00      
   Software loops can be optimized away            01/01/70 00:00      
   lacks side-effects            01/01/70 00:00      
      First time with LINT?            01/01/70 00:00      
   lacks side-effects            01/01/70 00:00      
      That does not mean it is an error.            01/01/70 00:00      
      It also blocks            01/01/70 00:00      
   How to post legible source code            01/01/70 00:00      
   DELAY_0.1.ZIP Useful?            01/01/70 00:00      
      That doesn't help, and it won't work anyhow!            01/01/70 00:00      
         I stand by it.            01/01/70 00:00      
            Yes a delay function is useful            01/01/70 00:00      
               wrong !!!!            01/01/70 00:00      
               No, that's precisely where you're wrong            01/01/70 00:00      
            How can you say that?            01/01/70 00:00      
               I think you should read Murray's comments            01/01/70 00:00      
                  I have seen ...            01/01/70 00:00      
                     Timers usable without start/stop too            01/01/70 00:00      
                        free-running counter/timer            01/01/70 00:00      
                           Unsigned integers            01/01/70 00:00      
                              re: unsigned            01/01/70 00:00      
                                 Try unsigned subtraction with borrow            01/01/70 00:00      
                                 bug in second (improved!?) code block            01/01/70 00:00      
   Delay Loops in 'C'..!!! NO            01/01/70 00:00      
      Go on. Suggest a SIMPLE alternative            01/01/70 00:00      
         My Methods            01/01/70 00:00      
            So he has a long list of constraints            01/01/70 00:00      
               oh boy what a load who wil have 10 minutes for this            01/01/70 00:00      
                  Ok. I was being naughty.            01/01/70 00:00      
                     you forget the obvious ...            01/01/70 00:00      

Back to Subject List