DebugLab
发表于 2024-9-14 17:33:37
ZhangYiGen 发表于 2024-9-14 17:07
或者能封装成一个直接调用的函数?PWM_SET(int xxHZ,int xx); //参数1 设置频率 参数2设置占空比(0-100 ...
https://www.stcaimcu.com/forum.php?mod=redirect&goto=findpost&ptid=10790&pid=107141
频率通过CMOD.CPS设置(配合调节主时钟频率)
ZhangYiGen
发表于 2024-9-15 10:34:01
DebugLab 发表于 2024-9-14 17:31
注意不能给100%,最大值要限制到1023,给1023,波形就是直线,PWM函数已经处理好了 ...
我明白了,十分感谢
jmg
发表于 2024-9-15 14:43:36
ZhangYiGen 发表于 2024-9-14 17:00
这是修改频率的吧,占空比我看了好几篇博客,也没看明白
To modify frequency there are limited choices with PCA.
You can select size of PWM count for 6/7/8/10 bits, and use SysCLK divided by CMOD.CPS or clock PCA from Timer0.
If timer0 is set to reload mode that gives more choice on frequency, but it is still coarse at higher PWM frequencies.
eg if you have 24MHz and timer0 reload of 93, PCA 8 bit gives 1008.064516Hz PWM,
Timer0 reload of 92 gives 1019.021739 Hz PWM etc
Or you can vary SYSCLK to vary frequency,but that varies all MCU timing.
Different PWM modules in other STC MCU allow change of the TOP counter, so you can finer tune PWM frequency at the cost of some interaction with PWM set points.
eg a PWM with top choice of 1024/1023/1022 etc can output a23437.5Hz PWM with 0.1% steps in Hz, but the % duty cycle needs to be adjusted.
ZhangYiGen
发表于 2024-9-16 20:23:20
jmg 发表于 2024-9-15 14:43
To modify frequency there are limited choices with PCA.
You can select size of PWM count for 6/7/8/ ...
佬,能使用中文解释?{:sweat:}
jmg
发表于 2024-9-17 07:22:08
ZhangYiGen 发表于 2024-9-16 20:23
佬,能使用中文解释?
使用带有翻译功能的 Chrome 浏览器
vb2002
发表于 2024-9-19 10:25:23
jmg 发表于 2024-9-17 07:22
使用带有翻译功能的 Chrome 浏览器
pca8位pwm已经蛮好了,我弄的手电驱动就是用的这个单片机,挺好的。
设置也简单,参照手册,里面有范例程序,