Other Parts Discussed in Thread: SYSBIOS, AM3359
We are having trouble implementing a PWM signal using the TM4C123X's hardware in a TI RTOS system. I want to preface by referencing these two posts:
- How to use the PWM on AM3359 running the SYSBIOS
- TI-RTOS exits on PWMGenConfigure function, very odd bug
So apparently TI-RTOS still doesn't support some sort of PWM creation/generation that directly uses the hardware. I have two options to create a pwm signal
- Create my own driver that uses the driverlib api
- Create a TI-RTOS timer based PWM that does a simple GPIO toggle
I have managed to create a TI-RTOS based PWM that gets the job done but the concern is that it will take up valuable cpu cycles in a system that will be heavily taxed during its application. I would like to implement a hardware based PWM but am running into problems similar to the "TI-RTOS exits on PWMGenConfigure function, very odd bug" post listed above. When I run our PWM setup code the system faults on the PWMGenConfigure() function. In particular, it faults at the "// Change the global configuration of the generator." section of code in the PWMGenConfigure() function:
//
// Change the global configuration of the generator.
//
HWREG(ui32Gen + PWM_O_X_CTL) = ((HWREG(ui32Gen + PWM_O_X_CTL) &
~(PWM_X_CTL_MODE | PWM_X_CTL_DEBUG |
PWM_X_CTL_LATCH | PWM_X_CTL_MINFLTPER |
PWM_X_CTL_FLTSRC |
PWM_X_CTL_DBFALLUPD_M |
PWM_X_CTL_DBRISEUPD_M |
PWM_X_CTL_DBCTLUPD_M |
PWM_X_CTL_GENBUPD_M |
PWM_X_CTL_GENAUPD_M |
PWM_X_CTL_LOADUPD | PWM_X_CTL_CMPAUPD |
PWM_X_CTL_CMPBUPD)) | ui32Config);
Below is our PWM init code:
void EK_TM4C123GXL_initPWM(void)
{
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
//Enable the PWM peripheral
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
//Configure the pins for PWM
GPIOPinConfigure(GPIO_PB1_T2CCP1);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_1);
//configure the PWM
PWMGenConfigure( PWM1_BASE, PWM_GEN_1, (PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_STOP));
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 64000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, PWMGenPeriodGet(PWM1_BASE, PWM_OUT_1) / 4);
PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
return;
}
The code compiles and links correctly with out errors or warnings. Also, EK_TM4C123GXL_initGeneral() (which enables all the SYSCTL_PERIPH_GPIO[A - F]) is called before EK_TM4C123GXL_initPWM() and SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1) is called before PWMGenConfigure() so I believe all the peripherals needed are enabled.
But, whenever I get to the PWMGenConfigure()function the system faults. The difference in code from the examples and above related posts is the pin that is used for the PWM. The TM4C123X family uses a Capture Compare PWM pin configurationon and not a "direct" PWM pin configuration. I figured that when I configured the pin for PWM I should call GPIOPinConfigure() with a parameter of GPIO_PB1_T2CCP1 as seen in the code snippet below:
//Example code GPIOPinConfigure(GPIO_PF0_M0PWM0); //Our code GPIOPinConfigure(GPIO_PB1_T2CCP1);
So my question is, how do I set up the PWM in a TI RTOS system without using a timer and with out causing a system fault during configuration?