SDK中pwm频率为2KHz,将分频系数0更改为1,频率小于1kHZ。
只更改了MAP_TimerPrescaleSet(ulBase,ulTimer,1); 如下图
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.
SDK中pwm频率为2KHz,将分频系数0更改为1,频率小于1kHZ。
只更改了MAP_TimerPrescaleSet(ulBase,ulTimer,1); 如下图
PWM模式下prescale不是分频器,注意模式不同,prescale的使用不同:
. Note that when counting down in oneshot or periodic modes, the prescaler acts as a true prescaler and contains the least-significant bits of the count. When counting up in one-shot or periodic modes, the prescaler acts as a timer extension, and holds the most-significant bits of the count. In input edge count, input edge time, and PWM mode, the prescaler always acts as a timer extension, regardless of the count direction.
时间间隔基于如下计算:
// // The PWM works based on the following settings: // Timer reload interval -> determines the time period of one cycle // Timer match value -> determines the duty cycle // range [0, timer reload interval] // The computation of the timer reload interval and dutycycle granularity // is as described below: // Timer tick frequency = 80 Mhz = 80000000 cycles/sec // For a time period of 0.5 ms, // Timer reload interval = 80000000/2000 = 40000 cycles // To support steps of duty cycle update from [0, 255] // duty cycle granularity = ceil(40000/255) = 157 // Based on duty cycle granularity, // New Timer reload interval = 255*157 = 40035 // New time period = 0.5004375 ms // Timer match value = (update[0, 255] * duty cycle granularity) // #define TIMER_INTERVAL_RELOAD 40035 /* =(255*157) */ #define DUTYCYCLE_GRANULARITY 157