2个问题: 1:我买了您的开发板LM3S615 , 我用于做逆变电源项目,需要逐周期更新占空比,您的demo 没有带PWM 在中断中更新占空值的例程,自己作了pwm的初始化就是不进中断为什么,能给个例程么? 2:您给的crossstudio for arm是测试版,期限是一个月我想知道一个月之后我该怎么办?
我的初始化程序
HWREG(SYSCTL_RCC) &= (~SYSCTL_RCC_USE_PWMDIV); // PWM时钟源1分频 HWREG(SYSCTL_RCGC2) |= SYSCTL_PERIPH_GPIOD; // 使能PD口外设 HWREG(SYSCTL_RCGC0) |= SYSCTL_PERIPH_PWM; // 使能PWM外设 IntMasterEnable(); // 处理器使能。 HWREG(GPIO_PORTD_BASE + GPIO_O_DIR) |= 0x00000003; // 设置PD0,PD1为输出 HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) |= 0x00000003; // 选择硬件功能,即PWM // 设置PWM发生器0为上下计数方式,两路PWM不同步 HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_CTL ) &= (~0x0000003F); HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_CTL ) |= PWM_GEN_MODE_UP_DOWN; HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_GENA) &=(~0x00000FFF); HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_GENA) |=((PWM_GEN_ACT_ONE<<PWM_GEN_ACT_A_UP_SHIFT)| (PWM_GEN_ACT_ZERO<<PWM_GEN_ACT_A_DN_SHIFT)); HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_GENB) &=(~0x00000FFF); HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_GENB) |=((PWM_GEN_ACT_ONE<<PWM_GEN_ACT_B_UP_SHIFT)| (PWM_GEN_ACT_ZERO <<PWM_GEN_ACT_B_DN_SHIFT));
HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_LOAD) = 84; // 设置两路PWM的共同周期 HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_CMPA) = 40; // 分别设置两路PWM的匹配值 HWREG(PWM_BASE + PWM_O_ENABLE) |= 0x00000003; // 使能PWM0和PWM1输出到引脚 HWREG(PWM_BASE + PWM_GEN_0_OFFSET+PWM_O_X_DBRISE) = 2; // Gen DB Rising Edge Delay Reg HWREG(PWM_BASE + PWM_GEN_0_OFFSET+PWM_O_X_DBFALL) =2; // Gen DB Falling Edge Delay Reg HWREG(PWM_BASE + PWM_GEN_0_OFFSET+PWM_O_X_DBCTL)|= 1; // Gen Dead Band Ctrl Reg
//HWREG(PWM_BASE + PWM_GEN_0_OFFSET+PWM_O_X_INTEN)|= 1; //清中断标志位 HWREG(PWM_BASE + PWM_GEN_0_OFFSET+PWM_O_X_INTEN)|= 1; //计数器为零允许产生中断 HWREG(PWM_BASE +PWM_O_INTEN)|=1; //PWM控制模块的全局中断允许 //PWMGenIntTrigEnable(PWM_BASE, PWM_GEN_0,PWM_INT_CNT_ZERO ); //jihuo HWREG(PWM_BASE + PWM_GEN_0_OFFSET + PWM_O_X_CTL ) |= 0x00000001;// 使能PWM发生器0
我的初始化程序第2种方法
SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // PWM时钟源1分频 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // 使能PD口外设 SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // 使能PWM外设 IntMasterEnable(); // 处理器使能。 GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 );// 设置PD0,PD1为PWM0和PWM1 PWMGenConfigure(PWM_BASE, PWM_GEN_0, // 设置PWM发生器0为上下计数方式,两路PWM不同步 PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 84); // 设置两路PWM的共同周期
PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,30); // 分别设置两路PWM的匹配值 PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);// 使能PWM0和PWM1 PWMDeadBandEnable(PWM_BASE,PWM_GEN_0,5,5); //使能死区
//PWMIntEnable(PWM_BASE,PWM_INT_GEN_0); // 使能中断PWM_GEN_0/////??? PWMGenEnable(PWM_BASE, PWM_GEN_0); // 使能PWM发生器0 //PWMGenIntRegister(PWM_BASE,PWM_GEN_0 ,PWM_Generator_0_ISR);//PWM_GEN_0,PWM_Generator_0_ISR()); //chulihanshu
PWMGenIntTrigEnable(PWM_BASE, PWM_GEN_0,PWM_INT_CNT_ZERO); //| PWM_INT_CNT_LOAD); //jihuo IntEnable(INT_PWM0 ); // 使能中断 IntEnable(PWM_GEN_0); // 使能中断
|