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.

Hercules launchpad issue with pwmSetDuty

Other Parts Discussed in Thread: HALCOGEN

Hello everybody, excuse me if this is to silly to post here or if I am missing something trivial, I am quite newbie to Hercules launchpad.

I am taking my first steps with Hercules TMS570LS04x/03x launchpad evaluation kit, I've already gone through some of the basic examples provided in the HalCoGen examples folder. Now I want to control 2 hobby servos modifiying one of their duty cycles with a button, while reading 3 adc channels and send these values to a terminal.

In HalCoGen I configured the GIO, SCI, ADC and HET drivers, set pwm signals pwm1 and pwm2 to 20ms of period and 7.5% duty cycle in order to command the servos to middle position, selected adc channels 0, 1 and 9 of the ADC1 Group1 and compiled in HalCoGen.

In code composer I basically took the adc example code and added the button and pwm duty cycle. I have no problems with the adc conversion and displaying data and the pwm signals are ok with the initial HalCoGen setting but I can't modify the pwm duty cycle with pwmSetDuty function, moreover, after some attempts of changing duty cycle by hitting the GIOA7 button on the launch pad, the data from the adc no longer display.

This is the code I tried:

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "esm.h"
#include "adc.h"
#include "sci.h"
#include "gio.h"
#include "het.h"

#define  TSIZE2 10
uint8  TEXT2[TSIZE2]= {'\r','\n','V','A','L','U','E','=','0','x'};

adcData_t adc_data[3];
void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length);
void sciDisplayData(sciBASE_t *sci, uint8 *text,uint32 length);
void wait(uint32 time);
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */
    uint32 ch_count=0;
    uint32 value=0;
    uint32 pwm_duty=7.5;
    /* initialize gio     */
    gioInit();
    //gioSetDirection(gioPORTB, 1); No se esta usando

    /* initialize sci/sci-lin  : even parity , 2 stop bits */
    sciInit();

    /* initialize ADC  */
    /* Group1 -> Channel 0 and 1                        */
    /* HW trigger trigger source as GIOB  Pin 0         */
    adcInit();

    /* start adc conversion */

    hetInit();


    for(; ;) /* ... continue forever */
    {
        /* trigger using gio port b, pin 0  */
    	//gioSetBit(gioPORTB, 0, 1);

    	adcStartConversion(adcREG1,adcGROUP1);

        /* ... wait and read the conversion count */
        while((adcIsConversionComplete(adcREG1,adcGROUP1))==0);
        ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]);

        ch_count = ch_count;
        /* conversion results :                                       */
        /* adc_data[0] -> should have conversions for Group1 channel1 */
        /* adc_data[1] -> should have conversions for Group1 channel2 */

        value = adc_data[0].value;

        //gioSetBit(gioPORTB, 0, 0);

        sciDisplayText(scilinREG,&TEXT2[0],TSIZE2);   /* send text 2 */
        sciDisplayData(scilinREG,(uint8*)&value,4); /* send data 2 */

        value = adc_data[1].value;

        sciDisplayText(scilinREG,&TEXT2[0],TSIZE2);   /* send text 2 */
        sciDisplayData(scilinREG,(uint8*)&value,4); /* send data 2 */

        value = adc_data[2].value;

        sciDisplayText(scilinREG,&TEXT2[0],TSIZE2);   /* send text 2 */
        sciDisplayData(scilinREG,(uint8*)&value,4); /* send data 2 */


        if((gioGetBit(gioPORTA, 7)))
                {
                	pwm_duty=pwm_duty+0.1;
                	if (pwm_duty==9)
                	{	pwm_duty=1;}

                	pwmSetDuty(hetRAM1, pwm1, pwm_duty);
                }

        wait(0xFFFFF);
        }
    }
/* USER CODE END */

/* USER CODE BEGIN (4) */
void sciDisplayData(sciBASE_t *sci, uint8 *text,uint32 length)
{
    uint8 txt = 0;
    uint8 txt1 = 0;

#if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
text = text + (length -1);
#endif

    while(length--)
    {
#if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
        txt = *text--;
#else
        txt = *text++;
#endif

        txt1 = txt;

        txt  &= ~(0xF0);
        txt1 &= ~(0x0F);
        txt1  =txt1>>4;

        if(txt<=0x9)
        {
            txt +=0x30;
        }
        else if(txt > 0x9 && txt < 0xF)
        {
            txt +=0x37;
        }
        else
        {
            txt = 0x30;
        }

        if(txt1 <= 0x9)
        {
            txt1 +=0x30;
        }
        else if((txt1 > 0x9) && (txt1 <= 0xF))
        {
            txt1 +=0x37;
        }
        else
        {
            txt1 = 0x30;
        }

        while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */
        sciSendByte(scilinREG,txt1);      /* send out text   */
        while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */
        sciSendByte(scilinREG,txt);      /* send out text   */
    };
}

void sciDisplayText(sciBASE_t *sci, uint8 *text,uint32 length)
{
    while(length--)
    {
        while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */
        sciSendByte(scilinREG,*text++);      /* send out text   */
    };
}

void wait(uint32 time)
{
    while(time){time--;};
}
/* USER CODE END */

I'm stuck so any help is appreciated