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,
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);
}
// }
}
Greetings Amit,
Firm/I noted this statement - very first post, "I am using the TI-RTOS example PWMLED."
I would have answered - but firm/clients refuse to, "lock ourselves in" to single vendor locked "solutions" - and portions of poster's code are not "pure" Stellaris/TM4 API.
Once again - as always - there is no/zero justification for use of the RTOS - and the clarity & power of the tried/true/tested Stellaris/TM4C API is compromised when brought under the (apparent) "heavy hand" of TI-RTOS .
Hello Amit,
This is the name of the folder of RTOS - sure you will get the version from it.
tirtos_tivac_2_10_01_38
Important to tell you that after I swapped Board_PWM1 to Board_PWM0 in the pwmled.c, I am getting PWM output on pin PF1. I added two new pwmhandles pwm3 and pwm4 and linked them with Board_PWM2 and Board_PWM3. after doing this I am also getting signal on PF2 and PF3. I cannot send you the new pwmled.c right-now but I will do it asap. Given I am losing the signal frequently, I fear there is some loose connections problem. I have soldered the right-angled header to my Tiva TM4C1294XL Connected Launchpad . Now it seems I must get a female connector to this header to ensure perfect connection. But I am definitely getting some signal on PF0, PF1, PF2 and PF3 even if it is intermittent. I will test it thoroughly and give you a report asap.
Thanking you,
Vikram
/* * Copyright (c) 2014, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== pwmled.c ======== */ /* XDCtools Header files */ #include <xdc/std.h> #include <xdc/cfg/global.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> /* TI-RTOS Header files */ #include <ti/drivers/PWM.h> /* Example/Board Header files */ #include "Board.h" /* * ======== pwmLEDFxn ======== * Task periodically increments the PWM duty for the on board LED. */ Void pwmLEDFxn(UArg arg0, UArg arg1) { PWM_Handle pwm1; PWM_Handle pwm2; PWM_Handle pwm3; PWM_Handle pwm4; 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_PF0 = 1050; uint16_t dutyRUN_PF1 = 1250; uint16_t dutyRUN_PF2 = 1500; uint16_t dutyRUN_PF3 = 1850; uint16_t CAL_time = 2000; uint16_t arm_time = 3000; PWM_Params_init(¶ms); params.period = pwmPeriod; pwm1 = PWM_open(Board_PWM1, ¶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_PWM0, ¶ms); } pwm3 = PWM_open(Board_PWM2, ¶ms); pwm4 = PWM_open(Board_PWM3, ¶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_PF0); if (pwm2) { PWM_setDuty(pwm2, dutyRUN_PF1); } PWM_setDuty(pwm3, dutyRUN_PF2); PWM_setDuty(pwm4, dutyRUN_PF3); // } } /* * ======== main ======== */ int main(void) { /* Call board init functions. */ Board_initGeneral(); Board_initGPIO(); Board_initPWM(); /* Turn on user LED */ GPIO_write(Board_LED0, Board_LED_ON); System_printf("Starting the example\nSystem provider is set to SysMin. " "Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
Hello Amit,
I attached the pwmled.c
I will come back to you as I have the signals.
Regards,
Vikram
Hi Amit,
I remade all the connections. I am getting all the 4 outputs after some code corrections. I even added 2 additional PWM outputs PG0 and PG1. they are also working correctly.
As a next step I will try to do as you say--based only on Tivaware. I have downloaded a project you attached in one of your posts on TM4C PWM - it is the same you mention above(reload_interrupt.c) but the signals are for 1294XL. I have already started adding the code for 4 PWM outputs. As soon as I complete and test, I will let you know.
Best regards,
Vikram
Hi Vikram,
I had a similar problem. The TI example pwmled example uses GPIO PF0 and the EK_TM4C1294XL.C and .h are set up only to provide PWM using PWM generator block 1. I have modified those files and board.h and now have PWM working on GPIO PF2 which is exactly what I want. I suspected this was the problem but would have struggled without your solution.
Thank you,
Russ