完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。请帮帮我。我在IAR嵌入我的代码编程,我没有建立错误,没有警告,但它没有工作。这是我在main.c中的代码:
#include''main.h'' void main(void) { CLK_HSICmd(ENABLE); CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); GPIO_Config(); tiM1_Config(); 而(1) { // TIM1_SetCompare1(349); } } void TIM1_Config() { TIM1_DeInit(); / * cau hinh timer 1 co dau ra PWM la 10kHz - bo chia tan 2 - 职责= 30% Ftimer = 16/2 = 8MHz的 TimerPeriod = Ftimer / Fpwm -1 = 799 * / TIM1_TimeBaseInit(1,TIM1_COUNTERMODE_UP,799,0); TIM1_SelectOCxM(TIM1_CHANNEL_1,TIM1_OCMODE_PWM2); TIM1_OC1PolarityConfig(TIM1_OCPOLARITY_LOW); TIM1_CCxCmd(TIM1_CHANNEL_1,ENABLE); TIM1_SetCompare1(239); TIM1_OC1PreloadConfig(ENABLE); TIM1_ARRPreloadConfig(ENABLE); / * TIM1计数器启用* / TIM1_Cmd(ENABLE); / * TIM1主输出使能* / TIM1_CtrlPWMOutputs(ENABLE); } void GPIO_Config(void) { GPIO_DeInit(GPIOB); GPIO_Init(GPIOB,GPIO_PIN_5,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_DeInit(GPIOC); GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_LOW_FAST); } 和我在main.h中的代码 #ifndef __MAIN_H #define __MAIN_H / *包括----------------------------------------------- ------------------- * / #include''stm8s.h'' #include''user_delay.h'' void TIM1_Config(); void GPIO_Config(void); #endif / * __MAIN_H * / 谢谢你的帮助! 以上来自于谷歌翻译 以下为原文 Hi all. please help me. I program my code in IAR embeded, I built no error, no warning, but it not working. this is my code in main.c : #include ''main.h'' void main(void) { CLK_HSICmd(ENABLE); CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1); GPIO_Config(); TIM1_Config(); while (1) { //TIM1_SetCompare1(349); } } void TIM1_Config() { TIM1_DeInit(); /* cau hinh timer 1 co dau ra PWM la 10kHz - bo chia tan 2 - duty =30% Ftimer=16/2=8Mhz TimerPeriod= Ftimer/Fpwm -1=799 */ TIM1_TimeBaseInit(1, TIM1_COUNTERMODE_UP, 799, 0); TIM1_SelectOCxM(TIM1_CHANNEL_1,TIM1_OCMODE_PWM2); TIM1_OC1PolarityConfig(TIM1_OCPOLARITY_LOW); TIM1_CCxCmd(TIM1_CHANNEL_1,ENABLE); TIM1_SetCompare1(239); TIM1_OC1PreloadConfig(ENABLE); TIM1_ARRPreloadConfig(ENABLE); /* TIM1 counter enable */ TIM1_Cmd(ENABLE); /* TIM1 Main Output Enable */ TIM1_CtrlPWMOutputs(ENABLE); } void GPIO_Config(void) { GPIO_DeInit(GPIOB); GPIO_Init(GPIOB,GPIO_PIN_5,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_DeInit(GPIOC); GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_LOW_FAST); } and my code in main.h #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include ''stm8s.h'' #include ''user_delay.h'' void TIM1_Config(); void GPIO_Config(void); #endif /* __MAIN_H */ thanks for helping! |
|
相关推荐
5个回答
|
|
嗨toan92.lee,
请参阅https://my.st.com中的''TIM1_7PWM_Output'示例.//content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm8-embedded-software/stsw-stm8069.html /保存,书签 ,输出PWM2信号就像你需要的那样。与您的代码比较,以确定您错过了什么。 示例位于以下路径:STM8S_StdPeriph_Lib Project STM8S_StdPeriph_Examples TIM1 TIM1_7PWM_Output -Hannibal- 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 Hi toan92.lee, Refer to the ''TIM1_7PWM_Output'' example in https://my.st.com//content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm8-embedded-software/stsw-stm8069.html/save-bookmark , which output PWM2 signals like you need. Compare with your code to identify what you have missed. Example is at this path: STM8S_StdPeriph_LibProjectSTM8S_StdPeriph_ExamplesTIM1TIM1_7PWM_Output -Hannibal- Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
|
|
|
|
你好,
我已经在我的系统上实现了上面的示例,并且没有在STM8S103F3上的Timer1 Channel1上获得任何输出,STM8S103F3是TSOP封装上的引脚16,其名称是PC6 / SPI_MOSI [TIM1_ CH1]。 我尝试修改极性并启用/禁用输出通道 - 似乎没有任何改变任何行为。 有谁知道为什么会这样? 这是TIM1_Config函数,它有一些小的修改来处理频率。 static void TIM11_Config(void) { uint16_t cr1 = 78; //这大约为100.8 kHz uint16_t period =((cr1 + 1)* 2)-1; TIM1_DeInit(); / *时基配置* / / * TIM1_Period = 4095 TIM1_Prescaler = 0 TIM1_CounterMode = TIM1_COUNTERMODE_UP TIM1_RepetitionCounter = 0 * / TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,句点,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_OC1Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_DISABLE,TIM1_OUTPUTNSTATE_ENABLE,cr1,TIM1_OCPOLARITY_HIGH,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR2_Val * / TIM1_OC2Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE,cr1,TIM1_OCPOLARITY_HIGH,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR3_Val * / TIM1_OC3Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE,cr1,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_HIGH,TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR4_Val * / TIM1_OC4Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,cr1,TIM1_OCPOLARITY_LOW,TIM1_OCIDLESTATE_SET); / * TIM1计数器启用* / TIM1_Cmd(ENABLE); / * TIM1主输出使能* / TIM1_CtrlPWMOutputs(ENABLE); 这就是它的全部 - 非常直接。 以上来自于谷歌翻译 以下为原文 Hello, I have implemented the above sample on my system and am NOT getting any output on Timer1 Channel1 on an STM8S103F3 which is Pin 16 on the TSOP package and the designation is PC6/ SPI_MOSI [TIM1_ CH1]. I've tried modifying the polarity and enable/disable of the output channels - nothing seems to change any behavior. Does anyone know why this might be happening? Here is the TIM1_Config function with a few small modifications to deal with frequency. static void TIM11_Config(void) { uint16_t cr1 = 78; // this gives approximately 100.8 kHz uint16_t period = ((cr1+1)*2)-1;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, period, 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_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE,cr1, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR2_Val*/ TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, cr1, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR3_Val*/ TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE,cr1, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);/*TIM1_Pulse = CCR4_Val*/ TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, cr1, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_SET);/* TIM1 counter enable */ TIM1_Cmd(ENABLE);/* TIM1 Main Output Enable */ TIM1_CtrlPWMOutputs(ENABLE); }That's all there is to it - pretty straight forward. |
|
|
|
我发现处理器需要设置一个OPTION位来改变引脚的备用功能。多年来,这个问题可能让很多人感到厌烦。
以上来自于谷歌翻译 以下为原文 I've discovered that the processor required one of the OPTION bits to be set to change the alternate function of the pin. This problem has probably bit many people over the years. |
|
|
|
mmmm ......现在正在扼杀我的时间。
以上来自于谷歌翻译 以下为原文 mmmm...and it is chomping into my time right now. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2718 浏览 1 评论
3235 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1807 浏览 1 评论
3645 浏览 6 评论
6033 浏览 21 评论
1333浏览 4评论
208浏览 3评论
195浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
348浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
440浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 03:02 , Processed in 1.651820 second(s), Total 85, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号