1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
知道怎么开启,关闭就不难了吧?禁止输出就可以了.
|
|
|
|
我是用定时器比较输出的,但是在TIM_ITConfig(TIM2, TIM_IT_CC1 , DISABLE);在中断使能这边把他关掉,还是有脉冲输出,但是如果关闭整个定时器,四个通道就都被关了,还有哪里语句可以关闭单个通道脉冲输出的,请各位大侠指教一下,谢谢!
|
|
|
|
这是小弟的程序,麻烦各位大侠指点一下,谢谢
u16 capture = 0; extern vu16 CCR1_Val; extern vu16 CCR2_Val; extern vu16 CCR3_Val; //extern vu16 CCR4_Val; void TIM_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // TIM_CtrlPWMOutputs(TIM2,ENABLE); TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 35; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; //PWM模式2 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //正向通道有效 TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;//反向通道无效 TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //占空时间 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性 TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //互补端的极性 TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM2,&TIM_OCInitStructure); //通道1 TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_OCInitStructure.TIM_Pulse = CCR2_Val; //占空时间 TIM_OC2Init(TIM2,&TIM_OCInitStructure); //通道2 TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_OCInitStructure.TIM_Pulse = CCR3_Val; //占空时间 TIM_OC3Init(TIM2,&TIM_OCInitStructure); //通道3 TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_Cmd(TIM2,ENABLE); // TIM_CtrlPWMOutputs(TIM2,ENABLE); TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2| TIM_IT_CC3 , ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_1| GPIO_Pin_0 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); } void WM_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_Configuration(); GPIO_Configuration(); } void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1 ); capture = TIM_GetCapture1(TIM2); TIM_SetCompare1(TIM2, capture + CCR1_Val ); } if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); capture = TIM_GetCapture2(TIM2); TIM_SetCompare2(TIM2, capture + CCR2_Val); } if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC3 ); capture = TIM_GetCapture3(TIM2); TIM_SetCompare3(TIM2, capture + CCR3_Val ); } } |
|
|
|
我用刚寄存器设置的.
用类似TIM3->CCER&=~(1<<4); //OC2 输出关闭 之类的试试吧. 如果还是不行,用绝招,直接把IO口设置为普通功能,或者设置为输入功能,此时横竖都不会输出PWM了.... |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1777 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1080 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
728 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1678 浏览 2 评论
1937浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
731浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
595浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
553浏览 3评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 00:46 , Processed in 0.899864 second(s), Total 82, Slave 66 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号