17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Built-in Functions<br />

Returns:<br />

Function:<br />

undefined<br />

Writes the 10-bit value to the PWM to set the duty. An 8-bit value may be<br />

used if the most significant bits are not required. The 10 bit value is then used<br />

to determine the duty cycle of the PWM signal as follows:<br />

duty cycle = value / [ 4 * (PR2 +1 ) ]<br />

Where PR2 is the maximum value timer 2 will count to before toggling the<br />

output pin.<br />

Availability:<br />

Requires:<br />

Examples:<br />

This function is only available on devices with CCP/PWM hardware.<br />

Nothing<br />

// For a 20 mhz clock, 1.2 khz frequency,<br />

// t2DIV set to 16, PR2 set to 200<br />

// the following sets the duty to 50% (or 416 us).<br />

long duty;<br />

duty = 408; // [408/(4*(200+1))]=0.5=50%<br />

set_pwm1_duty(duty);<br />

Example Files:<br />

Also See:<br />

ex_pwm.c<br />

setup_ccpX(), CCP1 Overview<br />

set_rtcc( ) set_timer0( ) set_timer1( ) set_timer2( )<br />

set_timer3( ) set_timer4( ) set_timer5( )<br />

Syntax: set_timer0(value) or set_rtcc (value)<br />

set_timer1(value)<br />

set_timer2(value)<br />

set_timer3(value)<br />

set_timer4(value)<br />

set_timer5(value)<br />

Parameters:<br />

Returns:<br />

Function:<br />

Timers 1 & 5 get a 16 bit int.<br />

Timer 2 and 4 gets an 8 bit int.<br />

Timer 0 (AKA RTCC) gets an 8 bit int except on the PIC18XXX where it<br />

needs a 16 bit int.<br />

Timer 3 is 8 bit on PIC16 and 16 bit on PIC18<br />

undefined<br />

Sets the count value of a real time clock/counter. RTCC and Timer0 are the<br />

same. All timers count up. When a timer reaches the maximum value it will<br />

273

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!