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

[复制链接]
2844|1
 楼主| Chaos_zc 发表于 2011-8-16 10:12 | 显示全部楼层 |阅读模式
  1. 00068 /* TIM1 Configuration ---------------------------------------------------
  2. 00069 Generate 7 PWM signals with 4 different duty cycles:
  3. 00070 TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
  4. 00071 SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
  5. 00072 and Connectivity line devices and to 24 MHz for Low-Density Value line and
  6. 00073 Medium-Density Value line devices
  7. 00074
  8. 00075 The objective is to generate 7 PWM signal at 17.57 KHz:
  9. 00076 - TIM1_Period = (SystemCoreClock / 17570) - 1
  10. 00077 The channel 1 and channel 1N duty cycle is set to 50%
  11. 00078 The channel 2 and channel 2N duty cycle is set to 37.5%
  12. 00079 The channel 3 and channel 3N duty cycle is set to 25%
  13. 00080 The channel 4 duty cycle is set to 12.5%
  14. 00081 The Timer pulse is calculated as follows:
  15. 00082 - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100
  16. 00083 ----------------------------------------------------------------------- */
  17. 00084 /* Compute the value to be set in ARR regiter to generate signal frequency at 17.57 Khz */
  18. 00085 TimerPeriod = (SystemCoreClock / 17570 ) - 1;
  19. 00086 /* Compute CCR1 value to generate a duty cycle at 50% for channel 1 and 1N */
  20. 00087 Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
  21. 00088 /* Compute CCR2 value to generate a duty cycle at 37.5% for channel 2 and 2N */
  22. 00089 Channel2Pulse = (uint16_t) (((uint32_t) 375 * (TimerPeriod - 1)) / 1000);
  23. 00090 /* Compute CCR3 value to generate a duty cycle at 25% for channel 3 and 3N */
  24. 00091 Channel3Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
  25. 00092 /* Compute CCR4 value to generate a duty cycle at 12.5% for channel 4 */
  26. 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

粉丝
快速回复 在线客服 返回列表 返回顶部