|
|
Component
PWMMC
Pulse width modulation for motor control
Component Level: Low
Category:
CPU Internal Peripherals-Timer
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Assume the component name "PWMC1" Property settings (for example): Device : PWMMC Mode : complementary Align : center-aligned mode Top-Side PWM Polarity : Positive Bottom-Side PWM Polarity : Positive Reload : every 8 PWM cycle Dead time : 0 us Correction method : method 1 Fault modes 0-3 : Automatic Enabled in init code : no Events enabled in init. code : no High speed mode : This component is enabled
MAIN.C
/* Main method sets the period register to maximum
and the duty to minimum value.
After setting this properties will be enabled
the PWMMC device and the events. */
void main(void)
{
word i;
PWMC1_SetPeriod(0x1234); // set period register
// to 0x1234 value
for (i=0; i<5; i+=2) {
PWMC1_SetDuty(i, 0x00); // set init. duty register to 0
// for each pair
}
PWMC1_SetPrescaler(3); // set prescaler of the PWMMC
PWMC1_Load(); // accept new values
PWMC1_EnableEvent(); // enable events
PWMC1_Enable(); // enable PWMMC
for(;;);
}
EVENTS.C
/* The PWMC1_OnReload method increase duty of each
complementary pair of PWMMC */
void PWMC1_OnReload(void)
{
for (i=1; i<6; i+=2) {
PWMC1_SetDuty(i,duty); // increase duty for each pair
/* May be used the following methods */
/* Setting duty by percent value: duty = 0 .. 100 */
// PWMC1_SetDutyPercent(i, duty);
/* Only for CPUs HCS12 and 56800 */
/* Setting duty by ratio value: duty = 0 .. 65535 */
// PWMC1_SetRatio16(i, duty);
/* Setting duty by ratio value: duty = 0 .. 32767 */
// PWMC1_SetRatio15(i, duty);
}
PWMC1_Load(); // accept new duties
duty++;
}
/* The PWMC1_OnFault method disable the PWMMC */
void PWMC1_OnFault(void)
{
PWMC1_Disable(); // stop PWMMC due to
// fault condition
}
|