I've been using tmr1 to generate 'beeps' of different frequencies, feeding a piezo 'speaker', and toggling two I/O pins to give a bridged output from within the ISR.
However, after having to reduce the clock frequency (from 64MHz to 16MHz) on one of the units the beep ended up being more of a 'squawk' some of the time
I concluded this was due to the number of interrupts actually in use, as there's quite a few.
So I decided, why not use the NCO (Numerically Controlled Oscillator) module?- then I had two issues, firstly I still wanted the bridged output (but didn't want to toggle the pins in the ISR for the same reason as before - as the NCO is hardware, the ISR routines won't affect it), and secondly the NCO output couldn't be set via PPS to the port (port B) that I was using for feeding the beeper.
So more studying - and I found the CWG (Complementary Waveform Generator), which can be fed from the NCO output and with the CWG set to 'half bridge mode' produces the required bridged output. Even better, there are a number of different CWG modules available, and between them all available ports are covered by PPS.
So a little bit of coding, and it all works great - just set the frequency you want for the beep - and it runs independently from the processor - you just need to turn it ON and OFF for the duration of the beep, which is already done for the previous tmr1 version anyway
However, after having to reduce the clock frequency (from 64MHz to 16MHz) on one of the units the beep ended up being more of a 'squawk' some of the time
I concluded this was due to the number of interrupts actually in use, as there's quite a few.
So I decided, why not use the NCO (Numerically Controlled Oscillator) module?- then I had two issues, firstly I still wanted the bridged output (but didn't want to toggle the pins in the ISR for the same reason as before - as the NCO is hardware, the ISR routines won't affect it), and secondly the NCO output couldn't be set via PPS to the port (port B) that I was using for feeding the beeper.
So more studying - and I found the CWG (Complementary Waveform Generator), which can be fed from the NCO output and with the CWG set to 'half bridge mode' produces the required bridged output. Even better, there are a number of different CWG modules available, and between them all available ports are covered by PPS.
So a little bit of coding, and it all works great - just set the frequency you want for the beep - and it runs independently from the processor - you just need to turn it ON and OFF for the duration of the beep, which is already done for the previous tmr1 version anyway