View previous topic :: View next topic |
Author |
Message |
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
interrupts again! |
Posted: Mon Jan 16, 2012 5:15 pm |
|
|
Hi, everyone, I am working on a project that uses interrupts. The program flow is such that MCU sleeps when interrupt is triggered, then by making pin_b0 low, it wakes up. It works fine at this stage, but i want like 15 pins to be able to wake the MCU, not just "pin_b0,pin_b4 t0 pin_7". i.e when the MCU sleeps, any of the 15 pins should be able to wake it.
I am using PIC18F2520, here's an excerpt of the code:
Code: |
while(1)
{
green_led_on; //to indicate when system is awake
while( count++!=3000) // 3secs, i.e 3000x1ms(delay)=3secs.
{
while(!input(pin_b0)) // i need 15 pins to do this
{
//delay_ms(50); // switch debounce
output_toggle(green_led);
delay_ms(100);
count=0; // reset count when button is pressed
break;
}
delay_ms(1); //delay used to increment count
}
count=0; //reset count before interrupts starts
enable_interrupts(GLOBAL);
EXT_INT_EDGE(H_to_L);
enable_interrupts(INT_EXT);
green_led_off;
sleep(); // put cpu to sleep
}
}
#INT_EXT
void ext_isr()
{
disable_interrupts(INT_EXT);
green_led_on;
enable_interrupts(INT_EXT);
}
|
Any help or code snippet would be appreciated.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2012 5:33 pm |
|
|
Look at this diagram in the 18F2520 data sheet and you can see what
interrupt sources you have available for wake-up from Sleep:
Quote: |
FIGURE 9-1: PIC18 INTERRUPT LOGIC |
http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf
There are not enough pins that have interrupts on them, to be able to
handle 15 separate interrupt sources. I count 8 for PortB, and 3 for
the INTx pins. That's 11. There are some tricks you can do with the
hardware peripherals to emulate an edge triggered interrupt pin, but
I don't know if you want to do that. It would be better, I think, if you
used an external combiner circuit and fed it into one of the INTx pins. |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Mon Jan 16, 2012 5:45 pm |
|
|
PCM programmer wrote: | There are some tricks you can do with the
hardware peripherals to emulate an edge triggered interrupt pin, but
I don't know if you want to do that. It would be better, I think, if you
used an external combiner circuit and fed it into one of the INTx pins. |
any form of trick is what trying, how can i achieve that?
Best regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Jan 16, 2012 6:03 pm |
|
|
Simplest 'trick' is to create a 15 wide diode OR gate connected to RB0. If you also need to know WHICH intput caused the interrupt, tie each line to an input pin.Providing the pin stays low long enough, the ISR will have enough time to read the 2 ports the inputs are connected to.
Only you know the timing requirements. Easy to test.
Next on the list, you could use a 16:4 demux chip attached to PORTB7.4. You actually get 16 interrupts but will cost you 1 extra chip.The benefit is only 4 PIC pins are used,fast testing of 'who it was'. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2012 6:03 pm |
|
|
There is the well-known method of setting Timer1 to 0xFFFF and then
when it gets a positive edge on the External clock input, it rolls over
to 0x0000 and generates an interrupt. Except it won't work for your
application because you want an interrupt on the falling edge.
You could probably get an interrupt from the comparator.
But I still say it's easier to do an external Wire-OR circuit with diodes.
See this Wikipedia article:
http://en.wikipedia.org/wiki/Wired_logic_connection
Look at the diagram with the two diodes and the pull-up. 'A' and 'B' are
inputs and C is the output. You can add more diodes to get more inputs.
It would be so easy to do it this way. You don't have to do it for all the
signals. Just do it for the ones that are not on PortB and on the INTx pins.
Though, you would need to reserve one INTx pin for the Wire-OR circuit. |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Mon Jan 16, 2012 8:16 pm |
|
|
temtronic wrote: | Simplest 'trick' is to create a 15 wide diode OR gate connected to RB0. . |
Thanks so much,it reminds me of my basic electronic course I had in school, with this i should be able to maneuver my way around.would keep you posted of any new development.
Best regards. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2012 8:26 pm |
|
|
The diodes should be Schottky diodes, because of their low voltage drop. |
|
|
balmer
Joined: 31 May 2010 Posts: 6
|
|
Posted: Tue Jan 17, 2012 1:58 pm |
|
|
What you should use is a "Wired AND connection" isof a OR.
Cheers |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 17, 2012 2:03 pm |
|
|
I agree that technically that's what it is, since any 0 in will give you a 0 out.
But it seems like that generic idea of using diodes to make a gate is
always referred to as "Wire-Or'ed". |
|
|
balmer
Joined: 31 May 2010 Posts: 6
|
|
Posted: Tue Jan 17, 2012 2:08 pm |
|
|
I agree with that "nomenclature".
My humble comment had the intention of highlighting the correct circuit to be used, just in case ;-) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Wed Jan 18, 2012 2:38 am |
|
|
The key is that the signals are using -ve logic.
For -ve logic, the gate is a 'wire or', and hence the traditional nomenclature.
Historically things like interrupt inputs have for a long time used -ve logic (since they were often driven by open collector drivers).
Best Wishes |
|
|
|