PDA

View Full Version : Stop program



Sam
- 29th March 2004, 00:24
Hi,

I am trying to stop the main program when the 16F628A senses a momentary high on two inputs. I have tried a IF...Then loop and it has not achieved the needed result.

I need to stop the main program dead in it's tracks,is using interrupts the way to go on this ?

Thanks for any info
Sam

Melanie
- 29th March 2004, 13:08
> is using interrupts the way to go on this ?

Not necessarily. You may be making life more complicated as you still have to work out what and how many pins have caused the interrupt. Remember that an interrupt isn't serviced until the current command has executed, so by the time you get to looking at the interrupt flag, you may miss the pulse on the next pin. If both pins are going to cause an interrupt, then the interrupt flags WON'T tell you that they happened simultaneously.

You need to AND the two pulses together and then trigger an interrupt. This will work, but remember the delay between completion of the last command being executed and servicing the interrupt.

If you use a PIC with comparators, and both pulses are the same level, then you can use those instead of any external AND gates. If the pulses are not the same level then you can still use the comparators but a little more magic is needed.

Finally, if you want to stop your processor dead, IMMEDIATELY, then the AND gate (or Comparator) connected to the MCLR pin is the way to go...

Sam
- 30th March 2004, 15:57
Thank you Melanie,

You provided the exact info I needed.I had thought about the MCLR but not using an AND to activate it. After reading your reply I used a PIC12F675 to perform the AND to trigger the MCLR on the 16F628. Works perfect !

I guess a 12F675 may be overkill for a AND gate, but I needed the timing function of it to keep MCLR low for an extended period. I am not sure about using the same 16F628 as an AND as I am using several of the I/O as digital for the main program.

Thanks again, your knowledge is appreciated,
Sam