|
|
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Required component name is "PWM1". There are the following four typical usage modes:
(1)
MAIN.C
void main(void)
{
unsigned int i, j;
for(i = 0; i < 65535; ++i) {
PWM1_SetRatio16(i); //change duty
for(j = 0; j < 65535; ++j); //delay
}
for(;;);
}
Note: The component may be also used without any method and event - only for settings of the output signal period and duty.
(2)
EVENTS.C
unsigned ratio = 0;
void PWM1_OnEnd(void)
{
PWM1_SetRatio16(++ratio); //change duty
}
(3)
EVENTS.C
int rpt_cntr = 255, mode = 0;
void PWM1_OnEnd(void)
{
if(--rpt_cntr == 0) { // If the event was generated 255times
if(++mode == 3) mode = 0; // Select next mode of the period
PWM1_SetDutyMode(mode);// Set new period mode
rpt_cntr = 255; // Set repeat counter
}
}
(4)
MAIN.C
void main(void)
{
/* output signal synchronization */
PWM1_Disable(); /* disable the component */
PWM1_ClrValue(); /* set output level to LOW */
PWM1_Enable(); /* enable the component */
}
|