CCS News RSS

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

EZ App Lynx V 2.0 - Released with New Features

Wednesday 18 March, 2015

A new version of EZ App Lynx has been released, which encompasses an update to the Android Application on the Google Play store and the EZ App Lynx framework library that comes with the CCS C Compiler. Not only does this update improve stability and reduce communication errors, it also adds many new features.

The most significant improvement is the ability to add styles. In the framework library API, the function EZAppStylesROM() allows the user to add one more style configuration. A style can contain configuration information such as text sizes, colors, spacing, margins and alignment. Once a style configuration has been added, all following UI elements added through the framework library will continue using the previously defined styles. The following example shows how a style was used to change the background color and add a border to each UI element, which was not supported in the previous version of the framework:



Another area of improvement is the handling of strings. A string field can now be added to the screen that contains both a header on the left, and the dynamic content on the right. The text style for the header portion on the left can differ from the text on the right. A string field can also be added that is writable from the smartphone/tablet host, allowing the user to add editable strings. This is done through the new framework function EZAppFieldText(). Also, string fields can be specified to read from EEPROM or other external memory devices. Here is an example of an editable string:



The user now has more options when it comes to creating buttons with the new framework function EZAppAddFieldButtons(). This function empowers the user to create:

* More than one button on the row
* Configure the buttons to fill up the entire horizontal space of the row
* Add an inset status LED on each button

The buttons may be configured to be a one-statue button, where it sends a set bit when the button is being held down on the smartphone/tablet. It will then send a cleared bit when the button is not being held down on the smartphone/tablet.

Buttons also have their own style configuration, using EZAppStylesROM(), for the user to configure the color and appearance of the button. Here is an example of 3 buttons on one row, filling the entire row horizontally, with inset status LEDs:



The Android App now supports the RN4020 Bluetooth module in MLDP mode. The RN4020 is a Bluetooth Low Energy module, and the MLDP mode provides a serial data delivery similar to SPP of Bluetooth Classic modules. Work is in development on an iOS version of the App that supports the RN4020 module (the iOS version will not support SPP like the Android app). The CCS C Compiler provides a new driver for the RN4020 module.

The EZ App Lynx framework allows one to quickly develop smartphone and tablet solutions that communicate with the PICmicro over Bluetooth. For more information about EZ App Lynx, see http://www.ccsinfo.com/ezapp

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.

Tech Note: Programmable Switch Mode Controller (PSMC)

Wednesday 18 March, 2015

Pulse Width Modulation (PWM) capability was first added to the PIC® microcontroller line using the Capture/Compare/PWM (CCP) unit. Since then we have seen the enhanced CCP (ECCP) and a variety of power and motor control PWM modules each with its own features. The newest PWM module is called the Programmable Switch Mode Controller (PSMC). This is the most sophisticated PWM yet and is on new chips like the PIC16F1789.

The PSMC allows for standard PWM, complementary PWM, shutdown control and deadband control like some of the older modules. It also allows for high resolution on the duty and frequency, as well variable frequency. It can for example do 3 phase 6 step PWM.

Input pins, comparator outputs and CCP triggers can be used not only to control shutdown, but to control if the PWM is running, or to start or stop a cycle.

Some PIC® devices have as many as 4 independent units and the units can optionally be synchronized with each other.

The new compiler functions are:

setup_psmc(unit, mode, period, period_time,
rising_edge, rise_time,
falling_edge, fall_time);

psmc_pins(unit, pins_used, pins_active_low);

psmc_duty(unit, fall_time);

psmc_deadband(unit, rising_edge, falling_edge);

psmc_blanking(unit, rising_edge, rise_time, falling_edge, fall_time);

psmc_shutdown(unit, option, source, pins_high);

psmc_freq_adjust(unit, freq_adjust);

psmc_modulation(unit, options);

psmc_sync(slave_unit, master_unit, options);


The following is a short example program that shows off some of the features:

#include <16f1789.h>
#use delay(osc=20mhz)

#define us(time) (int16)(time*(getenv("CLOCK")/1000000))

void main(void) {
setup_psmc(1, PSMC_ECCP_BRIDGE_FORWARD,
PSMC_EVENT_TIME | PSMC_SOURCE_FOSC | PSMC_DIV_2, us(100),
PSMC_EVENT_TIME, us(10),
PSMC_EVENT_TIME, us(35));

psmc_deadband(1, us(2), us(4));
psmc_modulation(1, PSMC_MOD_IN_PIN);
psmc_pins(1, PSMC_A | PSMC_B | PSMC_C | PSMC_D);

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0);
set_adc_channel(0);

while(TRUE) {
psmc_duty(1, us(((read_adc()*(int16)10)/25)) );
}
}

Other examples are included with the compiler download and begin with EX_PSMC_

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.

Serializing your USB devices, now made easier with CCS tools

Friday 22 May, 2015

Starting with version 5.046 of the CCS C Compiler and version 5.018 of CCSLOAD programming software has made it easy to create Unicode strings and write a user-provided serial number to the USB device descriptor during programming. In the device descriptor of a USB device a serial number string can be provided, but this is optional. If a serial number is provided in the device descriptor, two or more USB devices attached to a host cannot contain the same VID/PID/serial combination. Since USB has a mechanism for storing and reading serial numbers, it may be advantageous to a developer to use this mechanism instead of developing a custom mechanism on top of whatever USB protocol is being used. A challenge with using the standard USB mechanism, however, has been programming a user provided serial number due to the string being in Unicode and having the Unicode string packed in a table with other strings in the string table with a length field in front of the string. All of these problems have been solved in the latest tools from CCS.

First, a new pre-processor has been added to the CCS C Compiler:

_unicode(x)

When called, it converts the string x to a UTF-16 Unicode string. This is the format used by string descriptors in USB. For example:

char string[] = _unicode("Hello");

Since "Hello" is an ASCII string (no character has a value greater than 0x7F), all characters encoded will be 16bit - therefore the size of string[] would be the strlen("Hello")*2. string[], when in Unicode, will not be null terminated. It is not null-terminated since 0x00 is a valid character in UTF-16 and not a null-terminator. That means to get the string length of string[] the user would have to use sizeof() instead of strlen().

Second, the #serialize() pre-processor has been updated in the CCS C Compiler to tell the CCS CCSLOAD programming software how to serialize a Unicode string. The new parameter added is unicode, which tells the #serialize which USB string to write during programming with the user provided serial number. Here is an example:

#serialize(id=USB_STRING_DESC, unicode=3, prompt="SN#")

USB_STRING_DESC is a table of USB strings and is read by the CCS C Compiler's USB stack when the host PC reads a string from the PIC®. A value of 3 is passed to the Unicode parameter, to tell the #serialize that the serial number should be encoded as a Unicode string and that it should overwrite the 4th string in USB_STRING_DESC (the first string in USB_STRING_DESC is 0). In the device descriptor for your USB device, the field identifying which string to use for the serial number should also have been set to 3.

A working example of this is provided in the file ex_usb_hid.c. When compiled and programmed onto the PIC®, CCSLOAD will ask the user for the serial number and write the serial number onto the string descriptor used for the serial number.

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.

PID Module Introduced for the PIC16F1614 Family

Friday 22 May, 2015

Built-in functions have been added to the CCS C Compiler for setting up and using the PID module introduced for the PIC16F1614 family of devices. The PID module is a mathematics module that can perform a variety of operations, most prominently acting as a PID (Proportional-Integral-Derivative) controller.

The module accomplishes the task of calculating the PID algorithm by utilizing user-provided coefficients along with a multiplier and accumulator. The main benefit of using the PID module is for the PID calculation to be completed much faster with the hardware module than in software. For example when running the PIC® from the 32 MHz internal oscillator the built-in HW PID function was measured to take 12.8 us, compared to a software PID function which was measure to take 216 us. This is approximately 1/16 of the time.

The following are the built-in functions that have been added for the PID module:

  • setup_pid() - used to setup the PID module and set the user-input coefficients.
  • pid_get_result() - used to input the set point and feedback from the external system to the PID module, start the calculation, and to retrieve the result to input in the external system.
  • pid_read() - used to read various PID module registers.
  • pid_write() - used to write various PID module registers.
  • pid_busy() - used to check if PID module is busy or not-busy, finished, with calculation.

The user-input coefficients, K1, K2 and K3, are calculated from the three classic PID coefficients Kp, Ki and Kd with the following equations:



T is the sampling period.

The following is an example of how to setup and use the PID module:

void main(void) {
pid_struct_t PIDOutput;
unsigned int16 ADCReading;
signed int16 K1 = 7, K2 = -6, K3 = 0;
unsigned int16 SetPoint = 500;
unsigned int16 PWMDuty;

setup_pid(PID_MODE_PID, K1, K2, K3);

//Setup ADC
setup_adc_ports(sAN3, VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);

//Setup PWM 3
setup_timer_4(T4_CLK_INTERNAL | T4_DIV_BY_32, 249, 1); //1ms period, from 32 MHz clock
set_pwm3_duty(0); //0% duty
setup_pwm3(PWM_ENABLED | PWM_OUTPUT | PWM_TIMER4);

while(TRUE) {
delay_ms(50);

ADCReading = read_adc();
pid_get_result(SetPoint, ADCReading, &PIDOutput);

PIDOutput.u &= 0x07;

if(PIDOutput.u >= 4) //PIDOutput is negative, set PWMDuty to Minimum
PWMDuty = 0;
else if(PIDOutput.u != 0) //PIDOutput > Maximum, set PWMDuty to Maximum
PWMDuty = 1000;
else if(PIDOutput.l > 1000) //PIDOutput > Maximum, set PWMDuty to Maximum
PWMDuty = 1000;
else
PWMDuty = PIDOutput.l;

set_pwm3_duty(PWMDuty);
}
}

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

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 4 (of 4 articles)   Result Pages:  1