CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

interrupts again!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
flint



Joined: 05 Jun 2010
Posts: 24
Location: Nigeria

View user's profile Send private message

interrupts again!
PostPosted: Mon Jan 16, 2012 5:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 5:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 5:45 pm     Reply with quote

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: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 6:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 6:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 8:16 pm     Reply with quote

temtronic wrote:
Simplest 'trick' is to create a 15 wide diode OR gate connected to RB0. .


PCM programmer wrote:
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


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

View user's profile Send private message

PostPosted: Mon Jan 16, 2012 8:26 pm     Reply with quote

The diodes should be Schottky diodes, because of their low voltage drop.
balmer



Joined: 31 May 2010
Posts: 6

View user's profile Send private message

PostPosted: Tue Jan 17, 2012 1:58 pm     Reply with quote

What you should use is a "Wired AND connection" isof a OR.

Cheers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 17, 2012 2:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 17, 2012 2:08 pm     Reply with quote

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: 19546

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 2:38 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group