+ Reply to Thread
Results 1 to 10 of 10

Thread: Interrupts or not interrupts ? That is the question !

  1. #1
    ZERS Newbie
    Join Date
    Mar 2004
    Location
    FRANCE
    Posts
    43

    Default Interrupts or not interrupts ? That is the question !

    Hi,

    I'm designing a controller board for a CD PLAYER.
    The controller is based around a PIC18F452.

    I'm wondering whether I need to use interrupts or not.

    To sum up, while playing (or not), the PIC could received instructions from a RC5 remote control or a switch board (buttons PLAY, STOP, SKIP FWD, ...)

    Do I need to use interrupts to check whether a switch or a RC5 code is received by the PIC ?

    Or do I include two Functions in the main loop that checks every 20ms if some RC5 code is reveived or some button is pressed.

    I'm developping the code ic C.

    Could be something like this

    Code:
    void main(void)
    {
      InitializeControler();
      while(1)
      {
        detectButtons(); //detect if a buttons is pressed
        detectIRCode(); //detect if a RC5 code is recevied    
        waitFor(20); //delay of 20ms
      }
    }
    

    thanks for your help

    Regards
    It\'s better to burn out than to fade away


  2. #2
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,759

    Default Re: Interrupts or not interrupts ? That is the question !

    Quote Originally Posted by ZERS
    Hi,

    I'm designing a controller board for a CD PLAYER.
    The controller is based around a PIC18F452.

    I'm wondering whether I need to use interrupts or not.

    To sum up, while playing (or not), the PIC could received instructions from a RC5 remote control or a switch board (buttons PLAY, STOP, SKIP FWD, ...)

    Do I need to use interrupts to check whether a switch or a RC5 code is received by the PIC ?

    Or do I include two Functions in the main loop that checks every 20ms if some RC5 code is reveived or some button is pressed.
    You can do it either way, it's mostly personal preference, although there are sometimes circumstances where you HAVE to use interrupts.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  3. #3
    Super Moderator Jay.slovak Good Jay.slovak Good Jay.slovak Good
    Join Date
    Jan 2005
    Location
    Slovakia
    Posts
    1,740

    Default

    Useing interrupts is generaly a faster and more relyable solution. If you use normal checking in software, let's say every 20ms, you might miss an event... Integrating interrupts into your existing code is easy, no need to wory...

  4. #4
    ZERS Newbie
    Join Date
    Mar 2004
    Location
    FRANCE
    Posts
    43

    Default

    Quote Originally Posted by Jay.slovak
    Useing interrupts is generaly a faster and more relyable solution. If you use normal checking in software, let's say every 20ms, you might miss an event... Integrating interrupts into your existing code is easy, no need to wory...
    Could you please give me an example ?

    I do not understand how deal with the timer while using interrupts, more precisely while there are two sources of interrupts...

    One source using A/D conversion (the switches board), the other one the RC5 codes
    It\'s better to burn out than to fade away

  5. #5
    Super Moderator Jay.slovak Good Jay.slovak Good Jay.slovak Good
    Join Date
    Jan 2005
    Location
    Slovakia
    Posts
    1,740

    Default

    If you use multiple sources for interrupt, you need to add checking of Flag Bits. You should check T0IF & ADIF flag bits.... and then execute correct interrupt routine. Yes, there is a chance that you will get A/D interrupt and Timer interrupt at the same time, If you use PIC18 series, you can use priority levels to solve this issue..

  6. #6
    ZERS Newbie
    Join Date
    Mar 2004
    Location
    FRANCE
    Posts
    43

    Default

    Quote Originally Posted by Jay.slovak
    If you use multiple sources for interrupt, you need to add checking of Flag Bits. You should check T0IF & ADIF flag bits.... and then execute correct interrupt routine. Yes, there is a chance that you will get A/D interrupt and Timer interrupt at the same time, If you use PIC18 series, you can use priority levels to solve this issue..
    After reading the datasheet, it seems that I will set the "A/D" conversion in high priority and the RC5 in low priority.

    Still after reading the datasheet, It might be interesting to use the Timer Interrupts (reading the timer value to check if the PIC is stiuck), thus introducing a third source of interrupt.

    Is it possible ?
    It\'s better to burn out than to fade away

  7. #7
    Super Moderator Jay.slovak Good Jay.slovak Good Jay.slovak Good
    Join Date
    Jan 2005
    Location
    Slovakia
    Posts
    1,740

    Default

    Quote Originally Posted by ZERS
    Quote Originally Posted by Jay.slovak
    If you use multiple sources for interrupt, you need to add checking of Flag Bits. You should check T0IF & ADIF flag bits.... and then execute correct interrupt routine. Yes, there is a chance that you will get A/D interrupt and Timer interrupt at the same time, If you use PIC18 series, you can use priority levels to solve this issue..
    After reading the datasheet, it seems that I will set the "A/D" conversion in high priority and the RC5 in low priority.

    Still after reading the datasheet, It might be interesting to use the Timer Interrupts (reading the timer value to check if the PIC is stiuck), thus introducing a third source of interrupt.

    Is it possible ?
    Are you trying to detect when the PIC is stuck? Theres a feauture call WDT watchdog timer.... that might be more usefull.

  8. #8
    ZERS Newbie
    Join Date
    Mar 2004
    Location
    FRANCE
    Posts
    43

    Default

    Quote Originally Posted by Jay.slovak
    Are you trying to detect when the PIC is stuck? Theres a feauture call WDT watchdog timer.... that might be more usefull.
    Yes, especially while testing the program.
    I've never seen any program without a bug, especially developped by me :wink: :lol:
    It\'s better to burn out than to fade away

  9. #9
    motion Newbie
    Join Date
    Jul 2003
    Location
    Quezon City.PH
    Posts
    560

    Default

    Do I need to use interrupts to check whether a switch or a RC5 code is received by the PIC ?
    Using interrupts for switch detection would make it prone to switch bounce. Switch debounce software will totally negate using interrupts for switches in the first place. In general, switch events are so slow, polling offers a natural debounce. A user will not notice any sluggishness even if you poll switches once every 50-100ms.

    IR remote sensors are in the gray area where polling or interrupts can be used. I have used a polling method on a karaoke machine with an IR remote sensor, LED displays, pushbuttons, etc. It used an ancient PIC16C57 @4Mhz but was fast enough to poll the IR sensor every 256usec. This chip had no interrupts so I had no choice but to poll.
    "Having to do with Motion Control"

  10. #10
    Oznog Excellent Oznog Excellent Oznog Excellent Oznog Excellent Oznog Excellent
    Join Date
    Apr 2004
    Location
    Austin, Tx
    Posts
    2,765

    Default

    Bounce is just as easily removed by a counter inhibiting the action when you're using interrupts. The interrupts do catch button presses faster and are a pretty good solution. Also, if you want to implement a Sleep mode (and you probably do!) a button interrupt is the best way to wake it. Polling would be hard and raise the average current a lot, you'd have to configure an internal osc to wake the part every 50 ms or so to poll for a button press.

    You don't want to use a timer interrupt to reset the WDT to prevent hanging- there is a good chance an electrical problem could corrupt the variable space or program counter without breaking the timer interrupts, leaving it happily servicing broken code. You want to reset the WDT when something meaningful was accomplished.

    Multiple interrupt do not require the use of the interrupt prioritization on the 452. The ISR will simply have code for "if(INT0IF) { routine0}" and then "if(ADIF){routine1}". If responding to one very quickly is important, you want to put that routine first. If it's very critical, then you may want to implement the prioritization. I used High Priority for a high speed tachometer interrupt because there was a remote possibility that other multiple interrupts could take so long to handle that a second tach interrupt event could theoretically occur before the first one was serviced and thus fail to be counted. Usually this is not the case.

+ Reply to Thread

Tags for this Thread