Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nice to have extra peripherals in PIC's

Nigel Goodwin

Super Moderator
Most Helpful Member
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 :D

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 :D
 
You didn't mention exactly which device you're using, but if you have one with CLC modules (configurable logic cells) you might be able to use those to "move" the NCO output to a different port. A CLC could also invert the signal to get the complimentary output too.

You have to watch out since not all signals can go to all ports with PPS, so you could end up right where you started!
 
You didn't mention exactly which device you're using, but if you have one with CLC modules (configurable logic cells) you might be able to use those to "move" the NCO output to a different port. A CLC could also invert the signal to get the complimentary output too.

I was considering trying to use the CLC when I came across the CWG, which seemed a far better (and simpler) idea. The particular devices in question are the 16F18857 and the 18F27K42, but these peripherals are fairly universal across 'modern' PIC's.

You have to watch out since not all signals can go to all ports with PPS, so you could end up right where you started!

The multiple CWG's seem to allow all ports between them :D - avoiding the issues with other peripherals (such as the NCO).
 

Latest threads

New Articles From Microcontroller Tips

Back
Top