Page 1 of 1

Rising edge Interrupt 18F14K22

Posted: Sun Nov 10, 2013 3:58 am
by AndrewC
Hi.

I'm not sure which are the correct pins to use to enable a rising edge interrupt.
The editor suggests RB0 to RB3 for INT0 to INT3 but the chip image does not have pins RB0 to RB3 but instead shows INT0 to INT2 on pins RC0 to RC2.

What has me more confused the data sheet appears (I'm only a beginner) to suggest that INT0 to INT2 is on pins RA0 to RA2.

Have I miss read this and can a rising edge interrupt be done on this chip using Flowcode? If so what am I missing?

Thanks.

Re: Rising edge Interrupt 18F14K22

Posted: Sun Nov 10, 2013 10:30 am
by medelec35
Hi Andrew,
I can totally understand the confusion.
The correct interrupt pins should be the ones stated within the datasheet.
The RB0 - RB3 within Flowcode for INT0 to INT3 is just an error.
If you select RB0/INT0 you hardware should work if you connect your switch or whatever your using for interrupt to pin RA0, then your interrupt service macro should be triggered when RA0 a rising ( or falling depending on which edge you have selected) edge has been detected.
If you are using a switch and rising edge for example, it's vital that a pull down resistor(Say 4K7 to 10K) is connected between interrupt pin and 0V
Switch is connected between interrupt pin and +5V
Or if using falling edge interrupt is selected then you must either have a pull-up resistor connected between interrupt pin and +5V
Switch is connected between interrupt pin and 0V

Note: instead of a physical pull-up resistor you can enable a internal weak pull=up on port A (WPUA) or port B(WPUB)
Will only expand on that if you really want to go down that route since it gets slightly more complex.

If I can find a simular target device, I will see of my theory of connecting to RA0 for INT0 is correct.

Re: Rising edge Interrupt 18F14K22

Posted: Mon Nov 11, 2013 10:37 am
by AndrewC
If you select RB0/INT0 you hardware should work if you connect your switch or whatever your using for interrupt to pin RA0, then your interrupt service macro should be triggered when RA0 a rising ( or falling depending on which edge you have selected) edge has been detected.
Thank you for the clarification. I'll try that and report back.
If you are using a switch and rising edge for example, it's vital that a pull down resistor(Say 4K7 to 10K) is connected between interrupt pin and 0V
Switch is connected between interrupt pin and +5V
Or if using falling edge interrupt is selected then you must either have a pull-up resistor connected between interrupt pin and +5V
Switch is connected between interrupt pin and 0V
That will explain some of the erroneous behaviour I've been getting, Nice one.

Thanks very much for the help.

Re: Rising edge Interrupt 18F14K22

Posted: Mon Nov 11, 2013 11:21 am
by medelec35
AndrewC wrote:That will explain some of the erroneous behaviour I've been getting, Nice one.
Yes there will be some very unexpected triggering.
Since the input resistance is very high, if no pull-up or pull-down resistor is connected between i/p pin and supply, then the input will be classed as floating.
A finger placed near the i/p or other electrical interference will case the voltage of the i/p to rise to more than is required for logic 1.
AndrewC wrote:Thank you for the clarification.
Your welcome, just hope I'm not wrong.

There is also another issue you may need to deal with and that's switch contact bounce.
As the switch closes, the contacts may open and close a few times within a few milliseconds.
Each time that could happen, the interrupt will get fired.
The cure is to either use a resistor/capacitor filter circuit.
Or
Add delay in your software.
Avoid added a delay within interrupt routine as this is bad practice and prevents other interrupts from triggering whilst within the interrupt routine.


Martin

Re: Rising edge Interrupt 18F14K22

Posted: Tue Nov 12, 2013 10:37 am
by AndrewC
[quoteA finger placed near the i/p or other electrical interference will case the voltage of the i/p to rise to more than is required for logic 1.
][/quote]

That would explain why I thought I had a poor connection somehow triggering the chip as I went to press the button. :lol:
There is also another issue you may need to deal with and that's switch contact bounce.
As the switch closes, the contacts may open and close a few times within a few milliseconds.
Each time that could happen, the interrupt will get fired.
The cure is to either use a resistor/capacitor filter circuit.
Or
Add delay in your software.
Avoid added a delay within interrupt routine as this is bad practice and prevents other interrupts from triggering whilst within the interrupt routine.
I also had this issue but did use a delay although it was during the interrupt routine. But I do like that r/c filter idea and will use it next time. Thanks for that. Another awesome tip. :)
In this project the switching high will hopefully be done by another chip.

Re: Rising edge Interrupt 18F14K22

Posted: Thu Nov 14, 2013 9:26 am
by AndrewC
just hope I'm not wrong.
It works as you suspected.
Chosen interrupt works on pins as shown on data sheet. Thanks again

Re: Rising edge Interrupt 18F14K22

Posted: Fri Nov 15, 2013 11:40 am
by medelec35
That's great!

Thanks for letting us know.

Martin

Re: Rising edge Interrupt 18F14K22

Posted: Fri Nov 15, 2013 12:00 pm
by Benj
Thanks for this, I have now fixed these FCDs for v6 so they show the correct pins.