Counting pulses over hours

gtslabs

Member
I need to count pulses over a long period of time for my stepper motor project. My frequency range is 1hz to 5Khz. I am micro stepping my motor as slow as 1/8th or 1600 steps per rev. However that resolution is more than I need so I was thinking of counting only every x pulses. I estimated that over the entire range of movement I may need a 24 bit variable. (600,000 pulses every 1" of linear movement and I need 3 inches) The duration of counting may be hours to days so I did not think I could use the count command limited to 65 seconds. I know I will have to make some rollover flag for the last 8 bits of 24. I am using the 40x1 at 4mhz.

What can I do to accumulate pulses in to a variable?
 

premelec

Senior Member
Please be more specific - where are the 1 Hz to 5 KHz pusles? What _accuracy_ of count is needed? Timing of readings?

One possible way to do this is use a digital integrator - an external counter - which may or may not be connected to a D/A convertor the analog output of which is read by the PICAXE and then reset after read... or you read the digital high speed counter directly etc.... I'm being sketchy as I don't know just what you've got...


Edited by - premelec on 15/08/2007 06:33:36
 

Tom2000

Senior Member
Monitor one of the pulse lines with a Picaxe input. In your program, trigger an interrupt from the pulse input.

Set your interrupt routine to increment a 3-byte counter at each call, then continue to monitor the pulse input. When the interrupt condition clears, re-enable interrupts and exit.

Good luck!

Tom
 

Jeremy Leach

Senior Member
I think the interrupt idea might not function well with 5KHz input (although worth a try).

I think the 'SetTimer Count' command would be perfect here - using the internal timer as a counter, running in the background. If you use a crystal as well you've got yourself a very accurate counter.
 

Tom2000

Senior Member
<i>&quot;I think the interrupt idea might not function well with 5KHz inputt...&quot; </i>

I thought of that after I posted the message. When I get some time, I need to blow the dust off my function generator and give it a try.

(Actually, I'm wondering about that 5 kHz figure. I've never been able to pulse a stepper at much over 1 kHz. I know there are some out there that are supposed to be somewhat faster, but not that fast. If the realistic maximum rate is at typical speeds, this might work. Or might still be on the ragged edge.)

Code the interrupt routine tightly!

Tom
 

Tom2000

Senior Member
<i>&quot;I think the 'SetTimer Count' command would be perfect here - using the internal timer as a counter, running in the background...&quot; </i>

I forgot about that one. I just checked Manual 2 and yes, I believe that's the correct approach.

Tom
 

gtslabs

Member
Thanks

The manual states: &quot;When the internal
counter register overflows from 65535 to 0, the special &#8216;timer&#8217; variable is
automatically incremented&quot;

How do I access this special timer variable? Can I poll it?
 

Jeremy Leach

Senior Member
Page 10 refers to the Timer Variable, a word variable that's automatically updated and you can use in expressions as you want to.
 
Top