PDA

View Full Version : Pulse Counter in Assembly



orlandoG
- 20th March 2007, 19:41
Can someone please help!

I'm using picbasic pro and I want to insert an assembly language routine that can count a pulse using any I/O pin similar to the COUNT command in picbasic?

The COUNT/PULSIN commands in picbasic are too slow and hold up my program The Timer interrupt pin(s) are already being used (board is already layed out) so thats out of the question.

thanks in advance

Charles Linquis
- 20th March 2007, 19:52
The best pins to use are the PORTB pins that offer a hardware interrupt function. If you can't use those, you will have to rely on a timer - but using that approach, there is a limit to how fast/short the pulses can be.

Therefore, it would be nice to know.

Can you use the PORTB interrupt pins?
What is the minimum high and low time of your pulses?

orlandoG
- 20th March 2007, 19:58
I am using the 18F6722, and the pulses are being measured on PORTE, Pin 7. The pulse is roughly 340ms

Charles Linquis
- 21st March 2007, 01:23
Your pulses seem slow enough that you could do that with a PBP interrupt.
Look at Darrel Taylor's Instant Interrupts.

You could set up a 65mSec (or so) TMR0 interrrupt, and in the ISR, read the state of the input pin, XOR it with the last value you read from that pin (something like "oldpinvalue"), if the XOR value is "1", increment a counter. Then copy the pin's state to oldpinvalue in preparation for the next interrupt.

Since you have a (more or less) precision timer going with the interrupt, you will know exactly how many changes (pulses X 2) you got in any given time interval.