This doesn't sound to good. lets see if it makes sense: PR2=8 means every time TMR2 counts to 8, an interrupt should fire and TMR2 gets reset. with PR2=66, you had ~30K. So remember the main thats approx 7 clock ticks(clock ticks = instructions, so as not to continue confusing everyone). The math remains the same, for TMR to count to 8 thats 4uSec! 1/.000004 = 250K, not 22K. So my guess is you are going too fast. what was mains frequency? start back at PR2=66 and increase it. see if the INT gets slower, until it is 20K. At PR2=200, I think you were at 15K? so just guessing, maybe a value of ~130?
Now about that ADC time. I haven't read the errata, but did it say not to run faster then 8mHz or not to run the ADC faster? I ask because I saw something about the speed of the ADC implying there is a prescaler for that so maybe you could run at 32mHz?
I don't know much about this, I will have to think on it tonight when I get home from work.I'm thinking about putting the 'capacitor discharge' emulation into the same interrupt, so something high level like this...
(I will use a variable called previous_sample to store highest ADC sample)
1. does present incoming ADC sample equal (or is greater than) previous_sample.
i)if so previous_sample = present incoming sample .....& retrun
ii) if not, decrement previous_sample by '1' & return
with an ADC sample of 8 bits, the maximum signal sample is 255.....the maximum pseudo discharge time will be the interrupt rate (22khz) * 255, therefore about 12ms (which is nicely tied in with the lowest frequency 'cycle' on a guitar @82Hz)....sound about right?
Bookmarks