下面是我改的代码,产生占空比可变的PWM波(PD0输出),进入中断后,标志位count赋值,熄灭LED(PG2)的,我有以下问题:(1)我代码编译下载后,LED常亮,并没有进入中断,同时测试端口也没有波形产生,不知道问题在哪?(2)中断 PWM0IntHandler()函数在Startup.s里如何定义? DCD IntDefaultHandler ; PWM Generator 0 DCD IntDefaultHandler ; PWM Generator 1
DCD IntDefaultHandler ; PWM Generator 2
是在上面的设置吗? 哪位用过这,帮忙看看吧!谢谢大家了! void PWM0IntHandler(void){
PWMGenIntClear(PWM_BASE,PWM_GEN_0,PWM_INT_CNT_LOAD);
if((PWMPulseWidthGet(PWM_BASE,PWM_OUT_0)+64)<=(PWMPulseWidthGet(PWM_BASE,PWM_OUT_0))*3/4)
{
PWMPulseWidthSet(PWM_BASE,PWM_OUT_0,PWMPulseWidthGet(PWM_BASE,PWM_OUT_0)+64);
}
else
{
PWMPulseWidthSet(PWM_BASE,PWM_OUT_0,64)
}
count++;
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIODirModeSet(GPIO_PORTG_BASE, GPIO_PIN_2, GPIO_DIR_MODE_OUT);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2,0);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2,0x04);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
GPIOPinTypePWM(GPIO_PORTD_BASE,GPIO_PIN_0);
PWMGenConfigure(PWM_BASE,PWM_GEN_0,PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM_BASE,PWM_GEN_0,64000);
PWMPulseWidthSet(PWM_BASE,PWM_OUT_0,64);
IntMasterEnable();
PWMIntEnable(PWM_BASE,PWM_INT_GEN_0);
PWMGenIntTrigEnable(PWM_BASE,PWM_GEN_0,PWM_INT_CNT_LOAD);
IntEnable(INT_PWM0);
PWMOutputState(PWM_BASE,PWM_OUT_0_BIT,true);
PWMGenEnable(PWM_BASE,PWM_GEN_0);
if (count>=1)
{
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2,0);
}
else
{
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2,0x04);
}
}
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>