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.

PIC16F876A Interrupt instability

Status
Not open for further replies.

hantto

Member
Hi!

I'm building a colororgan with a PIC. I'm imlpementing a lamp brightness control using interrupts. I have a zerocrossing detector's output hoocked up to RB5 and I'm using the interrupt on change to turn off the lamp at the moment zero cross is detected.
To control the period I'm using Timer2. I.e. in the PortB interrupt I start Timer2 (which also has the interrupt configured on) and quit the interrupt. When Timer2 has run for a while (<10mS, 50Hz mains) set by RP2, it interrupts and turns the lamp off. That's the background on my program.

Now to the point. I've noticed that if I have the interrupts on it induces an instability on the PIC. About 30% of the times I apply power, it won't start running, just sits there and does nothing. If it starts to run it sometimes stops running. I don't know why this happens. If I turn the interrupts off this behaviour dissapears.

One more interesting point is that if I only have one of the interrupts on (PortB or Timer2) it doesn't do the thing described above as often, but still does it.

I've written the code twice from the beginning, incase I did something stupid the first time. But the problem still persists. I've used interrupt (and many other) routines known to work (most of them Nigel's) so there should be nothing wrong with them. And I cannot see any error in my code (attached below)

What could be the source of this behaviour? And more importantly, how to get rid of it?

P.S. I've tried with two 16F876A's and i'm using ICD as the programmer.

Thank you for your time!
 
Last edited:
you have both interrupts and timers set running before you have finished your initialisation, be careful they are not constantly interrupting each other as a result of something else not being correctly set before they go active
 
Consider what happens when an interrupt occurs and you are not in bank 0.

Try clearing RP0 and RP1 in your interrupt just after the line movwf P_Temp. You might also consider clearing PCLATH - it doesn't matter at the moment but if your code gets bigger you could have problems.

Mike.
 
Haha! I feel dumb. It turns out that I didn't have any decoupling caps to the PIC. I indeed have some caps in the circuit but none of them were connected over the rails. These things happen when you overlook the obvious (or do these things 1:30 at night) :p

Thanks for those suggestions tough! They will undoublty be usefull in similar situations in the future.
 
You really are dumb. I identified your error. In your main code you switch to bank 1, in your ISR you assume bank 0. You are either too stupid or too arrogant to acknowledge that.

I hate people that don't admit their errors.

Mike.
 
Pommie said:
You really are dumb. I identified your error. In your main code you switch to bank 1, in your ISR you assume bank 0. You are either too stupid or too arrogant to acknowledge that.

I hate people that don't admit their errors.

Mike.

I aknowledge that, and I did alter my code, and now it works. Thank you.

Yes, it sounds in my reply that the caps were tha main fault.

Pommie, I direct respect in your way, YOU are the reason my code works, thank you!

(hope it didn't sound too arrogant or stupid this time :))
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top