This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
Currently I am obtaining 2 independent PWM signals from pin PB6 and PB7 using single PWM generator, such as:
MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_8); ui32PWMClock = ui32SysClkFreq / PWM_DIV; ui32Load = (ui32PWMClock / PWM_FRQ) - 1; MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0); MAP_GPIOPinConfigure(GPIO_PB7_M0PWM1); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32Load); MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0); MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
Right now, I am using count up down strategy to obtain 2 different PWM signals, from single generator.
Can I use different PWM generators on pin PB6 and PB7? So I can take advantage of pwm sync, and other features? Or would I have to rewire my board and use a different pin for the second pwm generator.
Best Regards,
Can
Hi Can,
Can I use different PWM generators on pin PB6 and PB7? So I can take advantage of pwm sync, and other features? Or would I have to rewire my board and use a different pin for the second pwm generator.
That is not possible. As you can see, only generator 0 is associated with PB6/PB7. No other generators are associated with these two pins. You will need to use different pins for the second PWM generator.
Hello Charles Tsai,
Yes, I noticed that PB6 and PB7 are associated with generator 0, and tried to use D0 as secondary PWM output. Here is the relevant part of my code now:
uint32_t ui32SysClkFreq = MAP_SysCtlClockGet(); uint8_t PWM_DIV = 8; uint16_t PWM_FRQ_A = 10; uint16_t PWM_FRQ_B = 10; MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_8); uint32_t ui32PWMClock = ui32SysClkFreq / PWM_DIV; uint32_t ui32LoadA = (ui32PWMClock / PWM_FRQ_A) - 1; uint32_t ui32LoadB = (ui32PWMClock / PWM_FRQ_B) - 1; MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0); MAP_GPIOPinConfigure(GPIO_PD0_M1PWM0); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); MAP_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32LoadA); MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32LoadB); MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0); MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true); MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_0); MAP_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true); // send zero pwm MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6000); MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, 3000);
However, I am not getting independent pwm signals, indeed, I am getting, same output from pins PB6 and PD0, with the PWM signals overlapped. If I change the duty cycle of the second PWM generator, the parts at the top of the pwm signal change in duty, almost as I am summing them.
So, my question is reduced to: how can I generate 2 independent pwm signals on tm4c123, with from 2 different modules.
Best Regards,
Can
answering my own question: PD0 and PB6 are connected with a 0ohm resistor on the launchpad, hence why the pwm's overlap. removing the resistor enabled me to have two different generators, running at different frequencies.
best regarrds,
can