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.

How to send UART data on timer based interrupt on F28027F using CCS

Hello all,

I have made a running program which takes the data from ADC channels and sends it on adc interrupt via SCIA, i am also receiving it properly on PC using my own c# front end as well as other terminal programs. The thing I intend to do now is I would like to run the adc/uart part on each timer based interrupt event, so that they don't run unnecessarily all the time. I need help to code it, i have seen the led_blink and the  F2802x CPU Timer Example, but am unable to implement the code, here's the error free code I am using so far: 

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/flash.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/pwm.h"
#include "f2802x_common/include/wdog.h"
#include "f2802x_common/include/sci.h"
#include "f2802x_common/include/timer.h"

// Prototype statements for functions for analog to digital conversion
void Adc_Config(void);
// Prototype statements for functions for sci/uart communication.
void scia_echoback_init(void);
void scia_fifo_init(void);
void scia_xmit(int a);
void scia_msg(char *msg);
char *itoa(int i, char *a, int r);

char *msg;
char buffer[4];
// Global variables used in this example:
uint16_t LoopCount;
uint16_t ConversionCount;
uint16_t Voltage1;
uint16_t Voltage2;
uint16_t ErrorCount;
uint16_t ReceivedChar;
ADC_Handle myAdc;
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
PWM_Handle myPwm1;
SCI_Handle mySci;

void main(void)
{

    CPU_Handle myCpu;
    PLL_Handle myPll;
    WDOG_Handle myWDog;

    // Initialize all the handles needed for this application    
    myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
    myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
    myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
    myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
    myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
    myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
    myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
    myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
    mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj));
    myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));

    // Perform basic system initialization    
    WDOG_disable(myWDog);
    CLK_enableAdcClock(myClk);
    (*Device_cal)();
    
    //Select the internal oscillator 1 as the clock source
    CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
    
    // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
    PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
    
    // Disable the PIE and all interrupts
    PIE_disable(myPie);
    PIE_disableAllInts(myPie);
    CPU_disableGlobalInts(myCpu);
    CPU_clearIntFlags(myCpu);
    
// If running from flash copy RAM only functions to RAM   
#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif   
    // Initalize GPIO
       GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable);
       GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Disable);
       GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync);
       GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);
       GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA);
    // Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

       // Initialize the ADC
         ADC_enableBandGap(myAdc);
         ADC_enableRefBuffers(myAdc);
         ADC_powerUp(myAdc);
         ADC_enable(myAdc);
         ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);
         // Enable ADCINT1 in PIE
         PIE_enableAdcInt(myPie, ADC_IntNumber_1);
         // Enable CPU Interrupt 1
         CPU_enableInt(myCpu, CPU_IntNumber_10);
         // Enable Global interrupt INTM
         CPU_enableGlobalInts(myCpu);
         // Enable Global realtime interrupt DBGM
         CPU_enableDebugInt(myCpu);
         // Configure ADC
         //Note: Channel ADCINA4  will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata
         ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior);               //ADCINT1 trips after AdcResults latch
         ADC_enableInt(myAdc, ADC_IntNumber_1);                                  //Enabled ADCINT1
         ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);          //Disable ADCINT1 Continuous mode
         ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC2);                 //setup EOC2 to trigger ADCINT1 to fire
         ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A4);    //set SOC0 channel select to ADCINA4
         ADC_setSocChanNumber (myAdc, ADC_SocNumber_1, ADC_SocChanNumber_A4);    //set SOC1 channel select to ADCINA4
         ADC_setSocChanNumber (myAdc, ADC_SocNumber_2, ADC_SocChanNumber_A2);    //set SOC2 channel select to ADCINA2
         ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
         ADC_setSocTrigSrc(myAdc, ADC_SocNumber_1, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
         ADC_setSocTrigSrc(myAdc, ADC_SocNumber_2, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1, then SOC2
         ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_64_cycles);   //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
         ADC_setSocSampleWindow(myAdc, ADC_SocNumber_1, ADC_SocSampleWindow_64_cycles);   //set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
         ADC_setSocSampleWindow(myAdc, ADC_SocNumber_2, ADC_SocSampleWindow_64_cycles);   //set SOC2 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
         // Enable PWM clock
         CLK_enablePwmClock(myClk, PWM_Number_1);
         CLK_enableTbClockSync(myClk);
         // Setup PWM
         PWM_enableSocAPulse(myPwm1);                                         // Enable SOC on A group
         PWM_setSocAPulseSrc(myPwm1, PWM_SocPulseSrc_CounterEqualCmpAIncr);   // Select SOC from CPMA on upcount
         PWM_setSocAPeriod(myPwm1, PWM_SocPeriod_FirstEvent);                 // Generate pulse on 1st event
         PWM_setCmpA(myPwm1, 0x0080);                                         // Set compare A value
         PWM_setPeriod(myPwm1, 0xFFFF);                                       // Set period for ePWM1
         PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);                      // count up and start


         // Register interrupt handlers in the PIE vector table
         PIE_registerPieIntHandler(myPie, PIE_GroupNumber_10, PIE_SubGroupNumber_1, (intVec_t)&adc_isr);

         // Wait for ADC interrupt


         for(;;)
         { LoopCount++;

       }




}


interrupt void adc_isr(void)
{


	scia_echoback_init();  // Initalize SCI for echoback
scia_fifo_init();      // Initialize the SCI FIFO

    //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0
    Voltage1 = ADC_readResult(myAdc, ADC_ResultNumber_1);
    Voltage2 = ADC_readResult(myAdc, ADC_ResultNumber_2);
    // Wait for inc character
                       /*   while(SCI_getRxFifoStatus(mySci) < SCI_FifoStatus_1_Word){
                          }

                          // Get character
                          ReceivedChar = SCI_getData(mySci);
*/
                          // Send Data
    //msg="\r\nTemp Value of LM35CAZ is:\t";
   // scia_msg(msg);
                          msg =  itoa( Voltage2 , buffer, 10);
                          scia_msg(msg);
msg="\r\n";
scia_msg(msg);

    // Clear ADCINT1 flag reinitialize for next SOC
    ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
    // Acknowledge interrupt to PIE
    PIE_clearInt(myPie, PIE_GroupNumber_10);

    return;
}
void scia_echoback_init()
{

    CLK_enableSciaClock(myClk);

    // 1 stop bit,  No loopback
    // No parity,8 char bits,
    // async mode, idle-line protocol
    SCI_disableParity(mySci);
    SCI_setNumStopBits(mySci, SCI_NumStopBits_One);
    SCI_setCharLength(mySci, SCI_CharLength_8_Bits);

    SCI_enableTx(mySci);
    SCI_enableRx(mySci);
    SCI_enableTxInt(mySci);
    SCI_enableRxInt(mySci);

    // SCI BRR = LSPCLK/(SCI BAUDx8) - 1
#if (CPU_FRQ_60MHZ)
    SCI_setBaudRate(mySci, SCI_BaudRate_115_2_kBaud);
#elif (CPU_FRQ_50MHZ)
    SCI_setBaudRate(mySci, (SCI_BaudRate_e)162);
#elif (CPU_FRQ_40MHZ)
    SCI_setBaudRate(mySci, (SCI_BaudRate_e)129);
#endif

    SCI_enable(mySci);

    return;
}

// Transmit a character from the SCI
void scia_xmit(int a)
{
//    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    while(SCI_getTxFifoStatus(mySci) != SCI_FifoStatus_Empty){
    }
//    SciaRegs.SCITXBUF=a;
    SCI_putDataBlocking(mySci, a);

}

void scia_msg(char * msg)
{
    int i;
    i = 0;
    while(msg[i] != '\0')
    {
        scia_xmit(msg[i]);
        i++;
    }
}

// Initalize the SCI FIFO
void scia_fifo_init()
{

    SCI_enableFifoEnh(mySci);
    SCI_resetTxFifo(mySci);
    SCI_clearTxFifoInt(mySci);
    SCI_resetChannels(mySci);
    SCI_setTxFifoIntLevel(mySci, SCI_FifoLevel_Empty);SCI_enableTxFifoInt(mySci);
    SCI_resetRxFifo(mySci);
    SCI_clearRxFifoInt(mySci);
    SCI_setRxFifoIntLevel(mySci, SCI_FifoLevel_4_Words); SCI_enableRxFifoInt(mySci);


    return;
}
static char *i2a(unsigned i, char *a, unsigned r)
{
    if (i/r > 0) a = i2a(i/r,a,r);
    *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
    return a+1;
}
char *itoa(int i, char *a, int r)
{
    if ((r < 2) || (r > 36)) r = 10;
    if (i < 0)
    {
        *a = '-';
        *i2a(-(unsigned)i,a+1,r) = 0;
    }
    else *i2a(i,a,r) = 0;
    return a;
}

Can anyone help me on how to achieve my aforesaid goals by showing me the exact example?

  • I found the way, using the demo, it was pretty easy, the code is as follows for informative purpose:

    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "f2802x_common/include/adc.h"
    #include "f2802x_common/include/clk.h"
    #include "f2802x_common/include/flash.h"
    #include "f2802x_common/include/gpio.h"
    #include "f2802x_common/include/pie.h"
    #include "f2802x_common/include/pll.h"
    #include "f2802x_common/include/pwm.h"
    #include "f2802x_common/include/wdog.h"
    #include "f2802x_common/include/sci.h"
    #include "f2802x_common/include/timer.h"
    interrupt void adc_isr(void);
    // Prototype statements for functions for analog to digital conversion
    void Adc_Config(void);
    // Prototype statements for functions for sci/uart communication.
    void scia_echoback_init(void);
    void scia_fifo_init(void);
    void scia_xmit(int a);
    void scia_msg(char *msg);
    char *itoa(int i, char *a, int r);
    // Prototype statements for functions found within this file.
    interrupt void cpu_timer0_isr(void);
    interrupt void cpu_timer1_isr(void);
    interrupt void cpu_timer2_isr(void);
    
    unsigned long timer0IntCount;
    unsigned long timer1IntCount;
    unsigned long timer2IntCount;
    char *msg;
    char buffer[4];
    // Global variables used in this example:
    uint16_t LoopCount;
    uint16_t ConversionCount;
    uint16_t ErrorCount;
    uint16_t ReceivedChar;
    ADC_Handle myAdc;
    CLK_Handle myClk;
    FLASH_Handle myFlash;
    GPIO_Handle myGpio;
    PIE_Handle myPie;
    PWM_Handle myPwm1;
    SCI_Handle mySci;
    TIMER_Handle myTimer0, myTimer1, myTimer2;
    
    
    void main(void)
    {
    
        CPU_Handle myCpu;
        PLL_Handle myPll;
        WDOG_Handle myWDog;
    
        // Initialize all the handles needed for this application    
        myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
        myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
        myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
        myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
        myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
        myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
        myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
        myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
        mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj));
        myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
        myTimer0 = TIMER_init((void *)TIMER0_BASE_ADDR, sizeof(TIMER_Obj));
           myTimer1 = TIMER_init((void *)TIMER1_BASE_ADDR, sizeof(TIMER_Obj));
           myTimer2 = TIMER_init((void *)TIMER2_BASE_ADDR, sizeof(TIMER_Obj));
           timer0IntCount = 0;
           timer1IntCount = 0;
           timer2IntCount = 0;
        // Perform basic system initialization    
        WDOG_disable(myWDog);
        CLK_enableAdcClock(myClk);
        (*Device_cal)();
        
        //Select the internal oscillator 1 as the clock source
        CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
        
        // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
        PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
        
        // Disable the PIE and all interrupts
        PIE_disable(myPie);
        PIE_disableAllInts(myPie);
        CPU_disableGlobalInts(myCpu);
        CPU_clearIntFlags(myCpu);
        
    // If running from flash copy RAM only functions to RAM   
    #ifdef _FLASH
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif   
        // Initalize GPIO
           GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable);
           GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Disable);
           GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync);
           GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);
           GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA);
        // Setup a debug vector table and enable the PIE
        PIE_setDebugIntVectorTable(myPie);
        PIE_enable(myPie);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_7, (intVec_t)&cpu_timer0_isr);
           PIE_registerSystemIntHandler(myPie, PIE_SystemInterrupts_TINT1, (intVec_t)&cpu_timer1_isr);
           PIE_registerSystemIntHandler(myPie, PIE_SystemInterrupts_TINT2, (intVec_t)&cpu_timer2_isr);
        GPIO_setMode(myGpio, GPIO_Number_34, GPIO_0_Mode_GeneralPurpose);
        GPIO_setDirection(myGpio, GPIO_Number_34, GPIO_Direction_Output);
        GPIO_setHigh(myGpio, GPIO_Number_34);
        TIMER_stop(myTimer0);
          TIMER_stop(myTimer1);
          TIMER_stop(myTimer2);
    #if (CPU_FRQ_60MHZ)
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 50MHz CPU Freq, 1 second Period (in uSeconds)
    
    //    ConfigCpuTimer(&CpuTimer0, 50, 1000000);
        TIMER_setPeriod(myTimer0, 60 * 1000000);
    //    ConfigCpuTimer(&CpuTimer1, 50, 1000000);
        TIMER_setPeriod(myTimer1, 60 * 1000000);
    //    ConfigCpuTimer(&CpuTimer2, 50, 1000000);
        TIMER_setPeriod(myTimer2, 60 * 1000000);
    #endif
        TIMER_setPreScaler(myTimer0, 0);
            TIMER_reload(myTimer0);
            TIMER_setEmulationMode(myTimer0, TIMER_EmulationMode_StopAfterNextDecrement);
            TIMER_enableInt(myTimer0);
    
            TIMER_setPreScaler(myTimer1, 0);
            TIMER_reload(myTimer1);
            TIMER_setEmulationMode(myTimer1, TIMER_EmulationMode_StopAfterNextDecrement);
            TIMER_enableInt(myTimer1);
    
            TIMER_setPreScaler(myTimer2, 0);
            TIMER_reload(myTimer2);
            TIMER_setEmulationMode(myTimer2, TIMER_EmulationMode_StopAfterNextDecrement);
            TIMER_enableInt(myTimer2);
    
        // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
        // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in F2802x_CpuTimers.h), the
        // below settings must also be updated.
    
        //   CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
            TIMER_start(myTimer0);
        //   CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
            TIMER_start(myTimer1);
        //   CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
            TIMER_start(myTimer2);
            // Initialize the ADC
             ADC_enableBandGap(myAdc);
             ADC_enableRefBuffers(myAdc);
             ADC_powerUp(myAdc);
             ADC_enable(myAdc);
             ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);
             // Enable ADCINT1 in PIE
             PIE_enableAdcInt(myPie, ADC_IntNumber_1);
             CPU_enableInt(myCpu, CPU_IntNumber_1);
            //    IER |= M_INT13;
                CPU_enableInt(myCpu, CPU_IntNumber_13);
            //    IER |= M_INT14;
                CPU_enableInt(myCpu, CPU_IntNumber_14);
    
            // Enable TINT0 in the PIE: Group 1 interrupt 7
            //   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
                PIE_enableTimer0Int(myPie);// Enable CPU Interrupt 1
             CPU_enableInt(myCpu, CPU_IntNumber_10);
             // Enable Global interrupt INTM
             CPU_enableGlobalInts(myCpu);
             // Enable Global realtime interrupt DBGM
             CPU_enableDebugInt(myCpu);
             // Configure ADC
             //Note: Channel ADCINA4  will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata
             ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior);               //ADCINT1 trips after AdcResults latch
             ADC_enableInt(myAdc, ADC_IntNumber_1);                                  //Enabled ADCINT1
             ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);          //Disable ADCINT1 Continuous mode
             ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC2);                 //setup EOC2 to trigger ADCINT1 to fire
             ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A4);    //set SOC0 channel select to ADCINA4
             ADC_setSocChanNumber (myAdc, ADC_SocNumber_1, ADC_SocChanNumber_A4);    //set SOC1 channel select to ADCINA4
             ADC_setSocChanNumber (myAdc, ADC_SocNumber_2, ADC_SocChanNumber_A6);    //set SOC2 channel select to ADCINA2
    
             ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
             ADC_setSocTrigSrc(myAdc, ADC_SocNumber_1, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
             ADC_setSocTrigSrc(myAdc, ADC_SocNumber_2, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1, then SOC2
    
             ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_64_cycles);   //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
             ADC_setSocSampleWindow(myAdc, ADC_SocNumber_1, ADC_SocSampleWindow_64_cycles);   //set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
             ADC_setSocSampleWindow(myAdc, ADC_SocNumber_2, ADC_SocSampleWindow_64_cycles);   //set SOC2 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
    
             // Enable PWM clock
             CLK_enablePwmClock(myClk, PWM_Number_1);
             CLK_enableTbClockSync(myClk);
    
    
             // Wait for ADC interrupt
    
    
             for(;;)
             {
    
           }
    
    
    
    
    }
    interrupt void cpu_timer0_isr(void)
    {// Setup PWM
        PWM_enableSocAPulse(myPwm1);                                         // Enable SOC on A group
        PWM_setSocAPulseSrc(myPwm1, PWM_SocPulseSrc_CounterEqualCmpAIncr);   // Select SOC from CPMA on upcount
        PWM_setSocAPeriod(myPwm1, PWM_SocPeriod_FirstEvent);                 // Generate pulse on 1st event
        PWM_setCmpA(myPwm1, 0x0080);                                         // Set compare A value
        PWM_setPeriod(myPwm1, 0xFFFF);                                       // Set period for ePWM1
        PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);                      // count up and start
    
    
        // Register interrupt handlers in the PIE vector table
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_10, PIE_SubGroupNumber_1, (intVec_t)&adc_isr);
        timer0IntCount++;
    
        // Acknowledge this interrupt to receive more interrupts from group 1
    //   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
        PIE_clearInt(myPie, PIE_GroupNumber_1);
    }
    
    interrupt void cpu_timer1_isr(void)
    {scia_echoback_init();  // Initalize SCI for echoback
    scia_fifo_init();      // Initialize the SCI FIFO
    
                            // Send Data
    	msg=itoa( ADC_readResult(myAdc, ADC_ResultNumber_1) , buffer, 10);
    	scia_msg(msg);
    msg="\r\n";
    scia_msg(msg);
    msg =  itoa( ADC_readResult(myAdc, ADC_ResultNumber_2) , buffer, 10);
    scia_msg(msg);
    msg="\r\n";
    scia_msg(msg);
        timer1IntCount++;
        PIE_clearInt(myPie, PIE_GroupNumber_1);
    }
    
    interrupt void cpu_timer2_isr(void)
    {
        timer2IntCount++;
    }
    
    
    interrupt void adc_isr(void)
    {
    
    
    
    
        // Clear ADCINT1 flag reinitialize for next SOC
        ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
        // Acknowledge interrupt to PIE
        PIE_clearInt(myPie, PIE_GroupNumber_10);
    
        return;
    }
    void scia_echoback_init()
    {
    
        CLK_enableSciaClock(myClk);
    
        // 1 stop bit,  No loopback
        // No parity,8 char bits,
        // async mode, idle-line protocol
        SCI_disableParity(mySci);
        SCI_setNumStopBits(mySci, SCI_NumStopBits_One);
        SCI_setCharLength(mySci, SCI_CharLength_8_Bits);
    
        SCI_enableTx(mySci);
        SCI_enableRx(mySci);
        SCI_enableTxInt(mySci);
        SCI_enableRxInt(mySci);
    
        // SCI BRR = LSPCLK/(SCI BAUDx8) - 1
    #if (CPU_FRQ_60MHZ)
        SCI_setBaudRate(mySci, SCI_BaudRate_115_2_kBaud);
    #elif (CPU_FRQ_50MHZ)
        SCI_setBaudRate(mySci, (SCI_BaudRate_e)162);
    #elif (CPU_FRQ_40MHZ)
        SCI_setBaudRate(mySci, (SCI_BaudRate_e)129);
    #endif
    
        SCI_enable(mySci);
    
        return;
    }
    
    // Transmit a character from the SCI
    void scia_xmit(int a)
    {
    //    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
        while(SCI_getTxFifoStatus(mySci) != SCI_FifoStatus_Empty){
        }
    //    SciaRegs.SCITXBUF=a;
        SCI_putDataBlocking(mySci, a);
    
    }
    
    void scia_msg(char * msg)
    {
        int i;
        i = 0;
        while(msg[i] != '\0')
        {
            scia_xmit(msg[i]);
            i++;
        }
    }
    
    // Initalize the SCI FIFO
    void scia_fifo_init()
    {
    
        SCI_enableFifoEnh(mySci);
        SCI_resetTxFifo(mySci);
        SCI_clearTxFifoInt(mySci);
        SCI_resetChannels(mySci);
        SCI_setTxFifoIntLevel(mySci, SCI_FifoLevel_Empty);SCI_enableTxFifoInt(mySci);
        SCI_resetRxFifo(mySci);
        SCI_clearRxFifoInt(mySci);
        SCI_setRxFifoIntLevel(mySci, SCI_FifoLevel_4_Words); SCI_enableRxFifoInt(mySci);
    
    
        return;
    }
    static char *i2a(unsigned i, char *a, unsigned r)
    {
        if (i/r > 0) a = i2a(i/r,a,r);
        *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
        return a+1;
    }
    char *itoa(int i, char *a, int r)
    {
        if ((r < 2) || (r > 36)) r = 10;
        if (i < 0)
        {
            *a = '-';
            *i2a(-(unsigned)i,a+1,r) = 0;
        }
        else *i2a(i,a,r) = 0;
        return a;
    }
    

  • Hi Debasish Banerjee1,

     

    I am also working with similar things. My UI I have created using C#. In which I am sending 12byte of data and a termination character. based on that I am generating a PWM Pulse and pulse has given input to the ADC and the result i m sending to PC via UART again.. when i send information from PC Non-Periodically some time my controller receives wrongly..

    Do you have faced similar kind of scenarios??

    Thanks & Regards,

    Umesh T