完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
我正在尝试在STM8S003F3P6上运行tiM1,我正在使用标准外设库代码,但我只能在TIM1_CH3(PC3)引脚上产生pwm,其他引脚根本不产生任何波形。我确定这不是硬件问题 - 因为当我将引脚切换为gpio-它工作正常时,我在这里缺少什么? 代码是: static void TIM1_Config(void) { / * TIM1外设配置* / TIM1_DeInit(); / *时基配置* / / * TIM1_Prescaler = 0 TIM1_CounterMode = TIM1_COUNTERMODE_UP TIM1_Period = 65535 TIM1_RepetitionCounter = 0 * / TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_UP,65535,0); / * PWM模式下的通道1,2和3配置* / / * 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_LOW TIM1_OCIdleState = TIM1_OCIDLESTATE_SET TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET * / TIM1_OC1Init(TIM1_OCMODE_PWM1,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_DISABLE, CCR1_Val,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR2_Val * / TIM1_OC2Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); / * TIM1_Pulse = CCR3_Val * / TIM1_OC3Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,TIM1_OUTPUTNSTATE_ENABLE, CCR3_Val,TIM1_OCPOLARITY_LOW,TIM1_OCNPOLARITY_LOW,TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); / *自动输出启用,中断,死区时间和锁定配置* / / * TIM1_OSSIState = TIM1_OSSISTATE_ENABLE TIM1_LockLevel = TIM1_LOCKLEVEL_1 TIM1_DeadTime = 117 TIM1_Break = TIM1_BREAK_ENABLE TIM1_BreakPolarity = TIM1_BREAKPOLARITY_HIGH TIM1_AutomaticOutput = TIM1_AUTOMATICOUTPUT_ENABLE * / / * TIM1计数器启用* / TIM1_Cmd(ENABLE); / *主输出启用* / TIM1_CtrlPWMOutputs(ENABLE); } #stm8 #stm8s#tim1-timer 以上来自于谷歌翻译 以下为原文 Hi, I'm trying to operate TIM1 on STM8S003F3P6, I am using the standard peripheral library code, but I am only able to produce pwm on TIM1_CH3 (PC3) pin, the other pins do not produce any waveforms at all. I'm sure this is not a hardware issue- because when I toggle the pin as a gpio- it works fine, what am I missing here? The code is: static void TIM1_Config(void) { /* TIM1 Peripheral Configuration */ TIM1_DeInit(); /* Time Base configuration */ /* TIM1_Prescaler = 0 TIM1_CounterMode = TIM1_COUNTERMODE_UP TIM1_Period = 65535 TIM1_RepetitionCounter = 0 */ TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 65535,0); /* Channel 1, 2 and 3 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_LOW TIM1_OCIdleState = TIM1_OCIDLESTATE_SET TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET */ TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); /* TIM1_Pulse = CCR2_Val */ TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); /* TIM1_Pulse = CCR3_Val */ TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR3_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET); /* Automatic Output enable, Break, dead time and lock configuration */ /* TIM1_OSSIState = TIM1_OSSISTATE_ENABLE TIM1_LockLevel = TIM1_LOCKLEVEL_1 TIM1_DeadTime = 117 TIM1_Break = TIM1_BREAK_ENABLE TIM1_BreakPolarity = TIM1_BREAKPOLARITY_HIGH TIM1_AutomaticOutput = TIM1_AUTOMATICOUTPUT_ENABLE */ /* TIM1 counter enable */ TIM1_Cmd(ENABLE); /* Main Output Enable */ TIM1_CtrlPWMOutputs(ENABLE); } #stm8 #stm8s #tim1-timer |
|
相关推荐
2个回答
|
|
你有没有能够使这个工作?我必须在TIM1 CH1,2,3上输出PWM的配置在带有3K3芯片的stm8svldiscovery板上工作,但在我自己的板上使用的3F3上没有。
以上来自于谷歌翻译 以下为原文 Were you ever able to get this working? The configuration I had to output PWM on TIM1 CH1,2,3 worked on the stm8svldiscovery board with the 3K3 chip but not on the 3F3 I used on my own board. |
|
|
|
我发现问题,在20引脚STM8S003F3上,PWM输出是引脚上的备用功能。必须通过设置Option字节激活这些备用功能。在IAR中,这可以通过菜单选项ST-LINK->选项字节来完成,但也可以使用STM8S外设库在我已完成的代码中完成。设置选项字节后,仅在设备首次运行期间发生,有必要重置微控制器以使更改生效。
#define OPTION_BYTE_AFR 0x4803 / *备用函数重映射选项字节* / #define AFR0 0x01 / *备用功能重映射位0 * / ... verify_option(OPTION_BYTE_AFR,AFR0); / *为PWM * /激活备用引脚功能 ... void verify_option ( uint16_t地址, uint8_t数据 ) { uint16_t stored_data = FLASH_ReadOptionByte(address); if((FLASH_OPTIONBYTE_ERROR == stored_data)|| (data!=(uint8_t)(stored_data>> 8))) { FLASH_Unlock(FLASH_MEMTYPE_DATA); FLASH_EraseOptionByte(地址); FLASH_ProgramOptionByte(地址,数据); FLASH_Lock(FLASH_MEMTYPE_DATA); / *使用看门狗重置设备以启用该功能* / IWDG-> KR = IWDG_KEY_ENABLE; 而(1); } } 以上来自于谷歌翻译 以下为原文 I found the issue, on the 20-pin STM8S003F3 the PWM outputs are an alternate function on the pins. These alternate functions must be activated by setting the Option bytes. In IAR this can be done from the menu option ST-LINK->Option bytes but can also be done in code which is what I've done, using the STM8S peripheral library. After setting the option byte, which happens only during the first run of the device, it appears necessary to reset the microcontroller for the change to take effect. #define OPTION_BYTE_AFR 0x4803 /* Alternate function remapping option byte */ #define AFR0 0x01 /* Alternate function remapping bit 0 */ ... verify_option( OPTION_BYTE_AFR, AFR0 ); /* Activate alternate pin func for PWM */ ... void verify_option ( uint16_t address, uint8_t data ) { uint16_t stored_data = FLASH_ReadOptionByte( address );if( ( FLASH_OPTIONBYTE_ERROR == stored_data ) || ( data != (uint8_t)( stored_data>>8 ) ) ) { FLASH_Unlock( FLASH_MEMTYPE_DATA ); FLASH_EraseOptionByte( address ); FLASH_ProgramOptionByte( address, data ); FLASH_Lock( FLASH_MEMTYPE_DATA ); /* Use the watchdog to reset the device to enable the feature */ IWDG->KR = IWDG_KEY_ENABLE; while(1); } } |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2735 浏览 1 评论
3241 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1810 浏览 1 评论
3650 浏览 6 评论
6039 浏览 21 评论
1339浏览 4评论
201浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
350浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
444浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
274浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 15:06 , Processed in 1.569727 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号