Numerically Controlled Oscillator

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.

NCO.png

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:

NCO_formula.png

NCO Video Tutorial

This video introduces the Numerically Controlled Oscillator (NCO) for Microchip 8-bit MCU devices and shows how to use it.


NCO Modes

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

NCO_modes.png

The NCOCON register controls the mode setting for the NCO.

ncocon.png

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.png

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.png

Accumulator

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:

  • NCOxACCL
  • NCOxACCH
  • NCOxACCU
NCO_accumulator.png

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

Adder

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.

NCO_400_animated.gif

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.

  • NCOxINCL
  • NCOxINCH
NCO_adder.png

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.

Clock Sources

Clock sources available to the NCOx include:

  • HFINTOSC
  • FOSC
  • LCxOUT
  • CLKIN pin

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

NCO_clock.png

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

Output

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.png

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

NCO_output.png

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

Interrupt

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.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.