Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupts or not interrupts ? That is the question !

Status
Not open for further replies.

ZERS

New Member
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
 
ZERS said:
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.
 
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...
 
Jay.slovak said:
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
 
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..
 
Jay.slovak said:
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 ?
 
ZERS said:
Jay.slovak said:
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.
 
Jay.slovak said:
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:
 
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.
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top