设置了PB6(M0PWM0) PB7(M0PWM1) PF2(M1PWM6) PF3(M1PWM7)四路PWM输出,使用示波器测量时发现,管脚PD0和PD1也有PWM波形输出,可是我在整个程序中并没有将其配置为PWM管脚,怀疑是其自动与某些通道的PWM同步输出了,请问该怎么将其关闭。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
设置了PB6(M0PWM0) PB7(M0PWM1) PF2(M1PWM6) PF3(M1PWM7)四路PWM输出,使用示波器测量时发现,管脚PD0和PD1也有PWM波形输出,可是我在整个程序中并没有将其配置为PWM管脚,怀疑是其自动与某些通道的PWM同步输出了,请问该怎么将其关闭。
楼主的板子是自己做的还是TI的开发板?
PD0和PD1程序中做什么什么配置吗,有源码贴上来吗?在这两个管脚上测量到的PWM信号占空比和幅度和那四路一样吗?
是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);
}
看一下TIVA C LAUNCHPAD TM4C123GXL的原理图,PD0和PB6通过0欧电阻(R9)相连,PD1和PB7通过0欧电阻(R10)相连
所以PD0 PD1有信号。
单独调试的话把电阻摘掉就行了。
问题解决了,十分感谢。一直以为是配置问题,折腾很久,没想到在硬件上做了连接。不知TI这样设计是为何?
这样设计可以验证一些功能,例如一个IO输出高电平,另外一个作为输入就能采集到电平值;或者输入配置为GPIO中断,响应边沿变化并进入中断服务程序等。