Simple Pulse Duration measurement using Int0 Pin

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Simple Pulse Duration measurement using Int0 Pin

Post by Jay Dee »

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 ??
18F2580_Pulse_Measure.fcfx
(22.86 KiB) Downloaded 244 times
Thanks for any thoughts. :) J.

User avatar
QMESAR
Valued Contributor
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

Post by QMESAR »

Jay 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.
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 INT
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

User avatar
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

Post by Jay Dee »

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.

User avatar
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

Post by Jay Dee »

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.

User avatar
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

Post by Benj »

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. :D

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.

User avatar
QMESAR
Valued Contributor
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

Post by QMESAR »

Jay Dee wrote: So you need two CCP modules, one to detect the rising edge and one to detect the falling edge.
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 it

medelec35
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

Post by medelec35 »

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.
Martin

Post Reply