8-bit PIC® MCU Numerically Controlled Oscillator (NCO)

Last modified by Microchip on 2023/11/09 09:03

The Numerically Controlled Oscillator (NCOx) module is a timer that uses the overflow of an accumulator to create an output signal. The accumulator overflow is controlled by an adjustable increment value rather than just a single clock pulse or postscaler increment. This offers an advantage over a simple timer-driven counter in that the resolution of division does not vary with the somewhat limited prescaler/postscaler divider value. The NCOx is most useful for applications that require frequency accuracy and fine resolution at a fixed duty cycle.

Features of the NCOx include:

  • 16-bit increment function
  • Fixed Duty Cycle (FDC) mode
  • Pulse Frequency (PF) mode
  • Output pulse width control
  • Multiple clock input sources
  • Output polarity control
  • Interrupt capability

The NCOx operates by repeatedly adding a fixed value to an accumulator. Additions occur at the input clock rate. The accumulator will overflow with a carry periodically, which is the raw NCOx output. This effectively reduces the input clock by the ratio of the added value to the maximum accumulator value.


The NCOx output can be further modified by stretching the pulse or toggling a flip-flop. The modified NCOx output is then distributed internally to other peripherals and optionally output to an I/O pin. The accumulator overflow can also generate an interrupt. The NCOx period changes in discrete steps to create an average frequency. This output depends on the ability of the receiving circuit (i.e., CWG or external resonant converter circuitry) to average the NCOx output to reduce uncertainty.

The overflow of the NCO module is based on the formula below:

overflow of the NCO module formula

Back to top

NCO Modes

The NCO module can output a signal in one of the two modes.

NCO Modes

The NCOCON register controls the mode setting for the NCO.


Back to top

Fixed Duty Cycle

The Fixed Duty Cycle mode toggles the output on every accumulator overflow. As long as the adder value and clock don't change, this will result in a 50% duty cycle output.

NCO duty

Back to top

Pulse Frequency Modulation

The Pulse Frequency Modulation mode will trigger a pulse on every accumulator overflow for a period set by three bits in the NCOCON register.

NCO pulse

Back to top


The accumulator is a 20-bit register with a maximum value of 1,048,575. Read and write access to the accumulator is available through three registers:


NCO accumulator

When the accumulator overflows, the output of the NCO module will change state.

Back to top


The NCOx adder is a full adder, which operates independently from the system clock. It adds the value of the increment value to the accumulator on each NCO clock pulse. The adder takes the value in the accumulator and then adds the increment value. The result is placed back in the accumulator. The accumulator value will roll over and any value beyond the 1,048,575 will get placed as the starting value in the accumulator.

This can be reset if desired by writing a zero to the accumulator. This is typically done within the interrupt service routine if that is enabled on the NCO module.

Accumulator Overflow Animation

Back to top

Increment Registers

The increment value is stored in two 8-bit registers making up a 16-bit increment value. The lower 8-bits are in the NCOxINCL register and the upper 8-bits are in the NCOxINCH register.


NCO adder

Both of the registers are readable and writeable. The increment registers are double-buffered to allow for value changes to be made without first disabling the NCOx module. The buffer loads are immediate when the module is disabled. Writing to the NCOxINCH register first is necessary because then the buffer is loaded synchronously with the NCOx operation after the write is executed on the NCOxINCL register.

Back to top

Clock Sources

Clock sources available to the NCOx include:

  • FOSC
  • LCxOUT
  • CLKIN pin

The NCOx clock source is selected by configuring the NxCKS<2:0> bits in the NCOxCLK register.

NCO clockk

The HFINTOSC selection will continue to run even if the device is put into sleep mode.

Back to top


The output of the NCO has several options that can be set in the NCOCON register.

The output can be enabled or disabled (NxOE bit) and also inverted (NxPOL bit) by setting or clearing bits in the NCOCON register.

NCO outstate

The output can also be monitored in software by reading the state of the NxOUT bit in the NCOCON register.

NCO output

The NxEN bit can disable the whole NCO module. The setting of '1' enables the module and a setting of '0' disables it.

Back to top


The NCO output can trigger an internal interrupt when the accumulator overflows. This is handled by three bits (GIE, PEIE, NCOxIE) in the set of registers shown below. This will allow the NCO to control software actions through the interrupt service routine in the application code while also outputting a signal to an I/O pin.

GIE is the Global Interrupt Enable bit.
PEIE is the Peripheral Interrupt Enable bit.
NCOxIE is the NCO Interrupt Enable bit. There can be multiple NCO modules. The "x" represents the NCO number.

The NCOxIF bit is the interrupt indicator flag. This can be monitored in the software to see if an interrupt has occurred. This needs to be cleared in the interrupt service routine or in the software routine that read the bit.

NCO interrupt

Back to top