atomski,
The example given above uses PBP's ON INTERRUPT GOTO type of interrupts. Since the exact time that the interrupt is serviced is not known, it's not a good choice for timing both high and low pulses consecutively.
However, it can be done relatively easily with ASM using 1 of 2 possible methods.
1. CCP module in CAPTURE mode using Timer1 and CCPIF interrupt.
2. INT external interrupt using Timer1.
The first thing to point out here is that both methods use Timer1. So, the question is, Which one do you want to use. Do you use the INT pin and save the CCP module for something else? Or, use the CCP module and save the RB0 (INT) pin?
The second thing to mention is that these interrupts will interfere with any "Software Timed commands" like SEROUT, PULSOUT/IN, and most importantly FREQOUT. I say that because you had mentioned in the other thread that the chip would also be using FREQOUT. The degree to which it affects those commands is dependant on the time it takes to process the interrupt. Trying to capture and decode your pulse stream in real time might take enough time to make the problem noticable. But that's just a guess at this point.
The idea is pretty much the same for both techniques.
On each interrupt, immediately save the values in TMR1H:TMR1L, and then reset TMR1. Now at this point, simply change the "Edge" that causes an interrupt. For INT it's OPTION.6 (16F628). The first time through will give a Bad value. Then on the next interrupt is does the same thing, but this time the value will correspond to the last pulse width. Since you are just looking for the widths of either high or low pulses, theres no need to keep track of which one it actually was.
Actually decoding the stream will only take a few subtractions to determine if it's a START, 0 or 1. Shift the results through a register and you should have it. Also, if Timer1 overflows. it's either in-between bytes, or an error. It should scrap any bits that have already come in and wait for the next Start bit.
The only diference when using the CCP module is that you'll get the value from CCPR1H:CCPR1L instead of TMR1H:TMR1L. And, the "Edge" selection for the CCP module is CCP1CON = %101 (rising) and CCP1CON = %100 for falling edge.
-------------
It may or may not be apparent from that, but when measuring both high and low pulses consecutively, the CCP module doesn't really do anything for you. With only one exeption, it frees up RB0. Well, OK it does do one other thing. It introduces a small error, equal to the time it takes to enter the interrupt and reset the timer.
If you don't need RB0, I would suggest using option 2.
HTH,
Darrel
Bookmarks