PIC16F18446 Tone Generator Using the NCO
Check out this project's MPLAB Xpress Webpage to view the complete code example along with a detailed step by step write-up and description, or visit the PIC16F18446 Device Product Page for more information.
About this Code Example
In this project I use the NCO of the PIC16F18446 to generate a square wave with a desired frequency.
In this demo,
- PIC16F18446 (20-pin, PDIP) MCU is used to generate an adjustable frequency square signal.
- The Curiosity development board is used as it has got on-board programmer and debugger.
- A set of headphones in used to hear the output sound.
The frequency is adjusted using the POT1 on the Curiosity Board. The POT1 is read using the PIC's ADCC. In order to hear the sound, the headphone set must be connected in series with 1k resistor to RC1 and GND.
Make sure the latest MCC libraries for PIC16F18446 MCU are installed. The demo/example uses the following version of software tools from Microchip:
- MPLAB® X IDE v4.15
- MPLAB® Code Configurator (Plugin) v3.55.1
- MCC Core v4.35
- Microcontrollers and peripherals Library v1.65.1
Demo Hardware Setup
- Plug the PIC16F18446 MCU into its socket on the Curiosity board
- Connect a set of headphones in series with 1k resistor to RC1 and GND
This section shows the settings used in the demo/example for various MCU modules configuration. These settings were done using the Microchip Code Configurator (MCC). Open MCC to look at the settings of the modules.
System Module Settings
The MCU uses the high frequency internal oscillator (HFINTOSC), and the clock is set to 8 MHz. Watchdog Timer is not used in this demo, so it is disabled.
ADCC is used to read the POT1. It is configured to operate in basic mode, with a clock of Fosc/64.
NCO1 is used to generate the square signal on a specific frequency. It is configured to operate in fixed duty cycle (FDC) mode, with output active high, and clock source Fosc.
Pin Manager Settings
The pins are configured as follows:
- ADCC input on RC0, named channel_ANC0
- NCO1 output is connected to pin RC1
- After making the above hardware connections, connect the headphones in series with 1k resistor to RC1 and GND.
- Connect the Curiosity board to PC using the USB cable.
- Build demo firmware and load the generated hex file onto the PIC16F18446 MCU. When the demo firmware is loaded, a tone will be heard in the headphones.
- Move the POT1 to adjust the tone frequency.
This example shows how easy it is to use the PIC16F18446 and MCC to make a simple tone generator.
- Dec 4, 2018