完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。我在STM8S105K4T6上有一个可行的pwm代码,现在我把它粘贴到STM8S003k3 fnd它将无法正常工作。
& sharpdefine CCR1_Val((u16)2047)//配置通道1脉冲宽度蓝色 & sharpdefine CCR2_Val((u16)2047)//配置通道2脉冲宽度 static void TIM1_Config(void) { TIM1_DeInit(); / *时基配置* / / * TIM1_Period = 4095 TIM1_Prescaler = 0 TIM1_CounterMode = TIM1_COUNTERMODE_UP TIM1_RepetitionCounter = 0 * / TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,4095,0); / *通道1,2,3和4在PWM模式下配置* / / * TIM1_OCMode = TIM1_OCMODE_PWM2 TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE TIM1_Pulse = CCR1_Val TIM1_OCPolarity = TIM1_OCPOLARITY_LOW TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH TIM1_OCIdleState = TIM1_OCIDLESTATE_SET TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET * / / * TIM1_Pulse = CCR2_Val * / TIM1_OC2Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE,CCR2_Val, TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR4_Val * / TIM1_OC4Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,CCR1_Val,TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET); / * TIM1计数器启用* / TIM1_Cmd(ENABLE); / * TIM1主输出使能* / TIM1_CtrlPWMOutputs(ENABLE); } 任何人都可以告诉我这里有什么问题。 #stm8s003k3-TIM1-PWM-问题 以上来自于谷歌翻译 以下为原文 Hello every one. I have a workable code of pwm on STM8S105K4T6 and now I paste it in STM8S003k3 fnd it won't work. &sharpdefine CCR1_Val ((u16)2047) // Configure channel 1 Pulse Width Blue &sharpdefine CCR2_Val ((u16)2047) // Configure channel 2 Pulse Width static void TIM1_Config(void) { TIM1_DeInit(); /* Time Base configuration */ /* TIM1_Period = 4095 TIM1_Prescaler = 0 TIM1_CounterMode = TIM1_COUNTERMODE_UP TIM1_RepetitionCounter = 0 */ TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0); /* Channel 1, 2,3 and 4 Configuration in PWM mode */ /* TIM1_OCMode = TIM1_OCMODE_PWM2 TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE TIM1_Pulse = CCR1_Val TIM1_OCPolarity = TIM1_OCPOLARITY_LOW TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH TIM1_OCIdleState = TIM1_OCIDLESTATE_SET TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET */ /*TIM1_Pulse = CCR2_Val*/ TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); /*TIM1_Pulse = CCR4_Val*/ TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET); /* TIM1 counter enable */ TIM1_Cmd(ENABLE); /* TIM1 Main Output Enable */ TIM1_CtrlPWMOutputs(ENABLE); } Can any one tell me what is wrong here. #stm8s003k3-tim1-pwm-problem |
|
相关推荐
1个回答
|
|
对不起,我的错误代码很好。我只是忘记重新映射Timer 1 -channel 4 [AFR6]我的状态指示器所在的位置
以上来自于谷歌翻译 以下为原文 Sorry my fault code is fine. I just forget remap Timer 1 -channel 4[AFR6] where my status led is |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2644 浏览 1 评论
3209 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1784 浏览 1 评论
3613 浏览 6 评论
5990 浏览 21 评论
940浏览 4评论
1317浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
585浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1304浏览 3评论
1362浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 01:13 , Processed in 1.042981 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号