Hello,
I am trying since many months to obtain at least 4-8 PWM outputs from my connected Launchpad.
I am using the TI-RTOS example PWMLED to construct a project according to my needs. The aim is to have 4 PWM outputs to control the 4 motors of a Quadcopter.
I have followed all the recommendations of a post made by Emmanuel which explains how to create many instances of PWM . I test my PWM output by connecting the output pin PF0 to a ESC then to a motor. At present, I get the motor running well on PF0, but not on PF1.
Here I paste the modifications I done to the three files EKTM4C1294XL.c, EK_TM4C1294XL.h, Board.h and pwmled.c. I don't know if its possible for me to send the whole project. But its very simple - load the example project from TI resource explorer and do the modifs below.
I would highly appreciate if someone can identify what is missing for me to get the same output as I am obtaining on PF0 similary on PF1, PF2, PF3 and PF4
---------------------------------------------------------(EKTM4C1294XL.c)------------------------------------------
PWMTiva_Object pwmTivaObjects[EK_TM4C1294XL_PWMCOUNT];
/* PWM configuration structure */
const PWMTiva_HWAttrs pwmTivaHWAttrs[EK_TM4C1294XL_PWMCOUNT] = {
{
PWM0_BASE,
PWM_OUT_0,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
},
{
PWM0_BASE,
PWM_OUT_1,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
},
{
PWM0_BASE,
PWM_OUT_2,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
},
{
PWM0_BASE,
PWM_OUT_3,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
}
};
const PWM_Config PWM_config[] = {
{&PWMTiva_fxnTable, &pwmTivaObjects[0], &pwmTivaHWAttrs[0]},
{&PWMTiva_fxnTable, &pwmTivaObjects[1], &pwmTivaHWAttrs[1]},
{&PWMTiva_fxnTable, &pwmTivaObjects[2], &pwmTivaHWAttrs[2]},
{&PWMTiva_fxnTable, &pwmTivaObjects[3], &pwmTivaHWAttrs[3]},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initPWM ========
*/
void EK_TM4C1294XL_initPWM(void)
{
/* Enable PWM peripherals */
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
/*
* Enable PWM output on GPIO pins. PWM output is connected to an Ethernet
* LED on the development board (D4). The PWM configuration
* below will disable Ethernet functionality.
*/
GPIOPinConfigure(GPIO_PF0_M0PWM0);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PF1_M0PWM1);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinConfigure(GPIO_PF2_M0PWM2);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOPinConfigure(GPIO_PF3_M0PWM3);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
PWM_init();
}
---------------------------------------------------------------(EK_TM4C1294XL.h)--------------------------------------------------
typedef enum EK_TM4C1294XL_PWMName {
EK_TM4C1294XL_PWM0 = 0,
EK_TM4C1294XL_PWM1,
EK_TM4C1294XL_PWM2,
EK_TM4C1294XL_PWM3,
EK_TM4C1294XL_PWMCOUNT
} EK_TM4C1294XL_PWMName;
----------------------------------------------------------(Board.h)------------------------------------
#define Board_PWM0 EK_TM4C1294XL_PWM0
#define Board_PWM1 EK_TM4C1294XL_PWM1
#define Board_PWM2 EK_TM4C1294XL_PWM2
#define Board_PWM3 EK_TM4C1294XL_PWM3
--------------------------------------------------------------------------(PWMled.c)----------------------------------------------------------------
PWM_Handle pwm1;
PWM_Handle pwm2 = NULL;
PWM_Params params;
uint16_t pwmPeriod = 20000; // Period and duty in microseconds
uint16_t duty = 0;
uint16_t dutyInc = 100;
uint16_t dutyARM = 1000;
uint16_t dutyCALH = 2000;
uint16_t dutyCALL = 1000;
uint16_t dutyRUN = 1200;
uint16_t CAL_time = 2000;
uint16_t arm_time = 3000;
PWM_Params_init(¶ms);
params.period = pwmPeriod;
pwm1 = PWM_open(Board_PWM0, ¶ms);
if (pwm1 == NULL) {
System_abort("PWM0 did not open");
}
if (Board_PWM1 != Board_PWM0) {
// params.polarity = PWM_POL_ACTIVE_LOW;
pwm2 = PWM_open(Board_PWM1, ¶ms);
}
/* Loop forever incrementing the PWM duty */
// while (1) {
PWM_setDuty(pwm1, dutyCALH);
if (pwm2) {
PWM_setDuty(pwm2, dutyCALH);
}
Task_sleep((uint16_t) CAL_time);
PWM_setDuty(pwm1, dutyCALL);
if (pwm2) {
PWM_setDuty(pwm2, dutyCALL);
}
// duty = (duty + dutyInc);
// if (duty == pwmPeriod || (!duty)) {
// dutyInc = - dutyInc;
// }
Task_sleep((uint16_t) CAL_time);
PWM_setDuty(pwm1, dutyARM);
if (pwm2) {
PWM_setDuty(pwm2, dutyARM);
}
Task_sleep((uint16_t) arm_time);
PWM_setDuty(pwm1, dutyRUN);
if (pwm2) {
PWM_setDuty(pwm2, dutyRUN);
}
// }
}