CCS News

New Devices, New Peripherals, New Built-in Functions

Monday 15 July, 2013

CCS, Inc. C Compiler Version 5 supports Microchip's PIC10F®, PIC12®, PIC16F® 8bit peripherals. These peripherals include: Numerically Controlled Oscillator(NCO), Pulse-Width Modulation(PWM), Complementary Waveform Generator(CWG), Configurable Logic Cell(CLC), and Data Signal Modulator(DSM). In a two-part series we will cover these PIC® peripherals within C Compiler Version 5.

The Numerically Controlled Oscillator (NCO) module is a new peripheral that is supported by CCS C compiler. The NCO module is a timer used to generate a fixed duty Pulse-Width Modulation(PWM) or a pulse at a specific frequency. The NCO uses the overflow from the addition of an incremental value to divide the input frequency. The advantage of this is that the resolution of division does not vary with the divider value, making the NCO useful for applications that require frequency accuracy and fine resolution at a fixed duty cycle.

CCS C compiler makes it easy to setup and use the NCO module by providing several built-in functions including setup_nco() and set_nco_inc_value(). The setup_nco() function is used to enable, setup and set the increment value of the NCO module, and the set_nco_inc_value() function can be used to adjust the increment value of the NCO module. Adjusting the increment value of the module changes the frequency outputted by the module. When operating in fixed duty mode the frequency of the NCO module can be calculated with the following equation:

Frequency = (NCO Clock Frequency * Increment Value)/(2^21)

When operating in pulse frequency mode the frequency of the NCO module can be calculated with the following equation:

Frequency = (NCO Clock Frequency * Increment Value)/(2^20)

The following is a simple example program which sets up the NCO module in fixed duty mode at an initial frequency of 1 kHz. Every 5 seconds the program increases the period by 1kHz to a maximum of 16kHz and then repeats:

#include <16F1507.h>
#fuses NOWDT
#use delay(internal=16MHz)

#define INC_1KHZ 131072

void main() {
unsigned int8 i=2;


while(TRUE) {

set_nco_inc_value(((unsigned int32)(i) * INC_1KHz) / 1000);

if(++i > 16)
i = 1;

Another new peripheral that is supported by the CCS C compiler is the Complementary Waveform Generator (CWG) module. This peripheral can be used in conjunction with several other peripherals including the PWM and NCO modules to generate a complementary PWM with dead-band delay and auto-shutdown control. The CCS C compiler make it easy to setup and use the CWG module by providing the built-in function setup_cwg(). The setup_cwg() function is used to enable, set-up, and set the dead-band delay time of the CWG module. The period, frequency, and duty of the complementary PWM depends on the input signal to the CWG module. The previous example can be easily modified to enable the CWG sourced by the NCO module with a dead-band delay of 10 for both the rising and falling edges by adding the following to the program:


In part two of this series, next week, we will discuss the new Configurable Logic Cell (CLC) and Data Signal Modulator (DSM) peripherals which are also supported CCS C compiler.

We invite to learn more about CCS C Version 5 by pointing your browser to:

Like us on Facebook and follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries. REAL ICE™, ICSP™ and In-Circuit Serial Programming™ are trademarks of Microchip Technology Inc. in the U.S. and other countries