完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
新手,为什么STM32f429就是不能输出pwm波形 ,检查了好多遍就是找不到问题,怎么办 ?? 是我配置出问题了吗??代码如下,有大神能指教一下吗,/*¶¨Òå½á¹¹Ìå*/
GPIO_InitTypeDef GPIO_InitStructure; tiM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /*¿ªÆôÏà¹ØµÄGPIOÍâÉèʱÖÓ*/ RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd ( RCC_APB1Periph_TIM2, ENABLE); /* */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM2); GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_TIM2); GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_TIM2); GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_TIM2); TIM_TimeBaseStructure.TIM_Period = (1000000-1); //µ±¶¨Ê±Æ÷´Ó0¼ÆÊýµ½ TIM_Period+1 £¬ÎªÒ»¸ö¶¨Ê±ÖÜÆÚ TIM_TimeBaseStructure.TIM_Prescaler = 17; //ÉèÖÃÔ¤·ÖƵ TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //ÉèÖÃʱÖÓ·ÖƵϵÊý£º²»·ÖƵ(ÕâÀïÓò»µ½) TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ // ³õʼ»¯¶¨Ê±Æ÷TIMx, x[2,3,4,5] TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /*PWMģʽÅäÖÃ*/ /* PWM1 Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÅäÖÃΪPWMģʽ1 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ʹÄÜÊä³ö TIM_OCInitStructure.TIM_Pulse = 0; //ÉèÖóõʼPWMÂö³å¿í¶ÈΪ0 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //µ±¶¨Ê±Æ÷¼ÆÊýֵСÓÚCCR1_ValʱΪµÍµçƽ LEDµÆÁÁ //ʹÄÜͨµÀ1 TIM_OC1Init(TIM2, &TIM_OCInitStructure); /*ʹÄÜͨµÀÖØÔØ*/ TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable); //ʹÄÜͨµÀ2 TIM_OC2Init(TIM2, &TIM_OCInitStructure); /*ʹÄÜͨµÀÖØÔØ*/ TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); //ʹÄÜͨµÀ3 TIM_OC3Init(TIM2, &TIM_OCInitStructure); /*ʹÄÜͨµÀÖØÔØ*/ TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable); //ʹÄÜͨµÀ4 TIM_OC4Init(TIM2, &TIM_OCInitStructure); /*ʹÄÜͨµÀÖØÔØ*/ TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable); TIM_CtrlPWMOutputs(TIM2, ENABLE); // ¿ªÆô¼ÆÊýÆ÷ÖÐ¶Ï //TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); // ʹÄܼÆÊýÆ÷ TIM_Cmd(TIM2, ENABLE); |
|
相关推荐
2 个讨论
|
|
你正在撰写讨论
如果你是对讨论或其他讨论精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
828 浏览 0 评论
824 浏览 0 评论
861 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
836 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1292 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11824 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 20:46 , Processed in 0.704692 second(s), Total 48, Slave 37 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号