设置了PB6(M0PWM0) PB7(M0PWM1) PF2(M1PWM6) PF3(M1PWM7)四路PWM输出,使用示波器测量时发现,管脚PD0和PD1也有PWM波形输出,可是我在整个程序中并没有将其配置为PWM管脚,怀疑是其自动与某些通道的PWM同步输出了,请问该怎么将其关闭。
Michael Sun:
楼主的板子是自己做的还是TI的开发板?
PD0和PD1程序中做什么什么配置吗,有源码贴上来吗?在这两个管脚上测量到的PWM信号占空比和幅度和那四路一样吗?
Jin Zhang2:
回复 Michael Sun:
是TI的TIVA C LAUNCHPAD TM4C123GXL 经测试,PD0的波形和PB6一致,PD1的波形和PB7的一致。全部源码如下:
#include <stdbool.h>#include <stdlib.h>#include <stdio.h>#include <stdint.h>#include "hw_memmap.h"#include "hw_nvic.h"#include "hw_types.h"#include "hw_sysctl.h"#include "hw_pwm.h"#include "gpio.h"#include "interrupt.h"#include "pin_map.h"#include "sysctl.h"#include "pwm.h"
void PwmInit(void);void SetPwm(unsigned long channel_1,unsigned long channel_2,unsigned long channel_3,unsigned long channel_4);
int main(){ SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); IntPriorityGroupingSet(2); PwmInit(); SetPwm(10,20,30,50); while(1) {}}
void PwmInit(void){ // Enable the peripherals used by this program SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7); GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3); GPIOPinConfigure(GPIO_PB6_M0PWM0); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinConfigure(GPIO_PF2_M1PWM6); GPIOPinConfigure(GPIO_PF3_M1PWM7);
//Configure PWM Clock to match system SysCtlPWMClockSet(SYSCTL_PWMDIV_8);
PWMGenConfigure(PWM0_BASE,PWM_GEN_0, PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC); PWMGenConfigure(PWM1_BASE,PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE,PWM_GEN_0, 25000); PWMGenPeriodSet(PWM1_BASE,PWM_GEN_3, 25000); PWMPulseWidthSet(PWM0_BASE,PWM_OUT_1,0); PWMPulseWidthSet(PWM1_BASE,PWM_OUT_6,0); PWMPulseWidthSet(PWM1_BASE,PWM_OUT_7,0); // Enable the PWM generator PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM1_BASE, PWM_GEN_3); // Turn on the Output pins PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT |PWM_OUT_1_BIT), true); PWMOutputState(PWM1_BASE, (PWM_OUT_6_BIT |PWM_OUT_7_BIT), true);}
void SetPwm(unsigned long channel_1,unsigned long channel_2,unsigned long channel_3,unsigned long channel_4){ PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, channel_1*250); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, channel_2*250); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, channel_3*250); PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, channel_4*250);}
Jin Zhang2:
回复 Michael Sun:
问题解决了,十分感谢。一直以为是配置问题,折腾很久,没想到在硬件上做了连接。不知TI这样设计是为何?
Jin Zhang2:
回复 Michael Sun:
原来是这样,明白了,谢谢!
zihuai lin:
回复 Jin Zhang2:
为什么不能参数为100时,没有电压输出?按理不是应该输出高电平吗?