本帖最后由 hzqy110 于 2020-10-31 23:35 编辑
STM32F030单片机PB12和PB13设置为PWM输出,在配置的占空比不为0时候,PWM输出波形都是正常的。但是在配置为PWM0时候,正常结果是IO输出低电平,但是实际示波器测试IO脚为低电平但是有很多杂波输出。一下是程序,有高手麻烦帮忙看一下
#define Frequency_Max 1000
#define Frequency_Pulse 0
#define LED5_Num GpioPin12
#define LED6_Num GpioPin13
#define LED5_GPIO GpioPortB
#define LED6_GPIO GpioPortB
#define LED5(a) Adt_SetCompareValue(AdtTIM6, AdtCompareA, a)
#define LED6(a) Adt_SetCompareValue(AdtTIM6, AdtCompareB, a)
void TIM6_GPIO_Config(void)
{
stc_gpio_config_t stcTIM6Port;
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE); //¶Ë¿ÚÍâÉèʱÖÓʹÄÜ
stcTIM6Port.enDir = GpioDirOut;
Gpio_Init(LED5_GPIO, LED5_Num, &stcTIM6Port);
Gpio_SetAfMode(LED5_GPIO,LED5_Num,LED5_GpioAf);
Gpio_Init(LED6_GPIO, LED6_Num, &stcTIM6Port);
Gpio_SetAfMode(LED6_GPIO,LED6_Num,LED6_GpioAf); //
while (Ok != Sysctrl_SetPeripheralGate(SysctrlPeripheralAdvTim, TRUE));//ADTÍâÉèʱÖÓʹÄÜ
}
void TIM6_Mode_Config(void)
{
stc_adt_basecnt_cfg_t stcAdtBaseCntCfg;
stc_adt_CHxX_port_cfg_t stcAdtTIM6ACfg;
stcAdtBaseCntCfg.enCntMode = AdtSawtoothMode; //Èý½Ç²¨A
stcAdtBaseCntCfg.enCntDir = AdtCntUp;
stcAdtBaseCntCfg.enCntClkDiv = AdtClkPClk0;
Adt_Init(AdtTIM6, &stcAdtBaseCntCfg); //ADTÔز¨£¬¼ÆÊýģʽ£¬Ê±ÖÓÅäÖÃ
Adt_SetPeriod(AdtTIM6, Frequency_Max); //ÖÜÆÚ
Adt_SetCompareValue(AdtTIM6, AdtCompareA, Frequency_Pulse); //ͨÓñȽϻù×¼Öµ¼Ä´æÆ÷AÉèÖÃ
Adt_SetCompareValue(AdtTIM6, AdtCompareB, Frequency_Pulse); //ͨÓñȽϻù×¼Öµ¼Ä´æÆ÷AÉèÖÃ
stcAdtTIM6ACfg.enCap = AdtCHxCompareOutput;
stcAdtTIM6ACfg.bOutEn = TRUE;
stcAdtTIM6ACfg.enPerc = AdtCHxPeriodHigh;
stcAdtTIM6ACfg.enCmpc = AdtCHxCompareLow;
stcAdtTIM6ACfg.enStaStp = AdtCHxStateSelSS;
stcAdtTIM6ACfg.enStaOut = AdtCHxPortOutLow; //¿ªÊ¼¶Ë¿Ú״̬ΪµÍµçƽ
stcAdtTIM6ACfg.enStpOut = AdtCHxPortOutLow; //½áÊø¶Ë¿Ú״̬ΪµÍµçƽ
Adt_CHxXPortConfig(AdtTIM6, AdtCHxA, &stcAdtTIM6ACfg); //¶Ë¿ÚCHAÅäÖÃ
Adt_CHxXPortConfig(AdtTIM6, AdtCHxB, &stcAdtTIM6ACfg); //¶Ë¿ÚCHAÅäÖÃ
Adt_StartCount(AdtTIM6);
}
|