CCS News RSS

Click here to view the PDF newsletters. Interested in receiving our newsletters in your inbox? Click here to subscribe.

Higher Accuracy PWMs with PIC16F1574 and PIC16F1764

Monday 14 March, 2016

Ever wanted more accuracy in the output of your PWMs? The new PIC16F1574 and PIC16F1764 family of devices both have a 16-bit PWM peripheral. The advantage of using a 16-bit PWM is that it increases the resolution of the PWM signal allowing for more precise duty cycles. Additionally each 16-bit PWM peripheral has an independent timer, this allows for generating the PWM without using one of the device's timers. The CCS C Compiler supports the new 16-bit PWM peripheral using either built-in functions or the #use pwm() library. The following is an example of how to use the #use pwm() library to setup the 16-bit PWM peripheral on a PIC16F1574:

#include <16F1574.h>
#fuses NOWDT

#use delay(internal=8MHz)

#use pwm(output=PIN_C3, frequency=122Hz, bits=16, duty=50)

void main()
{
for(;;);
}

Because the 16-bit PWM peripheral has an independent timer and registers for setting the PWM signal's phase and offset, the following built-in functions have been added to the CCS C Compiler to set the period, phase and offset:

SET_PWMx_PERIOD() //x being the PWM peripheral
SET_PWMx_PHASE() //x being the PWM peripheral
SET_PWMx_OFFSET() //x being the PWM peripheral

The following is an example of how to use the built-in functions to setup the 16-bit PWM peripheral:

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

#pin_select PWM1=PIN_C3

void main()
{
set_pwm1_period(0xFFFF); //8.192ms period, ~122Hz frequency
set_pwm1_duty(0x7FFF); //50% duty

setup_pwm1(PWM_STANDARD);

for(;;);
}

The new built-in functions are available in IDE compilers and the PCM command-line compilers starting with version 5.056.

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Using the Advanced Analog-to-Digital Converter (ADC) of the dsPIC33EPxxGS50x

Monday 14 March, 2016

There is a chance that you will need to read multiple analog signals at once or are the analog signals you are reading too small? The dsPIC3EPxxGS50x family of microcontrollers solve both of these problems, and the CCS C Compiler makes it easy to use. This family of chips have new ADC capable of sampling up to 5 analog inputs simultaneously. With the addition of two new functions for setting up the dedicated ADC cores, the Compiler makes it simple to read a single channel or multiple channels simultaneously. The following is an example of how to setup the ADC to read AN0 using the Dedicated ADC Core 0:

setup_adc_ports(sAN0, VSS_VDD);

setup_adc(ADC_CLOCK_SYSTEM | ADC_CLOCK_DIV_1 | ADC_WARMTIME_512);

setup_dedicated_adc(0, ADC_DEDICATED_CLOCK_DIV_2 |
ADC_DEDICATED_TAD_MUL_257 |
ADC_DEDICATED_CORE_CONV_DELAY);

set_dedicated_adc_channel(0, ADC_CHANNEL_AN0);

while(TRUE)
{
ADCReading = read_adc(ADC_START_AND_READ, 0);
...
}

Since the dsPIC33EPxxGS50x family of devices have individual Data Ready Status flags and Buffer registers for each analog channel, an optional second parameter was added to the read_adc() function to specify the channel to read. This allows for quicker reads with far less code generated to determine the flag to test and buffer to read.

Additionally the dsPIC33EPxxGS50x family have two Programmable Gain Amplifiers (PGA). The PGA is an op amp based non-inverting amplifier that can be used to amplify small voltages by 4x, 8x, 16x, 32x or 64x to improve the signal-to-noise ration of the measured signal. The PGA output voltage can then be read by one of the dedicated cores of the of the ADC, or used as an input to the Analog Comparator.

The new built-in functions are available in IDE compilers and the PCM command-line compilers starting with version 5.056.

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

New and Improved Development Boards!

Monday 14 March, 2016

Now available are two new development boards from CCS, the Rapid-18 and LPC Starter. CCS also has updated the PIC24 development boards to now include the PIC24FJ256GA106 and the PIC24EP256GP206.

The Rapid-18 uses the PIC18F4523 and has a built-in bootloader for loading code and a USB port for text communication to the running program, and provides advanced peripherals including a 12-bit ADC. The prototyping board features a PIC18F4523 attached to a potentiometer, two pushbuttons, three LEDs, and an ICD connector.

LPC Starter is designed to be an easy way to start software testing with the low pin count (8, 14, 18 and 20) parts that are not as easy to find on other development boards. This board provides standard IC sockets for DIP parts, access to all I/O pins, three LEDs, two buttons, one potentiometer, and a USB to RS-232 converter. Dip switches are used to connect or disconnect the USB port and to select internal or external (8Mhz) clock for the 14, 18 and 20 pin sockets.

CCS has also updated the devices to newer PIC24 devices for general development. The PIC24F board has the newer PIC24F256GA106 device that includes access to 53 I/O pins. The PIC24EP board has the PIC24EP256GP206 that includes 53 I/O pins, 16 analog pins and 2 RS-232 ports.

Click here to view all CCS Development Kits: http://www.ccsinfo.com/development-kits.php

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Using the CCS C Compiler with Analog-to-Digital Converters with Computation Module

Tuesday 07 June, 2016

Support has been added to the CCS C Compiler for the new Analog-To-Digital Converter with Computation (ADC2) module that the PIC16F188xx family of devices have. In addition to legacy mode of operation the ADC2 module can be setup in Accumulate, Average, Burst Average or Low-Pass Filter modes of operation. When setup for Accumulate mode with each trigger of the ADC the conversion result is added to the accumulator and the ADCNT register is incremented. When setup for Average mode with each trigger of the ADC the conversion result is added to the accumulator and when the specified number of triggers has been done the average will be preformed on the accumulator. When setup for Burst Average mode it is similar to Average mode the difference being that when the ADC is triggered, it will perform the specified number of conversions and then perform the average calculation. When setup for Low-Pass Filter mode with each trigger of the ADC the conversion result is sent through the filter.

To support the new modes of operation the CCS C Compiler's built-in setup_adc() function has been updated to setup the ADC in these modes. Additionally an optional second and third parameter as been added to the function to set some additionally settings when using these the new modes of operation. When using Accumulate, Average or Burst Average modes the second parameter sets how much the accumulated value is divided by after each conversion. When using Low-Pass Filter mode the second parameter sets the cut-off frequency of the filter. The third parameter to the function sets the number of samples to be done before performing a threshold comparison for Average, Burst Average and Low-Pass Filter modes of operation.

In addition to the updates to the setup_adc() function the built-in functions adc_write() and adc_read() have been added to write and read some the other registers used by the ADC2 module. For example when setup for Low-Pass Filter mode the filtered result is stored in the ADFLTRH and ADFLTRL registers. After the calculation is completed the adc_read() function can be then be used to read the filtered result, for example:

Result = adc_read(ADC_FILTER);

Another feature of the ADC2 module is the ability to set a trigger source to start a conversion. To support this feature the built-in function set_adc_trigger() has been added to the CCS C Compiler. For example the following can be used to setup the ADC2 module to trigger the conversion when Timer 2 period match occurs:

set_adc_trigger(ADC_TRIGGER_TIMER2);

The following is an example using the CCS C Compiler to setup and use the ADC2 module for Low-Pass Filter mode, see ex_lowpass_filter_adc2.c in the PICCExamples folder for entire example:

setup_timer_2(T2_CLK_INTERNAL | T2_DIV_BY_128, 155, 10); //~10ms period, 100ms interrupt

setup_adc_ports(ADC_PIN, VSS_VDD);
setup_adc(ADC_LOW_PASS_FILTER_MODE | ADC_CLOCK_INTERNAL | ADC_TAD_MUL_255 | ADC_THRESHOLD_INT_END_OF_CALCULATION, FILTER_CUT_OFF_FREQ, ADC_READINGS);

set_adc_channel(ADC_CHANNEL);
set_adc_trigger(ADC_TRIGGER_TIMER2);

while(TRUE)
{
if(interrupt_active(INT_AD_THRESHOLD))
{
FilteredResult= adc_read(ADC_FILTER);

clear_interrupt(INT_AD_THRESHOLD);
}
}

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Add Non-Volatile Storage to Any PIC® MCU with the virtual EEPROM driver

Tuesday 07 June, 2016

Looking to store settings or data in your embedded project, but you are using a PIC® MCU without an internal EEPROM and your design doesn't have an external EEPROM? The virtual EEPROM driver included in the CCS C Compiler adds the ability to use the PIC® MCU's re-programmable flash memory as data storage. This driver also performs write balancing, which allows the developer to write to a specific location several times without fear of wearing out the endurance of the flash memory. The virtual EEPROM driver recently was updated to add support for PIC16 and to optimize the memory usage when used on 8-bit PIC® MCUs (PIC16, PIC18, etc).

To add this library into your project, simply #include the file virtual_eeprom.c. The function init_virtual_eeprom() needs to be called to initialize access to the virtual EEPROM. write_virtual_eeprom() can be used to write a value to a location, and read_virtual_eeprom() can be used to read the value at a specified location. The last two erase pages of the PIC's re-programmable flash are used as storage for the virtual EEPROM system.

Here is an example of usage:

#include <virtual_eeprom.c>

void test_virtual_eeprom(void)
{
init_virtual_eeprom();
write_virtual_eeprom(0, 55);
write_virtual_eeprom(1, 65);
write_virtual_eeprom(2, 75);
printf("%urn", read_virtual_eeprom(0)); //should say '55'
printf("%urn", read_virtual_eeprom(1)); //should say '65'
printf("%urn", read_virtual_eeprom(2)); //should say '75'
}

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

NEW! ICD-U80 Programmer/Debugger

Friday 14 October, 2016

ICD-U80
Sku: 53506-1648
Price: $119

Introducing the new ICD-U80 Programmer/Debugger from CCS. The advantages of the ICD-U80 include:
  • Accelerated programming speed
  • Integrated Vdd generator to supply 1.5-5.5V to target
  • Software controlled power to target - no jumpers to change

Check out the complete line of CCS Programmer/Debuggers to fit your needs. http://www.ccsinfo.com/programmers-debuggers.php


Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Capture Event Timers with the CCS C Compiler

Tuesday 06 December, 2016

The Capture Compare (CCP) peripheral of the PIC16 and PIC18 PIC® MCUs and the Input Capture (IC) peripheral of the dsPIC and PIC24 PIC® MCUs allow the MCU to capture and hold a timer value when a specific input pin reaches a user defined state. This peripheral is useful for measuring the duration between events, or determining the frequency or duty cycle of an incoming signal. This peripheral operates independent of the MCU operation, meaning it can trap the timer on the input signal without the developer having to block code execution waiting for the input signal to happen.

Version 5 of the CCS C Compiler has added a #use capture() library that makes it easy to use the CCP or IC peripheral. The API for this library provides an easy to use method for using and configuring the peripheral and timers, while also being portable from one PIC® MCU device to another. Here is an example of its use:

#use capture(CCP1, input=PIN_C2, capture_rising, stream=CAPTURE1)

unsigned int16 WaitForEvent(void)
{
while(!get_capture_event(CAPTURE1));
return(get_capture_time(CAPTURE1));
}

#use capture() configures a CCP or IC peripheral for use, and by using the STREAM option several peripherals can be configured with several instances of #use capture(). #use capture() also provides a method of configuring the timer peripheral to use and the tick rate of the timer. Several other configuration options exist, see the compiler help manual for documentation.

get_capture_event() returns TRUE if the CCP or IC peripheral has trapped an event that can be read, and get_capture_time() returns the time the event happened.

The CCS C Compiler provides an example of using this library, ex_use_caputure.c which can be found in the examples directory of the CCS C Compiler. This example can be used on any PCM, PCH or PCD version 5 CCS C Compiler.

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Utilizing the new Signal Measurement Timer (SMT) PIC® MCU peripheral with the CCS C Compiler

Tuesday 06 December, 2016

The Signal Measurement Timer (SMT) is a powerful new timing peripheral found on several of the newer PIC® MCU devices, such as the PIC16F18877 and PIC18F67K40 families. Each SMT is a 24bit timer that can operate in one of several modes:

* Timer - A simple 24bit timer, similar to the Timer0 or Timer1 peripheral.

* Gated Timer - Like timer mode above, but only increments when the signal GPIO signal is high.

* Period and duty cycle measurement - Like gated timer, increments a counter when the signal GPIO signal is high. But when the signal GPIO goes low, the timer value is stored for future use and the counter is reset back to 0.

* High and low measurement - Similar to Period and duty cycle mode above, but resets and stores on every signal edge.

* Window Measurement - akin to period and duty cycle measurement above, but measures time between two rising edge signals on the window GPIO pin.

* Gated window measurement - Like window measurement above, but time only increments when the signal GPIO pin is high.

* Time of flight - Similar to window measurement, but timing starts when the window GPIO pin goes high and the timer is stored and reset to 0 when the window GPIO pin or signal GPIO pin goes high.

* 24bit capture - Simply stores the timer value when the window GPIO pin changes state.

* 24bit counter - Counts all the rising edges of the signal GPIO pin.

* Gated counter - Comparable to the 24bit counter mode, but only increments when the window GPIO pin is high.

* Windows counter - Like the gated counter mode, but a rising edge of the window GPIO pin will store the existing timer counter and then reset it to 0.

The CCS C Compiler has been updated to add a library that allows for controlling, configuring and using the SMT in your PICmicro C projects. The functions that have been added are setup_smtX() (or setup_smt1() to setup the first SMT peripheral), smtX_status(), smtX_start(), smtX_stop(), smtX_update(), smtX_reset_timer(), smtX_read() and smtX_write(). For more help, refer to the CCS C Compiler Help file for documentation.

Here is an example of using the Timer mode to blink an LED at a 1Hz rate:

#define LED_PIN PIN_B4
#define SMT_PERIOD (getenv("CLOCK") - 1)

#INT_SMT1
void my_smt_isr(void)
{
output_toggle(LED_PIN);
}

void my_smt_init(void)
{
setup_smt1(SMT_ENABLED | SMT_MODE_TIMER | SMT_CLK_FOSC, SMT_PERIOD);
smt1_start();

enable_interrupts(INT_SMT1);
enable_interrupts(GLOBAL);
}

The CCS C Compiler also provides 2 full example programs showing how to use the SMT, which can be found in the examples directory of the CCS C Compiler. First ex_smt_timer.c which is an example of using the SMT peripheral in Timer mode to toggle an I/O pin, and second ex_smt_period_duty.c which is an example of using the SMT peripheral in Period and Duty Cycle Acquisition mode to determine the period and duty cycle of an input signal.

Like us on Facebook. 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 http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

 Displaying 1 to 8 (of 8 articles)   Result Pages:  1