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.

TMS320F28335: Setting the TBPRD EPWM value by sending it serially through my python code.

Part Number: TMS320F28335


Tool/software: CCS

Dear TI members,

I have tested one sample program Example_2833xSci_Echoback.c, and that works fine. It takes 'Texas' from my Python code and DSP receives that string and sends back a new string 'Instrument'. The program works fine. So no issue with the connection Between USB to UART. 

To follow this program, I made changes and this time I am sending an integer value saying '1500' instead of 'Texas'. from Python code. Please see the Python code lines below: 

Now I want to receive this value serially in my code of EPWM as TPWM value.  It will set the TBPRD value for setting the PWM signal frequencies in the Setup_ePWM1 & Setup_ePWM2 functions. I have made changes in the code for the serial port to receive this value of 1500 by following the tested example of Example_2833xSci_Echoback.c. 

The purpose is to receive the values (from Python code though TransmitBytes) in DSP  via serial and then make it equal to TPWM(TBPRD) for setting the ePWMs frequencies but it is not working. Please check the code lines for serially receiving values. 

Code:

Please suggest to resolve this issue:

Regards

Arsalan

  • Hi Arsalan,

    Can you please elaborate on the issue? What is the nature of it- are you having trouble receiving the data properly? Or storing it? Or is the issue seen with the EPWM signal output?

    Are you watching the SCI registers in CCS during this to see if the data is being received into the RX buffer correctly? 

    Best Regards,

    Allison

  • Hi Allison,

    Thanks for your reply.

    The purpose is to receive the values (from Python code though TransmitBytes) in DSP  via serial and then make it equal to TPWM(TBPRD) for setting the ePWMs frequencies but it is not working

    The very first error I have is in the Problem window. First, I need to fix this error, then I can check or investigate the Registers (SCIA registers) and realize whether I can receive data or not. 

    Please see the picture of the Error window. 

    Code: 

    Please suggest accordingly

    Kind Regards

    Arsalan

  • Hi Allison, 

    Latest Updates:

    In Python: (send Data int value= 1500, See result/compile window. Here the data is sent in hexadecimal  '\x05\xdc' . You can see/verify in the picture below).

    In CCS window: 

    (The building error has been resolved. But still the data integer = 1500 is not receiving in TBPRD of ePWM1 register and no updates in SCIA register too ) 

    ePWM1 register:

    SCIA register:

    Please suggest accordingly:

    Thanks

    Kind Regards

    Arsalan

  • Hi Arsalan,

    Allison is currently out of office; please expect a delayed response. I apologize for any inconvenience.

    Best Regards,

    Delaney

  • Hi Delaney,

    Thanks for your reply. I will wait for the response of Allison or other team members to resolve the above issues.

    Thanks

    Best Regards

    Arsalan

  • Hi Arsalan,

    Glad to hear the build error is resolved. So to clarify, the sole issue is that the C2000 device is not receiving the "1500" data, correct? Are you still seeing correct behavior of all other peripherals?

    Are you seeing any SCI activity at all? i.e. if you set a break point in your SCI ISR, is it getting hit and you are just receiving incorrect data? Or are you not having any successful SCI connection and the ISR is not getting triggered?

    Best Regards,

    Allison

  • Hi Allison and TI members,

    So to clarify, the sole issue is that the C2000 device is not receiving the "1500" data, correct?

    Yes.

    Are you still seeing correct behavior of all other peripherals?

    There are no issues with the peripherals connection. because I have tested the sample program Example_2833xSci_Echoback.c and it works well. Like Sending 'Texas' as string  from python and the DSP receives and compare and then replied back with 'Instruments' . See the results in Python below.

    No Issue with Peripherals by verifying this above code and result window. of Python. "Texas' is sent, and 'Instruments' is received.

    The Problem comes when I send an Integer as seen below.

    Are you seeing any SCI activity at all? i.e. if you set a break point in your SCI ISR, is it getting hit and you are just receiving incorrect data? Or are you not having any successful SCI connection and the ISR is not getting triggered?

    I can compare the values of the registers that are involved in the receiving side i.e. before sending 1500 through python code and after sending 1500 thorugh Python code.

    Here are the registers below: 

    1- SCITTL2

    before: 0x00C0 after: 0x00C2

    2- SCIRXST

    before: 0x0000 after: 0x00CA

    3- SCIRXEMU

    before: 0x0000 after: 0x00CD

    4- SCIRXBUF

    before: 0x0000 after: 0x00CD

    I am not sure whether Python is sending the data in integer or string format of '1500'.

    I have also tried by doing this in python : 

    { TransmitString = (f"{value_to_send}\n")
    SerialObj.write(TransmitString.encode()) } //for string to integer conversion.

    but I didn't receive 1500 in DSP. I always verify this value by looking into the Python syntax/result window before sending.

    If it is not an integer then how can I take this 1500 as a a string in my DSP registers so that the correct values of registers are shown and then it will convert it into 1500 integer format?

    After this, I could equate this integer 1500 in my TPWM/TBPRD values of ePWM1. At its moment TBPRD = 0. No generation of ePWM.

    (Note:  a small change I gave a try by moving above some EPWMs line codes from Line 204-206 & Line 224-230 to interrupt block under SCI_RX_isr but it also doesn't work) 

    Again: The purpose is to receive the integer values (from Python code) into my DSP via serially and then make it equal to TPWM(TBPRD) for setting the ePWM frequencies.

    Code:

    Please suggest to resolve this issue.

    Thanks

    Kind Regards

    Arsalan

  • Hi Arsalan,

    Good to hear the rest of the program is seems to be functional. It sounds like this is a small data formatting issue. To clarify, is the RX ISR getting hit when you put a breakpoint there? I can't provide much guidance from a python side, but let me review the information again today and provide another suggestion.

    Best Regards,

    Allison

  • Hi Allison, 

    To clarify, is the RX ISR getting hit when you put a breakpoint there?

    I have tried but I guess I found some issues in doing breakpoints setup. couldn't understood very well.

    Latest Updates:

    I found one error. The interrupt was not enabled.

    Now I have fixed it (by doing IER = 0x101;) due to which SCIRXST has been fixed now. (SCIRXST = 0x0002).

    2nd Change in the code: (SciaRegs.SCIFFRX.all = 0xE064;  // Rx interrupt level = 4) because 1500 is 4 words (character) letter not 5 words in the 'Texas' sample example [Example_2833xSci_Echoback.c].

    Still, I am having issues in the Block/function: interrupt void SCIA_RX_isr(void) for making the buffer = TPWM i.e. 1500.

    I am still unable to receive 1500 from Python. Even if I change 1500 with other values like 1200, 1200,1800 etc) no changes occur in the Registers of SCIRXEMU and SCIRXBUF (not highlighted). 

    Again: The purpose is to receive the integer values (from Python code)  into DSP via serially and then make it equal to TPWM(TBPRD) for setting the ePWM frequencies.

    Please check the latest updated code: after enabling interrupt & the Registers Status below:

    Latest Updated Code: after enabling Interrupts:

    Code:

    Please suggest accordingly to resolve it.

    Thanks

    Best Regards

    Arsalan

  • Hello,

    The appropriate expert for this question is currently out of office, returning on Monday 9/16. Please expect a response back by then.

    Thank you,

    Luke

  • Dear TI members,

    Thanks for your reply.

    Sorry for the inconvenience. Just to check if any suggestions in the code? Were you able to get a chance to have a look at the last problem (my last reply) to resolve it?

    Thanks

    Kind Regards

    Arsalan

  • Hi Arsalan,

    Apologies I actually just returned today. Please allow another day for me to review this information and get back to you. I appreciate your continued patience.

    Best Regards,

    Allison

  • Hi Arsalan,

    In reviewing your SCI init, can you add "ScibRegs.SCIFFRX.bit.RXFIFORESET=1;" after relenquishing SCI from reset? This will enable RX FIFO operation in the init. In your RX ISR, I would also comment out the two RXFIFORESET lines - I don't believe that is necessary here. 

    Reviewing the registers from your last post, the SCIFFRX register shows that the RXFFST is 0 (Receive FIFO is empty) and no RXFIFO Interrupts have occurred (let me know if you think otherwise). What I'd like to know is if your RX FIFO ISR is executing properly- I know you had some difficulty with setting a breakpoint in here. Can you perhaps toggle a GPIO in the ISR or some other indicator? 

    If your ISR is working fine, the FIFO RX ISR should trigger when the FIFO level is 4 or greater (given your RXFFIL is 4). Why don't you try the same code using internal loopback mode?  To test the RX FIFO, have a TX function that sends more than 4 words at once.  If it works with loopback, perhaps the issue is solely with how your PC is sending the data to the board. 

    Best Regards,

    Allison

  • Hi Allison,

    Thanks for your reply.

    In reviewing your SCI init, can you add "ScibRegs.SCIFFRX.bit.RXFIFORESET=1;" after relenquishing SCI from reset? This will enable RX FIFO operation in the init. In your RX ISR, I would also comment out the two RXFIFORESET lines - I don't believe that is necessary here. 

    Reviewing the registers from your last post, the SCIFFRX register shows that the RXFFST is 0 (Receive FIFO is empty) and no RXFIFO Interrupts have occurred (let me know if you think otherwise). What I'd like to know is if your RX FIFO ISR is executing properly- I know you had some difficulty with setting a breakpoint in here.

    I tried your suggestion in my last program code but it didn't work. I switched to a basic sample loop_Echo_back example. Please check below.

    Can you perhaps toggle a GPIO in the ISR or some other indicator?

    I couldn't understand this part of toggling. I guess I have started rechecking the Sci_Echo_loopback example. Please see below the latest updates in my loopback code which seems some improvements in my current program code, as shown in the latest updated work below.

    If your ISR is working fine, the FIFO RX ISR should trigger when the FIFO level is 4 or greater (given your RXFFIL is 4). Why don't you try the same code using internal loopback mode?  To test the RX FIFO, have a TX function that sends more than 4 words at once.  If it works with loopback, perhaps the issue is solely with how your PC is sending the data to the board. 

    Latest Updates:

    I took the sample working example of SciEcho_loopback again and kept TX and RX both as it is mentioned in the code.

    Following few changes I did in the SciEcho_loopback example:

    1- Adding EPWM1 and EPWM2 routine in the code:

    2- In my loopback example, especially in interrupt void SCIA_RX_isr(void) block, I commented out char buffer[16]; and used this above as a Global variable to investigate the buffer array values.

    3-  Instead of 'Texas', I transmit '1500'  having 4 characters through Python, and DSP will save this value (1500) into a char buffer array of interrupt void SCIA_RX_isr(void) function--- Same procedure I followed as in my sample program: Texas with 5 characters.

    4- I set the message array '2000! \n' instead of {Instruments \n\r}.  After comparing '1500', The DSP will respond back '2000! \n' instead of 'Instruments \n\r'

    Now the good thing is that I can call both char message [ ] and char buffer [16] in expression window. In this way, you are able to watch the changes in these two (buffer and message) arrays by seeing what you send and what you receive very clearly.

    Now in Python: value '1500' is transmitted and '2000! \n' is received.

    In CCS window: You can see the 'buffer' value  = 1500 & 'message' = '2000! \n'

    But here the problem is still there, EPwm1Reg.TBPRD or TPWM do not equal  to '1500' or buffer array value which I desire to become equal to generate ePWM signal. Here is conversion issue (array to single number). see in code below

    Now if we change the value from '1500' to '1600' and is then transmitted, Python will show an error or get stuck sometimes because 

    it violates the if statement if (strncmp(buffer, "1500", 4) == 0)-- Therefore you can't see '2000! \n' in run/ command window of Python.

    In the CCS window: You can see the buffer value  = '1600' & message value = '2000! \n'

    But here the problem is still there, EPwm1Reg.TBPRD or TPWM are not equal to '1500' / '1600' or buffer array value. Even it violates the if statement for comparing string.

    It seems like a formating or array to single value conversion problem by looking at all the above pictures, especially the expression window.

    Please check the updated code below:

    The updated Code is attached here:

    Please suggest to resolve the problem.

    Thanks

    Kind Regards

    Arsalan

  • Hi Arsalan,

    Apologies for the delay. I modified your code - please try the attached '.c' file. I commented where I modified the code.

    The saving of received values and attempted conversion you had were incorrect. Since you are saving the the serial values "1", "5', "0", "0" in a char array, you needed to convert these to a single integer so that it can be used properly as a PWM TBPRD parameter. I modified the program in a very rudimentary manner to execute/show this. I tested this as well and found it was able to update EPWM1 TBPRD to 1500. 

    Feel free to modify as needed -the code can be consolidated down further (I just wanted to show the necessary steps to convert the values). 

    #include "DSP2833x_Device.h"
    #include <string.h>
    #include <stdlib.h> // new addition
    
    // External Function prototypes
    extern void InitSysCtrl(void);
    extern void InitPieCtrl(void);
    extern void InitPieVectTable(void);
    
    
    // Prototype statements for functions found within this file.
    void Gpio_select(void);
    void Setup_ePWM1(void); // new addition
    void Setup_ePWM2(void); // new addition
    void SCIA_init(void);
    interrupt void SCIA_TX_isr(void);    // SCI-A Transmit Interrupt Service
    interrupt void SCIA_RX_isr(void);    // SCI-A Receive  Interrupt Service
    
    //interrupt void cpu_timer0_isr(void); // new addition
    
    // Global Variables
    char message[]={"2000! \n\r"};
    char buffer[4];
    //char buffer[];
    //int i;
    Uint32 TPWM; //1500(100K)
    //###########################################################################
    //                      main code
    //###########################################################################
    void main(void)
    {
    //    int counter=0;  // (new addition) binary counter for digital output
    
        InitSysCtrl();  // Basic Core Initialization
                        // SYSCLK=150MHz, HISPCLK=75MHz, LSPCLK=37.5MHz
        EALLOW;
        SysCtrlRegs.WDCR= 0x00AF;         // Re-enable the watchdog
        EDIS;           // 0x00E8  to disable the Watchdog , Prescaler = 1
                        // 0x00AF  to NOT disable the Watchdog, Prescaler = 64
    
        Gpio_select();  // GPIO9, GPIO11, GPIO34 and GPIO49 as output
                        // to 4 LEDs at Peripheral Explorer
    
        Setup_ePWM1();     // init  ePWM1A,B // new addition
    
        Setup_ePWM2();     // init  ePWM2A,B // new addition
    
        InitPieCtrl();      // default status of PIE; in DSP2833x_PieCtrl.c
    
        InitPieVectTable(); // init PIE vector table; in DSP2833x_PieVect.c
    
        // re-map PIE - entry for SCI-A-TX and SCI-A-RX
        EALLOW;
    //    PieVectTable.TINT0 = &cpu_timer0_isr; // new addition
        PieVectTable.SCITXINTA = &SCIA_TX_isr;
        PieVectTable.SCIRXINTA = &SCIA_RX_isr;
        EDIS;
    
    //    InitCpuTimers();    // basic setup CPU Timer0, 1 and 2 (new addition)
    
    //    ConfigCpuTimer(&CpuTimer0,150,100000); // (new addition)
    
        SCIA_init();  // Initalize SCI
    
    //    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;  // Enable CPU Timer 0 INT (new addition)
        // Enable SCI-A TX Interrupt Group9 interupt 2
        PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
        // Enable SCI-A RX Interrupt Group9 interupt 1
        PieCtrlRegs.PIEIER9.bit.INTx1 = 1;
    
    
        // Enable INT9 for SCIA-TX and SCIA-RX:
        IER = 0x100; //(original)
    //    IER = 0x101; // new addition
    
        // Enable global Interrupts and higher priority real-time debug events:
        EINT;   // Enable Global interrupt INTM
        ERTM;   // Enable Global realtime interrupt DBGM
    
        while(1)
        {
    
    //        while(CpuTimer0.InterruptCount == 0); // (new addition)
    //                   CpuTimer0.InterruptCount = 0; // (new addition)
    
    
            EALLOW;
            SysCtrlRegs.WDKEY = 0x55;           // Service watchdog #1
            SysCtrlRegs.WDKEY = 0xAA;           // Service watchdog #2
            EDIS;
    
    //        counter++; // (new addition)
    //        if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1; // (new addition)
    //             else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1; // (new addition)
    //        if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1; // (new addition)
    //             else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1; // (new addition)
    //        if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1; // (new addition)
    //            else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // (new addition)
    //        if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1; // (new addition)
    //             else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1; // (new addition)
    
    
        }
    }
    
    void Gpio_select(void)
    {
        EALLOW;
        GpioCtrlRegs.GPAMUX1.all = 0;           // GPIO15 ... GPIO0 = General Puropse I/O
        GpioCtrlRegs.GPAMUX2.all = 0;           // GPIO31 ... GPIO16 = General Purpose I/O
    
        GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1;    // SCIRXDA
        GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1;    // SCITXDA
    
        GpioCtrlRegs.GPBMUX1.all = 0;           // GPIO47 ... GPIO32 = General Purpose I/O
        GpioCtrlRegs.GPBMUX2.all = 0;           // GPIO63 ... GPIO48 = General Purpose I/O
        GpioCtrlRegs.GPCMUX1.all = 0;           // GPIO79 ... GPIO64 = General Purpose I/O
        GpioCtrlRegs.GPCMUX2.all = 0;           // GPIO87 ... GPIO80 = General Purpose I/O
    
        GpioCtrlRegs.GPADIR.all = 0;
        GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;      // peripheral explorer: LED LD1 at GPIO9
        GpioCtrlRegs.GPADIR.bit.GPIO11 = 1;     // peripheral explorer: LED LD2 at GPIO11
    
        GpioCtrlRegs.GPBDIR.all = 0;            // GPIO63-32 as inputs
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34
        GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49
    
        GpioCtrlRegs.GPCDIR.all = 0;            // GPIO87-64 as inputs
        EDIS;
    }
    
    //interrupt void cpu_timer0_isr(void)  // (new addition)
    //{                                    // (new addition)
    //    CpuTimer0.InterruptCount++; // (new addition)
    //    EALLOW;                     // (new addition)
    //    SysCtrlRegs.WDKEY = 0xAA;   // service WD #2  (new additon)
    //    EDIS;                       // (new addition)
    //    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;     // (new addition)
    //}                                               // (new addition)
    
    
    
    void SCIA_init()
    {
        SciaRegs.SCICCR.all =0x0027;    // 1 stop bit,  No loopback
                                        // ODD parity,8 char bits,
                                        // async mode, idle-line protocol
        SciaRegs.SCICTL1.all =0x0003;   // enable TX, RX, internal SCICLK,
                                        // Disable RX ERR, SLEEP, TXWAKE
    
        // SYSCLOCKOUT = 150MHz; LSPCLK = 1/4 = 37.5 MHz
        // BRR = (LSPCLK / (9600 x 8)) -1
        // BRR = 487  gives 9605 Baud
        SciaRegs.SCIHBAUD    = 487 >> 8;        // Highbyte
        SciaRegs.SCILBAUD    = 487 & 0x00FF;    // Lowbyte
    
        SciaRegs.SCICTL2.bit.TXINTENA = 1;      // enable SCI-A Tx-ISR
        SciaRegs.SCICTL2.bit.RXBKINTENA = 1;    // enable SCI_A Rx-ISR
    
        SciaRegs.SCIFFTX.all = 0xC060;  // bit 15 = 1 : relinquish from Reset
                                        // bit 14 = 1 : Enable FIFO
                                        // bit 6 = 1 :  CLR TXFFINT-Flag
                                        // bit 5 = 1 :  enable TX FIFO match
                                        // bit 4-0 :  TX-ISR, if TX FIFO is 0(empty)
        SciaRegs.SCIFFCT.all = 0x0000;  // Set FIFO transfer delay to 0
    
        SciaRegs.SCIFFRX.all = 0xE064;  // Rx interrupt level = 5
    
        SciaRegs.SCICTL1.all = 0x0023;  // Relinquish SCI from Reset
    }
    
    // SCI-A Transmit Interrupt Service
    interrupt void SCIA_TX_isr(void)
    {
        unsigned int i;
        // copy 16 character into SCI-A TX buffer
        for(i=0;i<16;i++) SciaRegs.SCITXBUF= message[i];
    
        // Acknowledge this interrupt to receive more interrupts from group 9
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
    }
    
    // SCI-A Receive Interrupt Service
    interrupt void SCIA_RX_isr(void)
    {
        int i;
    //    char buffer[16];
        for (i=0;i<4;i++) buffer[i]= SciaRegs.SCIRXBUF.all;
    
        if (strncmp(buffer, "1500", 4) == 0)
        {
            SciaRegs.SCIFFTX.bit.TXFIFOXRESET =1;  // enable TXFIFO
            SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1 ;  // clear interrupt to allow interrupt
    
    // MODIFIED SECTION
    
            //Convert chars to correct integer values
            Uint32 val1 = buffer[0] - '0';
            Uint32 val2 = buffer[1] - '0';
            Uint32 val3 = buffer[2] - '0';
            Uint32 val4 = buffer[3] - '0';
    
            //Multiply digits so we can add all
            val1 = val1 * 1000;
            val2 = val2 * 100;
            val3 = val3 * 10;
            val4 = val4 * 1; //not necessary, but added for completeness
    
            //Use sum of the values to set the PWM period
            Uint32 period = val1 + val2 + val3 + val4;
    
            TPWM = period; // (new addition)
    
    // END OF MODIFIED SECTION
    
            EPwm1Regs.TBPRD = TPWM; // (new addition) 1KHz - PWM signal //1500(100K),1250(120K),1666(90K),1154(130K),1364(110K)
            EPwm1Regs.CMPA.half.CMPA = TPWM/2; // (new addition) 50% duty cycle first
            EPwm1Regs.CMPB = TPWM/2; // (new addition)
    
            EPwm2Regs.TBPRD = TPWM; // (new addition) 1KHz - PWM signal //1500(100K),1250(120K),1666(90K),1154(130K),1364(110K)
            EPwm2Regs.CMPA.half.CMPA = TPWM/2; // (new addition) 50% duty cycle first
            EPwm2Regs.CMPB = TPWM/2; // (new addition)
            EPwm1Regs.TBCTL.bit.SYNCOSEL = 1;   // (new addition) generate a syncout if CTR = 0
            EPwm2Regs.TBCTL.bit.PHSEN = 1;      // (new addition) enable phase shift for ePWM2
            EPwm2Regs.TBCTL.bit.SYNCOSEL = 0;   // (new addition) syncin = syncout
            EPwm2Regs.TBPHS.half.TBPHS = TPWM; // (new addition) 1/3 phase sh
    
        }
    
    
        SciaRegs.SCIFFRX.bit.RXFIFORESET = 0;   // reset RX-FIFO pointer
        SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;   // enable RX-operation
        SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;    // clear RX-FIFO INT Flag
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
    }
    
    
    //===========================================================================
    // (new addition in rest of the code for ePWM1 & ePWM2)
    //===========================================================================
    
    
    void Setup_ePWM1(void)
    {
        EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // HSPCLKDIV = 2
        EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode
    
        EPwm1Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up, clear ePWM1A on CMPA down
        EPwm1Regs.AQCTLB.all = 0x0600; // set ePWM1B on CMPB up, clear ePWM1B on CMPB down
    
    //      EPwm1Regs.TBPRD = TPWM; // 1KHz - PWM signal //1500(100K),1250(120K),1666(90K),1154(130K),1364(110K)
    //      EPwm1Regs.CMPA.half.CMPA = TPWM/2; // 50% duty cycle first
    //      EPwm1Regs.CMPB = TPWM/2;
        EPwm1Regs.DBRED = 55; // 10 microseconds delay
        EPwm1Regs.DBFED = 55; // for rising and falling edge
        EPwm1Regs.DBCTL.bit.OUT_MODE = 3; // ePWM1A = RED
        EPwm1Regs.DBCTL.bit.POLSEL = 2; // S3=1 inverted signal at ePWM1B
        EPwm1Regs.DBCTL.bit.IN_MODE = 0; // ePWM1A = source for RED & FED
    
    }
    
    void Setup_ePWM2(void)
    {
        EPwm2Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
        EPwm2Regs.TBCTL.bit.HSPCLKDIV = 0; // HSPCLKDIV = 2
        EPwm2Regs.TBCTL.bit.CTRMODE = 2; // up - down mode
    
        EPwm2Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up, clear ePWM1A on CMPA down
        EPwm2Regs.AQCTLB.all = 0x0600; // set ePWM1B on CMPB up, clear ePWM1B on CMPB down
    
    //    EPwm2Regs.TBPRD = TPWM; // 1KHz - PWM signal //1500(100K),1250(120K),1666(90K),1154(130K),1364(110K)
    //                 EPwm2Regs.CMPA.half.CMPA = TPWM/2; // 50% duty cycle first
    //                 EPwm2Regs.CMPB = TPWM/2;
    //                 EPwm1Regs.TBCTL.bit.SYNCOSEL = 1;   // generate a syncout if CTR = 0
    //                 EPwm2Regs.TBCTL.bit.PHSEN = 1;      // enable phase shift for ePWM2
    //                 EPwm2Regs.TBCTL.bit.SYNCOSEL = 0;   // syncin = syncout
    //                 EPwm2Regs.TBPHS.half.TBPHS = TPWM; // 1/3 phase shift
    
        EPwm2Regs.DBRED = 55; // 10 microseconds delay
        EPwm2Regs.DBFED = 55; // for rising and falling edge
        EPwm2Regs.DBCTL.bit.OUT_MODE = 3; // ePWM1A = RED
        EPwm2Regs.DBCTL.bit.POLSEL = 2; // S3=1 inverted signal at ePWM1B
        EPwm2Regs.DBCTL.bit.IN_MODE = 0; // ePWM1A = source for RED & FED
    
    }
    
    
    //===========================================================================
    // End of SourceCode.
    //===========================================================================
    

    Best Regards,

    Allison

  • Hi Allison,

    Thanks for your help and continuous support. The code is working now.

    Thanks again

    Kind Regards

    Arsalan