Hi,
Interrupt frequency of 39060Hz?
Previously you said you wanted an output of 120Hz and with 72 steps per sin-cycle that's 120*72=8640Hz interrupt frequency. The math is then like this
65535 - (10,000,000 / 8640) + 1 = 64378
64378 is what the timer reload value is and this means that there's 65536-64378=1158 cycles between interrupts. 1158 cycles times 100ns per cycle equals 115.8us between interrupts 1/115.8us = 8635Hz so it's pretty close.
This means that there's only 1158 cycles (or instructions if you will) between interrupts. In this time the PIC has to save all the PBP system variables, reload the timer, execute your interrupt service routine and then restore all the PBP system variables.
Why are you trying to interrupt at ~39kHz? That's only about 256 cycles between interrupts which I'm pretty sure won't be enough time to do all that needs to get done in the interrupt.
Finally, this line:Probably doesn't work like you think. Here, Flag gets set no matter what the state of of PortC.4 actually is. So you are always running the recalc routine. If you want Flag to be set only when PortC.4 is high you need to change it to:Code:If PortC.4 = 1 Then InterruptFrequency = InterruptFrequency -1 : Flag = 1Code:If PortC.4 = 1 THEN InterruptFrequency = InterruptFrequency - 1 Flag = 1 ENDIF




Bookmarks