Using port B interrupt on change ( IOC) with No Masking.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
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:

Using port B interrupt on change ( IOC) with No Masking.

Post by medelec35 »

I thought I would pass on some of my experience of why Flowchart I developed did not work way I was expecting to.
All I wanted to do was add 1 to a count variable and reset another variable every time interrupt on port B4 was detected using 16F877A
What was happening was count incremented when there was no change on port B4. Scoping B4 confirmed pin was staying a 0V.
Issue was caused by the other portB pins defaulting to inputs.
This meant they were floating, hence outside interference was randomly changing from 0 to 1 and back to 0

Two fixes sprang to mind.
1) Set the port B pins not used to o/p
2) Even if not using other port B pins set a routine up within port B interrupt to check If state of Port B4 has changed since last time if yes count = count +1 etc.
There are advantages and disadvantages with both. I have opted for option 1.
Only since if i/p floating causes port interrupt to fire, then this puts any other interrupt firing in a queue.

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: Using port B interrupt on change ( IOC) with No Masking.

Post by Benj »

Hi Martin,

Another two possible options are to enable internal weak pull ups if available or to use external weak pull ups/pull downs to overcome the problem.

I remember a problem like this dragging on for about a week when I was first getting started with micros, just couldn't figure out that if you left an input pin disconnected it would essentially float due to low current electrical noise and not be the nice stable logic zero I was expecting.

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: Using port B interrupt on change ( IOC) with No Masking.

Post by medelec35 »

Benj wrote: I remember a problem like this dragging on for about a week when I was first getting started with micros, just couldn't figure out that if you left an input pin disconnected it would essentially float due to low current electrical noise and not be the nice stable logic zero I was expecting.
Bet that has happened to a good few people as I know that's caught me out before.

Benj wrote:Hi Martin,

Another two possible options are to enable internal weak pull ups if available or to use external weak pull ups/pull downs to overcome the problem.
Ah yes of course you are correct , that slipped my mind when writing the initial post :lol:

My point is that if you set to use one i/p e.g port A0 then you will know that it does not matter that port pins not used i.e ports A1- A7 will be all set to i/p and floating by default but does not matter since only A0 has an input icon.
So what ever happens to A1 - A7 does not matter.

However if setting up port B interrupt that's not maskable, you may only have 1 port B input e.g. B5
but in this case unlike port A, it does get affected by all the port B pins that can be used as an interrupt i/p even if you have not assigned any other port B to i/p.

So revising list, so long as weak pull-ups are not affected by strong fields would be the way to go.
Thanks for reminding me Ben. :)

Mrtin
Martin

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: Using port B interrupt on change ( IOC) with No Masking.

Post by medelec35 »

Hmmm.
That's odd.
As soon as WPU are enabled pulse duty readings fail :?
Flowchart reads a PWM then displays result on LCD directly as a duty, including 0 and 100%
Suppose I am measuring a pulse with a duty of 36% confirmed with a scope.
Display does read 36% with all port B inputs (except for one connected to PWM waveform) set to o/p.

If i remove this o/p component then just place clear_bit(option_reg , 7); at the start then display show 100%
I was not expecting that.
WPU not changing waveform to interrupt i/p pin.

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: Using port B interrupt on change ( IOC) with No Masking.

Post by Benj »

Hmmm :(

I have come across some similar problems when using interrupt pins but not this exact problem. My problem was with 3.3V signals on a 5V micro not triggering the interrupt due to lack of voltage even though the voltage was within the tolerance for a valid logic 1. I wonder if its related and the weak pullups are providing some kind of voltage divider that is effecting the interrupt from working?

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: Using port B interrupt on change ( IOC) with No Masking.

Post by medelec35 »

Benj wrote: I wonder if its related and the weak pullups are providing some kind of voltage divider that is effecting the interrupt from working?
It could be. Although mark is 4.58V measured directly on the pin, it is via a 27K resistor.
Act I have got a 10V o/p and using 22k & 27K in series and i/p to interrupt is across 22K so voltage just stays below 5V.
I would of thought 4.58V is more than enough :lol:
I will figure it out one day :P

Martin
Martin

Post Reply