Hi, So I am using the following code to generate a PWM signal, I eventually want it to working in this manner, I want it to be producing a certain frequency and then I would get an interrupt that would have me switch to a different frequency. For now, I haven't set up the interupt but tried to use a delay to mimic the intended operation. So I basically have it producing a certain frequency, delay for period of time, then switch the frequency after the delay. However, I am unable to do this, I end up in the Fault ISR loop, whenever I try to make this change.
I have tried using PWMdisable and setting PWMOutputState to false before changing and then re-configuring it. I also tried just changing PWMGenPeriodSet and PWMGenWidthSet only without calling the full function again but that also failed.
Any help or ideas would be appreciated.
void
configurePWM(int test)
{
uint32_t Ticks;
Ticks = test; //Number_Ticks_Freq();
//PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
//PWMGenDisable(PWM0_BASE, PWM_GEN_0);
//
// Enable the GPIO Peripheral used by PWM (PF0, and eventually PF1)
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Enable PWM0
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
//
//Dividing the clock for PWM use - Will use one for now
//
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
//
//Unlocking the pins
//
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x01;
//
// Configure GPIO pin for PWM
//
GPIOPinConfigure(GPIO_PF0_M0PWM0);
GPIOPinConfigure(GPIO_PF1_M0PWM1);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Configure PWM
//
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
//Setting PWM Period
//
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ceil(Ticks));
//
//Setting duty cycle
//
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0 , ceil(Ticks/2));
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1 , ceil(Ticks/2));
//
// Enable PWM
//
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMOutputInvert(PWM0_BASE, PWM_OUT_1_BIT, true);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
}
int
main(void)
{
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
configurePWM(1000);
//configureUART();
//IntMasterEnable(); // Enable the processor to respond to interrupts.
//Induction_Pulse();
SysCtlDelay(40000000*10); //40000000 = 120MHz/3 = 1 sec so this should be ten seconds - read in previous forum that thats how to get close to one sec delay
configurePWM(500);
// SysCtlDelay(400000);
//TimerEnable(TIMER0_BASE, TIMER_BOTH);
while(1)
{
}
}