完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我现在在做一个STM32F0的实验,板子的电路图如下,当tiM2开启输出PWM波形后,OLED会变暗,别外一个板子还直接重启,是不是我哪里没有配置好的?找了好久一直没有找到原因,代码和电路图如下:
uint32_t ohm_freq = 238000; uint16_t ohm_percent = 500; void OHM_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //Charge_PWM GPIO Port GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_2); //DIO_Ctrl_Pin GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, GPIO_InitStructure); GPIO_ResetBits(GPIOB, GPIO_Pin_14); } void OHM_TIM_PWM_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; uint32_t TimerPeriod = 0; uint32_t ChannelPulse = 0; TimerPeriod = (SystemCoreClock/ohm_freq)-1; ChannelPulse = ohm_percent*(TimerPeriod - 1)/1000; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频系数(48-1), t=48/48000000=1us, 即TIMx->CNT每1us加一次 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式 TIM_TimeBaseStructure.TIM_Period = TimerPeriod;//TimerPeriod; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = ChannelPulse;//ChannelPulse;; //TIM_OC1Init(TIM2, TIM_OCInitStructure); TIM_OC4Init(TIM2, TIM_OCInitStructure); //放到Enable函数里面 //TIM_Cmd(TIM2, ENABLE); //TIM_CtrlPWMOutputs(TIM2, ENABLE); } void OHM_Chk_Timer_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03; NVIC_Init( NVIC_InitStructure); TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 50; //50ms TIM_TimeBaseStructure.TIM_Prescaler = 47999; //分频,1ms计数一次 TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x03; TIM_TimeBaseInit(TIM16, TIM_TimeBaseStructure); TIM_ClearITPendingBit(TIM16, TIM_IT_Update); TIM_ITConfig(TIM16, TIM_IT_Update, ENABLE); TIM_Cmd(TIM16, ENABLE); } void OHM_Init(void) { OHM_GPIO_Init(); OHM_TIM_PWM_Init(); OHM_Chk_Timer_Init(); } void OHM_Start(void) { TIM_Cmd(TIM2, ENABLE); TIM_CtrlPWMOutputs(TIM2, ENABLE); GPIO_SetBits(GPIOB, GPIO_Pin_14); } void OHM_Stop(void) { GPIO_ResetBits(GPIOB, GPIO_Pin_14); TIM_CtrlPWMOutputs(TIM2, DISABLE); TIM_Cmd(TIM2, DISABLE); } |
|
相关推荐
3个回答
|
|
OLED变暗怎么感觉像是电流不够造成的,系统复位重启感觉像是电压不稳,造成的。会不会是你的电路板有问题?
|
|
|
|
怀疑PWM输出有问题的话,可以把输出线切断看看
|
|
|
|
把uint32_t ohm_freq = 238000;改成uint32_t ohm_freq = 90000;就可以正常的了
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1718 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1600 浏览 1 评论
1040 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
716 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1654 浏览 2 评论
1911浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
703浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
553浏览 3评论
581浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
538浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-13 20:51 , Processed in 0.697670 second(s), Total 53, Slave 46 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号