View previous topic :: View next topic |
Author |
Message |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
RB change interrupt |
Posted: Tue Jun 28, 2005 1:34 am |
|
|
hi,
I want to use the RB change interrupt on port RB4.
RB5, RB6 ,RB7 are configured as outputs and RB4 is configured as an input.
So if state of RB5 .. RB7 changes as output, will the RB_isr() fire? This is unwanted.
The goal of this is, while the processor sleeps < 5uA; he will wake of RB4 going low, this means that the battery voltage is below 3.15; when this has happened, the PIC should do some things and then goes to sleep again.
When RB4 goes high again (I need some kind of schmitt trigger input), the battery voltage is back OK and the PIC should do some things again, and go back to sleep. Is that all possible?
many thanks |
|
|
Ttelmah Guest
|
|
Posted: Tue Jun 28, 2005 6:50 am |
|
|
RB change will fire if any of the top 4 bits change.
You can 'program round' it with something like:
disable_interrupts(INT_RB);
output_high(PIN_B4)
dummy=input_B;
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
Potentially an external trigger, will be 'missed' if it occurs in the instructions represented by this, but at least you won't get the interrupt when you output data. Obviously you could add a manual test for the RB4 but having changed to cover this contingency.
Best Wishes |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jun 28, 2005 8:05 am |
|
|
dear,
this I read in AN566
Quote: | The feature this application note will focus on is the
Interrupt on Change of the PORTB pins. This �interrupt
on change� is triggered when any of the RB7:RB4 pins,
configured as an input, changes level. |
=> configured as an input; so if RB5 - configured as an output - changes from L to H, will the isr() fire? |
|
|
Ttelmah Guest
|
|
Posted: Tue Jun 28, 2005 8:44 am |
|
|
You don't mention what chip is involved?.
You can see how the logic works, by looking at the layout of the I/O pins concerned. The behaviour changes between chips. A couple of the very early chips simply compare the input with the latched value, to trigger the interrupt. Latter chips generally have an extra 'and' gate, that disable the comparison on pins configured as an output, but some also have the ability to enable the comparison on a 'per pin' basis.
You need to check the data sheet for your specific chip.
Best Wishes |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jun 28, 2005 8:54 am |
|
|
Dear,
I just tested it. It does fire when RB5, RB6 and RB7 change state as an output; that is unwanted!
In main I state
Code: | set_tris_b(0x11); // B0 en B4 zijn inputs |
I'm using RB5, RB6 and RB7 to scan my keyboard, as outputs! :\
R7 = RB5
R8 = RB6
R9 = RB7
Code: | // RIJ 7
Output_low(R7);
temp = input_d();
Output_float(R7);
if ((buffer[6] & temp) != buffer[6])
Pressed = TRUE;
buffer[6] = buffer [6] & temp;
if (temp != 255)
Alles_los = FALSE;
// RIJ 8
Output_low(R8);
temp = input_d();
Output_float(R8);
if ((buffer[7] & temp) != buffer[7])
Pressed = TRUE;
buffer[7] = buffer [7] & temp;
if (temp != 255)
Alles_los = FALSE;
// RIJ 9
Output_low(R9);
temp = input_d();
Output_float(R9);
if ((buffer[8] & temp) != buffer[8])
Pressed = TRUE;
buffer[8] = buffer [8] & temp;
if (temp != 255)
Alles_los = FALSE; |
I'll try your workaround and post the results after checking the datasheet (didn't fiind the part on interrupts that easy, I'll look again) |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jun 28, 2005 9:05 am |
|
|
Code: | Four of the PORTB pins, RB7:RB4, have an interrupton-
change feature. Only pins configured as inputs can
cause this interrupt to occur (i.e., any RB7:RB4 pin
configured as an output is excluded from the interrupton-
change comparison). The input pins (of RB7:RB4)
are compared with the old value latched on the last
read of PORTB. The �mismatch� outputs of RB7:RB4
are OR�ed together to generate the RB port change
interrupt with flag bit RBIF (INTCON<0>). |
Only inputs :\ Still it fires continuously |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Wed Jun 29, 2005 8:10 am |
|
|
Hi
if I state:
output_float(PIN_B5);
can that cause an interrupt RB on change?
My program is continuously interrupting |
|
|
Ttelmah Guest
|
|
Posted: Wed Jun 29, 2005 8:17 am |
|
|
If the pin actually is floating (not driven by something else), then 'yes'. Enable the weak 'pull-ups' on port B, and it'll ensure that a pin that is floating stays 'high'. All 'output_float' does, is set the pin as an input...
Best Wishes |
|
|
|