请问哪位大哥,我用EasyArm8962编写了下面这个程序,想试着通过按键KEY1改变PWM的输出方式,为什么我的GEN0能够实现按键就正常翻转,而GEN1输出是翻转了,但是幅值变得小的很多,现在纠结中。
#include "systemInit.h"
#include "pwm.h"
// 主函数(程序入口)
int main(void)
{
jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 时钟初始化:晶振,6MHz
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeIn(GPIO_PORTE_BASE,GPIO_PIN_2);
GPIOIntTypeSet(GPIO_PORTE_BASE,GPIO_PIN_2,GPIO_LOW_LEVEL);
GPIOPinIntEnable(GPIO_PORTE_BASE,GPIO_PIN_2);
IntEnable(INT_GPIOE);
IntMasterEnable();
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
GPIOPinTypePWM(GPIO_PORTB_BASE,GPIO_PIN_0|GPIO_PIN_1);
GPIOPinTypePWM(GPIO_PORTF_BASE,GPIO_PIN_0);
GPIOPinTypePWM(GPIO_PORTG_BASE,GPIO_PIN_1);
GPIOPinTypePWM(GPIO_PORTE_BASE,GPIO_PIN_0|GPIO_PIN_1);
PWMGenConfigure(PWM_BASE,PWM_GEN_0,PWM_GEN_MODE_UP_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM_BASE,PWM_GEN_1,PWM_GEN_MODE_UP_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM_BASE,PWM_GEN_2,PWM_GEN_MODE_UP_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM_BASE,PWM_GEN_0,6000);
PWMPulseWidthSet(PWM_BASE,PWM_OUT_0,4000);
PWMDeadBandEnable(PWM_BASE,PWM_GEN_0,60,60);
PWMGenPeriodSet(PWM_BASE,PWM_GEN_1,6000);
PWMPulseWidthSet(PWM_BASE,PWM_OUT_2,4000);
PWMDeadBandEnable(PWM_BASE,PWM_GEN_1,60,60);
PWMGenPeriodSet(PWM_BASE,PWM_GEN_2,6000);
PWMPulseWidthSet(PWM_BASE,PWM_OUT_4,4000);
PWMDeadBandEnable(PWM_BASE,PWM_GEN_2,60,60);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeriEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeOut(GPIO_PORTA_BASE,GPIO_PIN_4);
GPIOPinTypeOut(GPIO_PORTC_BASE,GPIO_PIN_5);
GPIOPinTypeOut(GPIO_PORTB_BASE,GPIO_PIN_6);
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT|PWM_OUT_2_BIT|PWM_OUT_3_BIT|PWM_OUT_4_BIT|PWM_OUT_5_BIT,false);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4,0x00);
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_5,0x00);
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,0x00);
PWMGenEnable(PWM_BASE,PWM_GEN_0);
PWMGenEnable(PWM_BASE,PWM_GEN_1);
PWMGenEnable(PWM_BASE,PWM_GEN_2);
for (;;)
{
}
}
void GPIO_Port_E_ISR(void){
unsigned long ulStatus;
static unsigned long temp=0;
ulStatus=GPIOPinIntStatus(GPIO_PORTE_BASE,true);
GPIOPinIntClear(GPIO_PORTE_BASE,ulStatus);
if(temp%3==0){
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT|PWM_OUT_2_BIT|PWM_OUT_3_BIT|PWM_OUT_4_BIT|PWM_OUT_5_BIT,false);
PWMOutputInvert(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,false);
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,true);
PWMOutputInvert(PWM_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,false);
PWMOutputState(PWM_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,true);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4,~(GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_4)));
}
if(temp%3==1){
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT|PWM_OUT_2_BIT|PWM_OUT_3_BIT|PWM_OUT_4_BIT|PWM_OUT_5_BIT,false);
PWMOutputInvert(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,true);
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT|PWM_OUT_1_BIT,true);
PWMOutputInvert(PWM_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,true);
PWMOutputState(PWM_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,true);
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_5,~(GPIOPinRead(GPIO_PORTC_BASE,GPIO_PIN_5)));
}
if(temp%3==2){
PWMOutputState(PWM_BASE,PWM_OUT_4_BIT|PWM_OUT_5_BIT|PWM_OUT_2_BIT|PWM_OUT_3_BIT|PWM_OUT_0_BIT|PWM_OUT_1_BIT,false);
PWMOutputState(PWM_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT,true);
PWMOutputState(PWM_BASE,PWM_OUT_4_BIT|PWM_OUT_5_BIT,true);
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,~(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_6)));
}
temp++;
SysCtlDelay(10*(TheSysClock/3000));
while(GPIOPinRead(GPIO_PORTE_BASE,GPIO_PIN_2)==0x00);
SysCtlDelay(10*(TheSysClock/3000));
}
此帖出自
小平头技术问答
怎么测的?PWM信号有占空比,平均电压当然低于Vcc,要用示波器看,另外,如果负载过重要加缓冲。
一周热门 更多>