打印

官方库中利用TIM1产生7路PWM的例程,是否有错?

[复制链接]
2191|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Chaos_zc|  楼主 | 2011-8-16 10:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
00068 /* TIM1 Configuration ---------------------------------------------------
00069 Generate 7 PWM signals with 4 different duty cycles:
00070 TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
00071 SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
00072 and Connectivity line devices and to 24 MHz for Low-Density Value line and
00073 Medium-Density Value line devices
00074
00075 The objective is to generate 7 PWM signal at 17.57 KHz:
00076 - TIM1_Period = (SystemCoreClock / 17570) - 1
00077 The channel 1 and channel 1N duty cycle is set to 50%
00078 The channel 2 and channel 2N duty cycle is set to 37.5%
00079 The channel 3 and channel 3N duty cycle is set to 25%
00080 The channel 4 duty cycle is set to 12.5%
00081 The Timer pulse is calculated as follows:
00082 - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100
00083 ----------------------------------------------------------------------- */
00084 /* Compute the value to be set in ARR regiter to generate signal frequency at 17.57 Khz */
00085 TimerPeriod = (SystemCoreClock / 17570 ) - 1;
00086 /* Compute CCR1 value to generate a duty cycle at 50% for channel 1 and 1N */
00087 Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
00088 /* Compute CCR2 value to generate a duty cycle at 37.5% for channel 2 and 2N */
00089 Channel2Pulse = (uint16_t) (((uint32_t) 375 * (TimerPeriod - 1)) / 1000);
00090 /* Compute CCR3 value to generate a duty cycle at 25% for channel 3 and 3N */
00091 Channel3Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
00092 /* Compute CCR4 value to generate a duty cycle at 12.5% for channel 4 */
00093 Channel4Pulse = (uint16_t) (((uint32_t) 125 * (TimerPeriod- 1)) / 1000);


这是官方库中利用TIM1产生7路PWM的例程。
此句计算定时器重加载的值TimerPeriod,已经有了减1
00085   TimerPeriod = (SystemCoreClock / 17570 ) - 1;
下句计算设置占空比为50%,其中在TimerPeriod的基础上又有减1,请问是否是个错误?还是另有原因?
00087   Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
沙发
香水城| | 2011-8-16 10:56 | 只看该作者
你可以实际运行验证一下。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:在追求有意义而又快乐的目标时,我们不是在消磨时间,而是在让时间,闪闪发光。

5

主题

272

帖子

2

粉丝