先附上代码:
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
先附上代码:
//
// Set the PWM period to 250Hz. To calculate the appropriate parameter
// use the following equation: N = (1 / f) * SysClk. Where N is the
// function parameter, f is the desired frequency, and SysClk is the
// system clock frequency.
// In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles. Note that
// the maximum period you can set is 2^16 - 1.
// TODO: modify this calculation to use the clock frequency that you are
// using.
//
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 64000);
//
// Set PWM0 PD0 to a duty cycle of 25%. You set the duty cycle as a
// function of the period. Since the period was set above, you can use the
// PWMGenPeriodGet() function. For this example the PWM will be high for
// 25% of the time or 16000 clock cycles (64000 / 4).
//
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM0_BASE, PWM_OUT_0) / 4); //这个是配置25%占空比的方法
//
// Enable the dead-band generation on the PWM0 output signal. PWM bit 0
// (PD0), will have a duty cycle of 25% (set above) and PWM bit 1 will have
// a duty cycle of 75%. These signals will have a 10us gap between the
// rising and falling edges. This means that before PWM bit 1 goes high,
// PWM bit 0 has been low for at LEAST 160 cycles (or 10us) and the same
// before PWM bit 0 goes high. The dead-band generator lets you specify
// the width of the "dead-band" delay, in PWM clock cycles, before the PWM
// signal goes high and after the PWM signal falls. For this example we
// will use 160 cycles (or 10us) on both the rising and falling edges of
// PD0. Reference the datasheet for more information on dead-band
// generation.
//