PDA

View Full Version : Need help with INTerrupts



Srigopal007
- 2nd August 2007, 21:24
I have a project that has a sensor connected to the analog pins of the microcontroller.
PIC18F6520 is the controller part number which I am using The sensor is sending a
train of pulses at a certain frequency. I would like to measure the length of time
the signal is high, and the period od the entire pulse so that I can measure the frequency and the duty cycle of the pulse.


I was thinking that I should implement a interrupt and two timers Timer0 and Timer1.

the timer0 can measure the time the pulse is high, and timer1 can measure the period of the pulse.

I know this is possible but I need your help. My question is from the code below. how will the timer know when the input pulse made a transition from high to low and when to stop the timer.

here is what I ahve thus far.

I have started interrupt and the timer0(the timer that will measure the high pulse).
I was wondering how to use the On inteerupt command that PBP comes. so whenever the interrupt comes I can jump into the ISR and begin measureing the pulse with timer0


CODE----------------------------------------------------------

Value VAR Byte 'value for how long the pulse was high.
TrisD = %11000000


On Interrupt goto ISR_INT

start:
if(PortD.7 = 1)&&(PortD.6 = 0) then
T0CON = %11000011 'Timer0 is turned on
INTCON.7 = 1 'Globale interrupt enabled
endif
if(PortD.7 = 0)&&(PortD.6 = 1) then
T0CON = %11000011 'Timer0 is turned on
IntCON.7 = 1 'Global interrupt enabled

endif

Goto Start

Disable


ISR_INT:

T0CON = %11000011 'Timer0 is turned on
'Timer0 prescalar to 16
'Timer0 increment on low to high transition

Value = TMR0L 'store the value of the lower 8 bits of TIMER0 into the Value variable

INTCON.1=0 'clear the timer0

Resume
Enable

Bruce
- 3rd August 2007, 00:53
There's an example of using the capture module in this thread
to measure high/low pulse width, and period;
http://www.picbasic.co.uk/forum/showthread.php?t=6719