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.

Interrupt witin interrupt

Status
Not open for further replies.

AGCB

Member
I'm using a 16f84a PIC. Is it posible to allow for a TMR0 interrupt while serving a INT interrupt or do I need to accomplish this another way? Thanks Aaron
 
Hello,

yes sure , the interrupt flags (from TMR0/ INT) that you check first , thats the one who has the priority to.
 
When an interrupt is set and the program counter is directed to program ROM address 0x04, all unmasked interrupts are disabled by the hardware to prevent an interrupt from occuring while it's servicing the ISR (Interrupt Service Routine).

You can write code in the ISR that polls the TMR0 interrupt flag, then jumps to service the appropriate routine when the TMR0 interrupt flag gets set. Even though interrupts themselves are disabled until you return from the ISR, the interrupt flags still get set/cleared as they normally do and are still available for polling.

What is it exactly that you're trying to do? If you could tell us this we will be able to better assist you.
 
Last edited:
It is possible to do but difficult and fraught with dangers. As Jon said, what are you trying to do, as there is probably a simpler way to do it.

Mike.
 
I'm using two interrupts in this program. One uses TMR0 thru RB4/tock1 to count motor shaft revolutions and turn off power to the motor at the correct time. The other, a INT, detects a falling edge on a 555 timer timeout to end the program and turn off power to a relay which powers everything including the PIC. During this second interrupt, it has to again run the same motor and count revolutions in the opposite direction. I've tryed to attach the ISR code, hope it works. Thanks. Aaron
 

Attachments

  • ISR camera3.txt
    1.8 KB · Views: 127
Well there's not enough code there to make any sense of it, the ISR on it's own is useless - but why are you using a 555 for anything?, why can't the PIC also do that?.
 
From what I can see, your ISR code only disables TMR0 interrupts when the right number of shaft revolutions occurs but there doesn't appear to be any code in the ISR that tells the motor itself to turn off after "X" number of shaft revolutions.

Also, like Nigel asked, what is the purpose of the 555 timer?

Any chance you can post the entire code including the ISR? It would greatly aid us in assisting you with this.
 
Last edited:
This is a game trail camera made with an old VCR camcorder. The 555 is triggered by a motion sensor circuit and times the record length of 1/2 - 3 minutes (adjustable). A second 555 timer prevents retriggering for 2-20 minutes (adjustable) to prevent continiuos recording thereby saving battery life. The camera controles are operated mechanically by small motors controlled by the PIC. This project is close to done, many bugs have been fixed and everything works MOST of the time. The MOST is the problem as it is not yet fool proof . I will post the entire code but please give me a break as 8 months ago I did not know what a PIC or any other uC was. I like helpful coments but ! Thanks
 

Attachments

  • camera3.asm
    8 KB · Views: 121
This is a game trail camera made with an old VCR camcorder. The 555 is triggered by a motion sensor circuit and times the record length of 1/2 - 3 minutes (adjustable). A second 555 timer prevents retriggering for 2-20 minutes (adjustable) to prevent continiuos recording thereby saving battery life. The camera controles are operated mechanically by small motors controlled by the PIC. This project is close to done, many bugs have been fixed and everything works MOST of the time. The MOST is the problem as it is not yet fool proof . I will post the entire code but please give me a break as 8 months ago I did not know what a PIC or any other uC was. I like helpful coments but ! Thanks

So you have two spurious 555's :D

It would make more sense to perform their functions in the PIC.
 
Problem is the 16F84 only has 1 timer/counter. However, the 16F628 has 3 timer counters, is pin and code compatible with the 16F84 (with the exceptions of the config word and having to disable the on chip comparator in the port config code) and costs less than the 16F84. The 628 can be thought of as a "super 16F84" and I feel it is a far better choice over the F84. I've worked with this chip for the last few months and it is an awesome chip to use for small projects such as this. Then you can get rid of your 555 timers and have the PIC do it all.
 
Last edited:
Apart from hardware though, would the main and delay timer be adjustable in the field w/o reprograming. With the 555 I just use a POT
 
You can by using an encoder wheel instead of a pot. Have the encoder wheel set 1 input pin low momentarily when rotated 1 way while setting a different pin low momentarily when rotating it in the opposite direction. When encoder pin 1 is set low it increments the timer register by a factor of 1. When encoder pin 2 is set low it decriments the timer counter register by a factor of 1.
 
Or upgrade to the 16F88 which has an A/D (handy for the pot)
You can also read pots from a digital I/O pin, the BASIC Stamps used this method.
 
You can by using an encoder wheel instead of a pot. Have the encoder wheel set 1 input pin low momentarily when rotated 1 way while setting a different pin low momentarily when rotating it in the opposite direction. When encoder pin 1 is set low it increments the timer register by a factor of 1. When encoder pin 2 is set low it decriments the timer counter register by a factor of 1.


Can you point me to more info or a tutorial on this? Thanks.
 
Thanks! I have some more reading and experimenting to do. Also need to order more toys. Aaron
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top