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!
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: