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.

PWM handle not recognized in Hwi thread

Other Parts Discussed in Thread: TM4C129ENCPDT

I am working on a sinewave inverter project based on TM4C129ENCPDT and TI-RTOS. I use PWM0 outputs 0 to 3 to drive H-Bridge.It is based on the example "pwmled" supplied with CCS which is ver. 6.1.1.0002. I already do fan regulation with PWM1 output 7 and other things.

The problem is generating the sinewave. The desired switching frequency is ~14kHz so I need to adjust the PWM duty in intervals of 71us. I found out it can be done with usage of Hwi. It is configured correctly in .cfg and it calls the function normally. The problem is I can not use PWM_setDuty function in the Hwi, because it tells that the handler is undefined:

Void sinetimer(UArg arg) // sinewave hwi, called every 71us
	{
    PWM_setDuty(pwm0,5);
    PWM_setDuty(pwm1,5);
    PWM_setDuty(pwm2,5);
    PWM_setDuty(pwm3,5);

	};

returns

#20 identifier "pwm0" is undefined    pwmled.c    /pwmled_EK_TM4C129EXL_TI_TivaTM4C129ENCPDT    line 108    C/C++ Problem
#20 identifier "pwm1" is undefined    pwmled.c    /pwmled_EK_TM4C129EXL_TI_TivaTM4C129ENCPDT    line 109    C/C++ Problem
#20 identifier "pwm2" is undefined    pwmled.c    /pwmled_EK_TM4C129EXL_TI_TivaTM4C129ENCPDT    line 110    C/C++ Problem
#20 identifier "pwm3" is undefined    pwmled.c    /pwmled_EK_TM4C129EXL_TI_TivaTM4C129ENCPDT    line 111    C/C++ Problem


Timer definition in .cfg file:

/* Create sineTimer as source of Hwi */
var Timer = xdc.useModule('ti.sysbios.hal.Timer');
var timerParams = new Timer.Params();
timerParams.startMode = Timer.StartMode_USER;
timerParams.runMode = Timer.RunMode_ONESHOT;
timerParams.period = 71; // 71us ~ 14kHz
Program.global.sineTimer = Timer.create(Timer.ANY, "&sinetimer", timerParams);

PWM configuration in main functionn:

 //PWM1L
    PWM_Params params;
    PWM_Handle pwm0;
    PWM_Params_init(&params);
    params.period = pwmPeriod;
    params.polarity = PWM_POL_ACTIVE_HIGH;
    pwm0 = PWM_open(PWM0, &params);
    if (pwm0 == NULL) {
    System_abort("pwm0 did not open");
    }

    //PWM1H
    PWM_Handle pwm1;
    PWM_Params_init(&params);
    params.period = pwmPeriod;
    params.polarity = PWM_POL_ACTIVE_LOW;
    pwm1 = PWM_open(PWM1, &params);
    if (pwm1 == NULL) {
    System_abort("pwm1 did not open");
    }

    //PWM2L
    PWM_Handle pwm2;
    PWM_Params_init(&params);
    params.period = pwmPeriod;
    params.polarity = PWM_POL_ACTIVE_HIGH;
    pwm2 = PWM_open(PWM2, &params);
    if (pwm2 == NULL) {
    System_abort("pwm2 did not open");
    }

    //PWM2H
    PWM_Handle pwm3;
    PWM_Params_init(&params);
    params.period = pwmPeriod;
    params.polarity = PWM_POL_ACTIVE_LOW;
    pwm3 = PWM_open(PWM3, &params);
    if (pwm3 == NULL) {
    System_abort("pwm3 did not open");
    }

//synchronization
    PWMSyncTimeBase(PWM0_BASE,PWM_GEN_0_BIT|PWM_GEN_1_BIT|PWM_GEN_2_BIT|PWM_GEN_3_BIT);
    PWMSyncUpdate(PWM0_BASE,PWM_GEN_0_BIT|PWM_GEN_1_BIT|PWM_GEN_2_BIT|PWM_GEN_3_BIT);

    Timer_start(sineTimer);

Do I need to do the PWM_open each time in the Hwi to get the handler? That would add delay to the interrupt...

Or is there some other way to make PWM_setDuty in the Hwi thread understand the handle?

Or is my approach completely wrong?

Thanks in advance for help!