本人使用GD32F207VC
开发板无法输出互补PWM波形。程序使用高级定时器时钟1,将PA8和PB11设为互补PWM输出引脚。具体程序如下。请各位帮我看一下。谢谢!程序编译无措。
- #include "gd32f20x.h"
- #include <stdio.h>
- #include "systick.h"
- int compare ;
- void TIM8_init()
- {
- TIMER_BaseInitPara tim1_int;// ʱÖÓ1³õʼ»¯
- TIMER_BKDTInitPara tim1_DT; //ʱÖÓ1ËÀÇøʱ¼ä
- TIMER_OCInitPara tim1_OC; // ʱÖÓ1ͨµÀÉèÖÃ
- tim1_int.TIMER_Period = 1200;// 120Mʱ¿ª¹ØƵÂÊ100k
- tim1_int.TIMER_Prescaler = 0;//¶¨Ê±Æ÷ʱÖÓΪ120M
- tim1_int.TIMER_ClockDivision = TIMER_CDIV_DIV1;//¶¨Ê±Æ÷ʱÖÓΪ120M
- tim1_int.TIMER_CounterMode = TIMER_COUNTER_UP;//ÏòÉϼÆÊý
- TIMER_BaseInit(TIMER1,&tim1_int);
-
- //ÅäÖÃËÀÇøʱ¼ä ËÀÇøΪ0.1us
-
- tim1_DT.TIMER_ROSState = TIMER_ROS_STATE_ENABLE;
- tim1_DT.TIMER_IOSState = TIMER_IOS_STATE_ENABLE;
- tim1_DT.TIMER_LOCKLevel = TIMER_LOCK_LEVEL_OFF;
- tim1_DT.TIMER_DeadTime = 12;
- tim1_DT.TIMER_Break = TIMER_BREAK_DISABLE;
- tim1_DT.TIMER_BreakPolarity = TIMER_BREAK_POLARITY_LOW;
- tim1_DT.TIMER_OutAuto = TIMER_OUTAUTO_DISABLE ;
- TIMER_BKDTConfig(TIMER1,&tim1_DT);
-
- //ÉèÖÃͨµÀ1£¬Í¨µÀ1N
-
- tim1_OC.TIMER_OCMode = TIMER_OC_MODE_PWM1;//¼ÆÊýֵСÓÚÉ趨ֵΪÓÐЧµçƽ
- tim1_OC.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;//Êä³ö±È½ÏʹÄÜ
- tim1_OC.TIMER_OutputNState = TIMER_OUTPUTN_STATE_ENABLE;//Êä³ö±È½Ï·´ÏòʹÄÜ
- tim1_OC.TIMER_Pulse = compare;//±È½ÏÖµ
- tim1_OC.TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;//ÓÐЧµçƽΪ¸ßµçƽ
- tim1_OC.TIMER_OCNPolarity = TIMER_OCN_POLARITY_HIGH;//ÓÐЧµçƽΪ¸ßµçƽ
- tim1_OC.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_SET;//¿ÕÏÐʱÒý½Å״̬
- tim1_OC.TIMER_OCNIdleState = TIMER_OCN_IDLE_STATE_RESET;//¿ÕÏÐʱÒý½Å×´
- TIMER_OC1_Init(TIMER1,&tim1_OC);
- TIMER_OC1_Preload(TIMER1,TIMER_OC_PRELOAD_ENABLE);//×Ô¶¯×°ÔØʹÄÜ
- TIMER_Enable(TIMER1,ENABLE);
- TIMER_CtrlPWMOutputs(TIMER1,ENABLE);//¿ªÆôON£¬OCÊä³ö£¨BDTR£©
- // TIMER_CC_PreloadControl(TIMER1,ENABLE);
- }
- void PWM_GPIO_init()
- {
- GPIO_InitPara GPIO_InitPara;
- RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER1,ENABLE);
- RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_GPIOB, ENABLE);
- GPIO_InitPara.GPIO_Pin = GPIO_PIN_8;
- GPIO_InitPara.GPIO_Mode = GPIO_MODE_AF_PP;
- GPIO_InitPara.GPIO_Speed = GPIO_SPEED_50MHZ;
- GPIO_Init(GPIOA,&GPIO_InitPara);//ÅäÖÃPA7Ϊ¸´ÓÃÍÆÍì TM8-CH1N
- GPIO_InitPara.GPIO_Pin = GPIO_PIN_13;
- GPIO_InitPara.GPIO_Mode = GPIO_MODE_AF_PP;
- GPIO_InitPara.GPIO_Speed = GPIO_SPEED_50MHZ;
- GPIO_Init(GPIOB,&GPIO_InitPara);//ÅäÖÃPC6Ϊ¸´ÓÃÍÆÍì TM8-CH1
- }
- int main(void)
- {
- compare = 800;
- TIM8_init();
- PWM_GPIO_init();
-
- while(1)
- {
- compare = 800;
- TIMER_Compare1Config(TIMER1,compare);
-
- }
-
- }
复制代码
一周热门 更多>