Hi,
If I wished to measure a pulse duration, can I....
Trigger on INT0 Rising edge.
Start timer Tmr2 and index a counter, on each tick.
Trigger on INT0 Falling edge. Read Timer value and reset counter.
I've been playing with FC in simulation only and I dont seem to be able to get sensible behavior to calling INT0 twice, once for rising edge, once for falling.
Can you NOT call two different macro based on the rising and falling edges of INT0 ??
Thanks for any thoughts. J.
Simple Pulse Duration measurement using Int0 Pin
Moderator: Benj
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
This works well and I have used it in the past however I am not sure if this will work as you think in FC by setting up two interrupts for the same INTJay Dee wrote: Trigger on INT0 Rising edge.
Start timer Tmr2 and index a counter, on each tick.
Trigger on INT0 Falling edge. Read Timer value and reset counter.
just with a different edge selected.
To make this work you need to make sure that the first edge is triggered then start the timer and configure the Interrupt for the second edge this is a sequence that you must follow to get accurate Timer readings.
This said in my opinion it is the hard way of doing it your micro has a CCP module that is designed to measure pulses /generate pulses and PWM signals
why not using the CCP module it is far more elegant as the method above use a C call and set it up it is an easy module to use
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
Yeah, I agree it certainly is a clunky way to do the task. I'll have a read of the Microchip App note on the CCP and see if I can make sense of it.
Thanks J.
Thanks J.
- Jay Dee
- Posts: 398
- Joined: Tue Aug 18, 2009 6:42 pm
- Has thanked: 121 times
- Been thanked: 154 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
Ah...So if I was to use the CCP module, each module can only be set to detect either the rising or falling edge.
So you need two CCP modules, one to detect the rising edge and one to detect the falling edge.
Unfortunately the chip in use the lower pin count PIC18F2580 only has one CCP module.
So you need two CCP modules, one to detect the rising edge and one to detect the falling edge.
Unfortunately the chip in use the lower pin count PIC18F2580 only has one CCP module.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
Hello,
There is a timer component in Flowcode 7 and 8 you could use to do the timing, it's available under the storage category. It should work out everything for you to give you the time in a standard unit.
The CCP is another good option if you fancy manipulating the registers using C. On the CCP rising interrupt you would have to configure the module to interrupt again on falling and visa versa.
The same trick can be used on an int pin that has only one rising or falling edge mode selection.
There is a timer component in Flowcode 7 and 8 you could use to do the timing, it's available under the storage category. It should work out everything for you to give you the time in a standard unit.
The CCP is another good option if you fancy manipulating the registers using C. On the CCP rising interrupt you would have to configure the module to interrupt again on falling and visa versa.
The same trick can be used on an int pin that has only one rising or falling edge mode selection.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
No you don't,you set the CCP to detect the Rising edge for example and to interrupt on detection,then when the Interrupt fires you set the ccp to interrupt on the falling edge and when the CCP int fires you reed the CCP capture value and start at edge 1 again that's all to itJay Dee wrote: So you need two CCP modules, one to detect the rising edge and one to detect the falling edge.
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Simple Pulse Duration measurement using Int0 Pin
I created this flowchart for V6 to use CCP for pulse measurement.
If it's of some interest I can convert it to V8.
At least you could view the flowchart to see how to use CCP method.
If it's of some interest I can convert it to V8.
At least you could view the flowchart to see how to use CCP method.
Martin