Rising edge Interrupt 18F14K22

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
AndrewC
Flowcode v5 User
Posts: 28
Joined: Wed Oct 02, 2013 12:16 pm
Has thanked: 7 times
Been thanked: 7 times

Rising edge Interrupt 18F14K22

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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Rising edge Interrupt 18F14K22

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

AndrewC
Flowcode v5 User
Posts: 28
Joined: Wed Oct 02, 2013 12:16 pm
Has thanked: 7 times
Been thanked: 7 times

Re: Rising edge Interrupt 18F14K22

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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Rising edge Interrupt 18F14K22

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

AndrewC
Flowcode v5 User
Posts: 28
Joined: Wed Oct 02, 2013 12:16 pm
Has thanked: 7 times
Been thanked: 7 times

Re: Rising edge Interrupt 18F14K22

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

AndrewC
Flowcode v5 User
Posts: 28
Joined: Wed Oct 02, 2013 12:16 pm
Has thanked: 7 times
Been thanked: 7 times

Re: Rising edge Interrupt 18F14K22

Post 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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Rising edge Interrupt 18F14K22

Post by medelec35 »

That's great!

Thanks for letting us know.

Martin
Martin

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: Rising edge Interrupt 18F14K22

Post by Benj »

Thanks for this, I have now fixed these FCDs for v6 so they show the correct pins.

Post Reply