完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用默认引脚输出6路PWM,#define FullRemap_TIM1则重映射 PIN脚;
遗留问题:调用TIM_CCxNCmd(TIM1, TIM_Channel_X, TIM_CCx_Enable);导致互补PWM无输出。 TIM_CCxCmd(TIM1, TIM_Channel_X, TIM_CCx);确可以正常开关PWM输出; 遇到问题:PA8、10、PB13、14、15均有输出,PA9无输出; 问题解决:虽然没初始化UART1模块,但打开RCC_APB2Periph_USART1时钟导致; void Timer1_Init(void) { TIM_OCInitTypeDef TIM_OCInitStructure; GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_BDTRInitTypeDef TIM_BDTRInitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); #ifdef FullRemap_TIM1 GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE); #endif 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); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); #ifdef FullRemap_TIM1 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9 |GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); #endif TIM_TimeBaseStructure.TIM_Period = 5999;//ARR 10K TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Prescaler = 99;//??????1us TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); 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 = 1000;//CCR TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //关断后PWM默认输出状态 TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = 2000;//CCR TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = 3000;//CCR TIM_OC3Init(TIM1, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable); TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable); 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 = 0; TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High; TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_ITConfig(TIM1,TIM_IT_Update, ENABLE); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_ClearITPendingBit(TIM1, TIM_IT_Update); TIM_CtrlPWMOutputs(TIM1, ENABLE); TIM_Cmd(TIM1, ENABLE); //TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); //TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); //TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); //TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); //TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); //TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); } void TIM1_UP_IRQHandler(void) // { if(TIM_GetITStatus(TIM1,TIM_IT_Update)!=RESET) { TIM_ClearITPendingBit(TIM1,TIM_IT_Update); } } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1152 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1184 浏览 1 评论
602 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
449 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1089 浏览 2 评论
1645浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
311浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
313浏览 3评论
306浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
278浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-27 06:03 , Processed in 0.727894 second(s), Total 46, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191