Greetings,
Trying to configure one of the GP Timers on CC2538 to function as a PWM Generator. So far, absolutely no success.
Tried to configure as follows:
Timer 0, Section A
Mapped to I/O port A, Pin 0
Port A Pin 0 mapped to Input Capture 1
Nothing real fancy here.
Here is the test code (derived from TI Example Project GPTimer -- periodic_prescaler_16bit
found in the cc2538_foundation_firmware_1_0_1_0 driverlib stuff) :
====================================================================
int
main(void)
{
int delayIndex;
unsigned int pwmDutyCycle = 0x0000;
//
// Initialize the interrupt counter.
//
g_ui32Counter = 0;
//
// Set the clocking to run directly from the external crystal/oscillator.
// (no ext 32k osc, no internal osc)
//
SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);
//
// Set IO clock to the same as system clock
//
SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
//
// The Timer0 peripheral must be enabled for use.
//
SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);
//
// Set up the serial console to use for displaying messages. This is
// just for this example program and is not needed for Timer operation.
//
InitConsole();
//
// Display the example setup on the console.
//
UARTprintf("16-Bit Timer PWM ->");
UARTprintf("\n Timer = Timer0B");
UARTprintf("\n Mode = PWM with variable duty cycle");
//
// Configure GPTimer0A as a 16-bit PWM Timer.
//
TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM);
//
// Set the GPTimer0B load value to 1sec by setting the timer load value
// to SYSCLOCK / 255. This is determined by:
// Prescaled clock = 16Mhz / 255
// Cycles to wait = 1sec * Prescaled clock
TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, SysCtrlClockGet() / 4000);
TimerControlLevel(GPTIMER0_BASE, GPTIMER_A, false);
// Configure GPIOPortA.0 as the Timer0_InputCapturePin.1
IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_0, IOC_MUX_OUT_SEL_GPT0_ICP1);
// Tell timer to use GPIOPortA.0
// Does Direction Selection and PAD Selection
GPIOPinTypeTimer(GPIO_A_BASE, GPIO_PIN_0);
//
// Enable processor interrupts.
//
IntMasterEnable();
//
// Enable GPTimer0B.
//
TimerEnable(GPTIMER0_BASE, GPTIMER_A);
UARTprintf("\n");
//
// Loop forever while the Timer0B runs.
//
while(1)
{
for (delayIndex = 0; delayIndex < 100000; delayIndex++);
pwmDutyCycle += 0x0F;
pwmDutyCycle &= 0xFFFF;
TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, pwmDutyCycle);
UARTprintf("PWM DC Value: %04X -- %04X -- %04X\r",
pwmDutyCycle,
TimerValueGet(GPTIMER0_BASE, GPTIMER_A),
TimerMatchGet(GPTIMER0_BASE, GPTIMER_A) );
}
}
====================================================================
Thanks in advance.
mDupont