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.

LAUNCHXL-F280049C: Terminal character merging.

Part Number: LAUNCHXL-F280049C
Other Parts Discussed in Thread: C2000WARE

I'm having some trouble with my terminal. I'm trying to read a pwm data from my terminal but the printing order is all messed up and meaningless.

     int i = 0;
     for (i = 0; i<20; i++)
     {
         SCI_writeCharBlockingNonFIFO(SCIA_BASE, (uint16_t)(*(msg+i)));
         DEVICE_DELAY_US(50000);
         ltoa(compAValue,buffer);
         SCI_writeCharArray(SCIA_BASE, (uint16_t*)buffer,5);
         DEVICE_DELAY_US(50000);
         SCI_writeCharBlockingNonFIFO(SCIA_BASE, (uint16_t)(*(prc+i)));
         DEVICE_DELAY_US(50000);
     }

This code remains in a code block that changes the duty cycle of a pwm signal. But it stops the cycle change when I try to run it. (msg,prc and buffer is defined in globals. compAValue is defined in cycle change main.) I'm modifying examples to learn better but I can't seem to resolve what I occured right now. I'll be waiting for your answers. Thank you ^^

  • UPDATE:

    I can see the prints in order however duty cycle value is at the begginning. Like this;

    52%Duty Cycle:

                                %

    And the print code looks like this;

    int i = 0;
         for (i = 0; i<20; i++)
         {
             SCI_writeCharBlockingNonFIFO(SCIA_BASE, (uint16_t)(*(msg+i)));
             DEVICE_DELAY_US(50000);
    
         }
    ltoa(compAValue,buffer); SCI_writeCharArray(SCIA_BASE, (uint16_t*)buffer,5); DEVICE_DELAY_US(50000); SCI_writeCharBlockingNonFIFO(SCIA_BASE, (uint16_t)(*(prc))); DEVICE_DELAY_US(50000); looks like this

    Still can't read the duty cyle data correctly since it has no change on duty cycle. It's just counting up from fifty.

  • Hi,

    Could you please refer to the sci_ex2_interrupts example at  C2000Ware_X_XX_XX_XX\driverlib\f28004x\examples\sci\

    and check if you are configuring everything as per the example?

    Thanks, Katta

  • Hi Katta!

    What I'm trying to do is quite different than sci_ec2_interrupts. You can consider it as a mix of epwm_ex2_updown_aq and sci_ex2_interrupts but with little twists. I can provide you full code if you want. My current problem right now I can't read the data and change duty cycle at the same time. Data reading part is breaking the cycle change code. Here is the part I'm talking about;

    void updateCompare(epwmInformation *epwmInfo)
    {
        uint16_t compAValue;
    
        compAValue = EPWM_getCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A);
    
    
         if(epwmInfo->epwmTimerIntCount == 10U)
         {
             epwmInfo->epwmTimerIntCount = 0U;
    
             if(epwmInfo->epwmCompADirection == EPWM_CMP_UP)
             {
                 if(compAValue < (epwmInfo->epwmMaxCompA))
                 {
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, ++compAValue);
    
    
                 }
                 else
                 {
                     epwmInfo->epwmCompADirection = EPWM_CMP_DOWN;
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, --compAValue);
    
                 }
             }
             else
             {
                 if(compAValue == (epwmInfo->epwmMinCompA))
                 {
                     epwmInfo->epwmCompADirection = EPWM_CMP_UP;
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, ++compAValue);
    
                 }
                 else
                 {
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, --compAValue);
    
                 }
             }
    
         }
         else
         {
             epwmInfo->epwmTimerIntCount++;
         }
    
         SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg,15);
         DEVICE_DELAY_US(50000);
         ltoa(compAValue,buffer);
         SCI_writeCharArray(SCIA_BASE, (uint16_t*)buffer,5);
         DEVICE_DELAY_US(50000);
    }

    Can you see anything wrong? I'm still in my learning phase so I trust your experience on topic.

    Thank you for your time.

    Regards

    Anıl

  • Hi Katta,

    I'm still waiting for your assistance. Could you get back to me please?

    Regards

    Anıl

  • Hi Anil,

    I couldn't get the complete picture. I have informed the respective EPWM expert to reply.

    Meanwhile, what do you mean by "My current problem right now I can't read the data and change duty cycle at the same time. Data reading part is breaking the cycle change code. "

    Do you have a separate code for Data read and print? Just read part or print works but not both. Right?

    Did you check if it is something to do with you interrupt handling? Do EPWM and SCI share any common GPIO configurations?

    Thanks, Katta

  • Hi Katta,

    Thanks for replying. No they do not share a common GPIO. The code I posted above handling two tasks. The if part changing the duty cycle and the part after else prints the current duty cycle. When I remove the printing part duty cycle changes but when it stays there it does not. It just starts counting from fifty and goes on. Duty cycle stays the same.

    Thanks, Anıl

  • Hi Katta,

    Any word from EPWM expert?

    Regards, Anıl

  • Hi,

    When is this updateCompare API getting called in your code?

    Also what do you mean by "Still can't read the duty cyle data correctly since it has no change on duty cycle" as you are trying to print the compAValue value which is getting incremented or decremented in the updateCompare() function.

    You can share your code for better assistance.

    Thanks

    Vasudha

  • Hi Vasudha,

    I don't know if it is proper but here is all of the code;

    #include "driverlib.h"
    #include "device.h"
    #include "stdlib.h"
    #include "string.h"
    
    
    #define EPWM1_TIMER_TBPRD   2000U
    #define EPWM1_MAX_CMPA      1950U
    #define EPWM1_MIN_CMPA        50U
    
    #define EPWM_CMP_UP           1U
    #define EPWM_CMP_DOWN         0U
    
    typedef struct
    {
        uint32_t epwmModule;
        uint16_t epwmCompADirection;
        uint16_t epwmCompBDirection;
        uint16_t epwmTimerIntCount;
        uint16_t epwmMaxCompA;
        uint16_t epwmMinCompA;
    
    }
    epwmInformation;
    
    epwmInformation epwm1Info;
    
    void initEPWM1(void);
    
    __interrupt void epwm1ISR(void);
    
    void updateCompare(epwmInformation*epwminfo);
    
    char buffer[5];
    char *msg = "\r\nDuty cycle:% \0 ";
    
    
    void main(void)
    {
    
    
        Device_init();
        Device_initGPIO();
    
        GPIO_setMasterCore(28, GPIO_CORE_CPU1);
        GPIO_setPinConfig(GPIO_28_SCIRXDA);
        GPIO_setDirectionMode(28, GPIO_DIR_MODE_IN);
        GPIO_setPadConfig(28, GPIO_PIN_TYPE_STD);
        GPIO_setQualificationMode(28, GPIO_QUAL_ASYNC);
    
        GPIO_setMasterCore(29,GPIO_CORE_CPU1);
        GPIO_setPinConfig(GPIO_29_SCITXDA);
        GPIO_setDirectionMode(29,GPIO_DIR_MODE_OUT);
        GPIO_setPadConfig(29, GPIO_PIN_TYPE_STD);
        GPIO_setQualificationMode(29, GPIO_QUAL_ASYNC);
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
        SCI_performSoftwareReset(SCIA_BASE);
        SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ,600,(SCI_CONFIG_WLEN_8| SCI_CONFIG_STOP_ONE| SCI_CONFIG_PAR_NONE));
    
        SCI_resetChannels(SCIA_BASE);
        SCI_resetRxFIFO(SCIA_BASE);
        SCI_resetTxFIFO(SCIA_BASE);
        SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF| SCI_INT_RXFF);
        SCI_enableFIFO(SCIA_BASE);
        SCI_enableModule(SCIA_BASE);
        SCI_performSoftwareReset(SCIA_BASE);
    
    //#ifdef AUTOBAUD
    //    //
    //    // Perform an autobaud lock.
    //    // SCI expects an 'a' or 'A' to lock the baud rate.
    //    //
    //    SCI_lockAutobaud(SCIA_BASE);
    //#endif
    
        Interrupt_register(INT_EPWM1, &epwm1ISR );
        GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_0_EPWM1A);
        GPIO_setPadConfig(1, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_1_EPWM1B);
    
        SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
        initEPWM1();
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        Interrupt_enable(INT_EPWM1);
    
        EINT;
        ERTM;
    
    
    }
    
    __interrupt void epwm1ISR(void)
    {
        updateCompare(&epwm1Info);
        EPWM_clearEventTriggerInterruptFlag(EPWM1_BASE);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    void initEPWM1()
    {
        EPWM_setTimeBasePeriod(EPWM1_BASE, EPWM1_TIMER_TBPRD);
        EPWM_setPhaseShift(EPWM1_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);
    
        EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM1_MIN_CMPA);
    
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM1_BASE);
        EPWM_setClockPrescaler(EPWM1_BASE, EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_12 );
    
        EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
        EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
        EPWM_setActionQualifierAction(EPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    
        EPWM_setInterruptSource(EPWM1_BASE, EPWM_INT_TBCTR_ZERO);
        EPWM_enableInterrupt(EPWM1_BASE);
        EPWM_setInterruptEventCount(EPWM1_BASE, 3U);
    
        epwm1Info.epwmCompADirection = EPWM_CMP_UP;
        epwm1Info.epwmTimerIntCount = 0U;
        epwm1Info.epwmMaxCompA =  EPWM1_MAX_CMPA;
        epwm1Info.epwmMinCompA =  EPWM1_MIN_CMPA;
        epwm1Info.epwmModule = EPWM1_BASE;
    
     }
    
    
    
    void updateCompare(epwmInformation *epwmInfo)
    {
        uint16_t compAValue;
    
        compAValue = EPWM_getCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A);
    
    
         if(epwmInfo->epwmTimerIntCount == 10U)
         {
             epwmInfo->epwmTimerIntCount = 0U;
    
             if(epwmInfo->epwmCompADirection == EPWM_CMP_UP)
             {
                 if(compAValue < (epwmInfo->epwmMaxCompA))
                 {
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, ++compAValue);
    
    
                 }
                 else
                 {
                     epwmInfo->epwmCompADirection = EPWM_CMP_DOWN;
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, --compAValue);
    
                 }
             }
             else
             {
                 if(compAValue == (epwmInfo->epwmMinCompA))
                 {
                     epwmInfo->epwmCompADirection = EPWM_CMP_UP;
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, ++compAValue);
    
                 }
                 else
                 {
                     EPWM_setCounterCompareValue(epwmInfo->epwmModule, EPWM_COUNTER_COMPARE_A, --compAValue);
    
                 }
             }
    
         }
         else
         {
             epwmInfo->epwmTimerIntCount++;
         }
    
         SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg,15);
         DEVICE_DELAY_US(50000);
         ltoa(compAValue,buffer);
         SCI_writeCharArray(SCIA_BASE, (uint16_t*)buffer,5);
         DEVICE_DELAY_US(50000);
    }

    Regards.