OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4554|回复: 3

关于pwm的问题

[复制链接]

1

主题

3

帖子

0

精华

新手入门

积分
27
金钱
27
注册时间
2014-3-23
在线时间
0 小时
发表于 2014-3-23 17:37:19 | 显示全部楼层 |阅读模式
/* 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);

怎么算的占空比?不是 = pulse/(period+1)吗?还有频率?[/mw_shl_code]
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

3

帖子

0

精华

新手入门

积分
27
金钱
27
注册时间
2014-3-23
在线时间
0 小时
 楼主| 发表于 2014-3-23 17:38:15 | 显示全部楼层
/* TIM1 Configuration ---------------------------------------------------
00069    Generate 7 WM signals with 4 different duty cycles:
00070    TIM1CLK = SystemCoreClock, rescaler = 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 WM 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);
回复 支持 反对

使用道具 举报

1

主题

3

帖子

0

精华

新手入门

积分
27
金钱
27
注册时间
2014-3-23
在线时间
0 小时
 楼主| 发表于 2014-3-23 17:38:56 | 显示全部楼层
回复【2楼】七七九八:
---------------------------------
上面是固件库上面的内容
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2014-3-24 00:15:05 | 显示全部楼层
这个我们教程就讲了。
占空比其实就是CCRx和arr-CCRx的比值。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-9 13:47

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表