Ok, here's what I see with a PR value of 200....
(top green trace is main loop 'toggle', the lower yellow trace is interrupt 'toggle ....oh btw, ignore the spikes sitting on the square waves!)
now here it is with a PR value of 66....
Now, whilst I can understand the need to get a clean main loop (& establish what PR2 value yields that), I'm wondering here what's going on with the PR2 value ....does higher mean less interrupts? (ie should I be taking the PR2 value higher or lower)...cos whichever way I quickly experimented with I got an uneven main toggle trace!
oh & btw, how did you determine the port toggle took 7 instruction cycles a couple of posts ago?!!
I've pondered the end goal a little bit - an anlogue peak detect circuit emulator.
What's going on with a peak detector is that a cap charges up to reflect the value an AC signal....a diode stops the cap charge decrementing when the waveform traverses back towards zero - meanwhile there's another resitor in parallel across the cap that disharges the cap (at a t rate chosen by the circuit designer).
So I guess I need some code like this...
1. Take an ADC Sample (via a timer ...or special event trigger etc)
2. Is the present signal sample bigger than the last? ......if yes, then update a variable with the latest value, if not then do nothing.
Have another timer decrement the same variable (this is the discharge time)
Ought to be simple enough (once I get a grip on this interrupt frequency melarkey!).....and would stop the strong second harmonic presence messing up the overall results as seen when I put a guitar into the circuit.







Bookmarks