完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我的STM32F103RCT6 tim8输出6路互补信号中有三路PWM信号输出有间断,请问可能是什么原因导致的,麻烦各位高人帮我看看.调了很久了,找不到原因.
以下贴出代码。 //初始化Tim8 void MotorLeft_Hw_PWM_Init(void) { by_Direct = 0; by_Step = 0; w_PWM_Save = 0; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_BDTRInitTypeDef TIM_BDTRInitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* GPIOA Configuration: Channel 1, 2 and 3 as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* GPIOB Configuration: Channel 1N, 2N and 3N as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOB, &GPIO_InitStructure); /* GPIOB Configuration: BKIN pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Time Base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 3499; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* Channel 1, 2,3 and 4 Configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OC3Init(TIM1, &TIM_OCInitStructure); /* Automatic Output enable, Break, dead time and lock configuration*/ TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; TIM_BDTRInitStructure.TIM_DeadTime = 0xFF; TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable; TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High; TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); TIM_ClearITPendingBit(TIM1, TIM_IT_Break); TIM_ITConfig(TIM1, TIM_IT_Break, ENABLE); TIM_CCPreloadControl(TIM1, ENABLE); TIM_ITConfig(TIM1, TIM_IT_COM, ENABLE); TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } //输出PWM void MotorLeft_Hw_Hall_Int(UCHAR by_State) { switch(by_Step) { case 5: default: MotorLeft_Hw_PWM(0, 1749); /* Next by_Step: by_Step 1 (A+,C-)Configuration ---------------------------- */ /* Channel2 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /* Channel1 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /* Channel3 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable); by_Step = 4; break; case 4: /* Next by_Step: by_Step 2 (A+,B-)Configuration ---------------------------- */ /* Channel3 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /* Channel1 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /* Channel2 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 ); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable); by_Step = 6; break; case 6: /* Next by_Step: by_Step 3 (C+,B-)Configuration ---------------------------- */ /* Channel1 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /* Channel3 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /* Channel2 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable); by_Step = 2; break; case 2: /* Next by_Step: by_Step 4 (C+,A-)Configuration ---------------------------- */ /* Channel2 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /* Channel3 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /* Channel1 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable); by_Step = 3; break; case 3: /* Next by_Step: by_Step 5 (B+,A-)Configuration ---------------------------- */ /* Channel3 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /* Channel2 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /* Channel1 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable); by_Step = 1; break; case 1: /* Next by_Step: by_Step 6 (B+,C-)Configuration ---------------------------- */ /* Channel1 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /* Channel2 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /* Channel3 configuration */ TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable); by_Step = 5; break; } } |
|
相关推荐
9个回答
|
|
想问一下楼主的波形工具是什么?
|
|
|
|
|
|
|
|
|
|
|
|
是不是与您的逻辑分析仪的采样频率与采样深度有关系呢
|
|
|
|
|
|
|
|
|
|
现在好了,是brake的问题
|
|
|
|
关于如何输出六路互补带死区PWM波形,请关注“单片机STM32”公众号,里面有一篇文章“STM32定时器TIM1输出六路带死区互补PWM波形(一)”描述。
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1252 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1184 浏览 3 评论
2263 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1351 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1774 浏览 1 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 05:58 , Processed in 0.840955 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号