View previous topic :: View next topic |
Author |
Message |
rayhall
Joined: 05 Jun 2010 Posts: 2 Location: Cairns, Australia
|
Rising and falling Interrupt |
Posted: Sat Jun 05, 2010 9:38 pm |
|
|
I am using the PIC18F2620.
I want the external interrupt to trigger on both rising and falling edges. The only options I can find are
Code: |
ext_int_edge( L_TO_H );
ext_int_edge( H_TO_L );
|
I need something like, ext_int_edge( H_OR_L );
Ray. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Jun 06, 2010 9:38 am |
|
|
What you can do is change the edge at the next interrupt.
I've done that in the past and it's works fine.
Just do an IF to check to see which way the level is currently set and then set/clear it as appropriate.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sun Jun 06, 2010 12:50 pm |
|
|
You can use PORTB interrupt (int_rb) for detecting level changes.
Most PICs support that interrupt. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 06, 2010 1:02 pm |
|
|
Right, but on the 18F2620 you can't enable the PortB pins on an individual
basis for Interrupt-on-change. He would have to change to the K-series
(18F26K20) to get that capability. The K-series only runs at 3.6v max,
so that could be a limitation. |
|
|
rayhall
Joined: 05 Jun 2010 Posts: 2 Location: Cairns, Australia
|
|
Posted: Sun Jun 06, 2010 3:40 pm |
|
|
Thank you for the replies.
I have been using Atmel in the past, and I must say, I see the PIC interrupts as flawed for not having this. It just makes for more complicated code.
I hope as I use the PIC more, I do not find other flaws like this.
Ray. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
i had to solve that same problem on another part |
Posted: Sun Jun 06, 2010 7:40 pm |
|
|
its not perfect but i did make it work in MY case.
IF you have a SPARE pin elsewhere on port B -
you can solve it the way i did:
* choose a portB or ANY other digital input pin and connect
your input signal to it.
* pick a portB pin with edge int - set LOW to HI trigger
and drive IT with the output of a 74HC86 EXOR gate -
* feed the SAME source signal into ONE input of the exor gate
and feed the OTHER input with the same signal thru
a 1K resistor shunted to ground
( at the pin input ) with a 2 -20 pf capacitor.
you may need to adjust the capacitor value based on your frequency
of state transitions but 5 pf is a safe value for even 100 khz rate
this produces very narrow pulses in the 100 nano second range or less
and the idle state is always zero - but i found i could reliably trigger the interrupt and then read the ACTUAL hi or LOW state on the second pin i was paralleled to - to do the actual reading of HI or LOW
yes it requires some hardware and an extra pin - but it will work - in my case with square waves in the 50 khz range - getting both transitions
hope it helps you |
|
|
|