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.

TMS320F28379D: Combining the Sci_echoback example with the adc_soc_epwm_cpu01 example

Part Number: TMS320F28379D
Other Parts Discussed in Thread: CONTROLSUITE

Hi, 

I added the Sci_Echoback main file to the  "adc_soc_epwm_cpu01"  in order to combine both in the same project. However, when I built the example I got the error shown in the attached picture. Any Idea how can I solve this error as when I double click the error didn't shows any response where is the error. the errors I got are:

error #10056: symbol "_main" redefined: first defined in "./Example_2837xDSci_Echoback.obj"; redefined in "./adc_soc_epwm_cpu01.obj"
error #10010: errors encountered during linking; "adc_soc_epwm_cpu01.out" not built

>> Compilation failure
makefile:147: recipe for target 'adc_soc_epwm_cpu01.out' failed
gmake: *** [adc_soc_epwm_cpu01.out] Error 1
gmake: Target 'all' not remade because of errors.

My main aim is that  I could use the sci communication to transmit the adc buffer result to a monitor. 

Kind Regards 

  • Hayder,

    You can only have one main() function in the project. That is, you can add to your project, but you must only have one main() function to enter after the C RTS Library finishes executing.

    I hope this helps. If this answers your question, please click the green "Verified Answer" button. Thanks.

    - Ken
  • Hi,

    I don't know how to manage this problem in separate files, So I tried to combine the sci_file within the adc_soc_epwm_cpu01 as flowing:

    //
    // Included Files
    //
    #include "F28x_Project.h"

    //
    // Function Prototypes
    //
    void ConfigureADC(void);
    void ConfigureEPWM(void);
    void SetupADCEpwm(Uint16 channel);

    void scia_echoback_init(void); // from sci example
    void scia_fifo_init(void);
    void scia_xmit(int a);
    void scia_msg(char *msg); // from sci example

    interrupt void adca1_isr(void);
    interrupt void adcb1_isr(void);
    interrupt void adcd1_isr(void);

    //
    // Defines
    //
    #define RESULTS_BUFFER_SIZE 256
    #define ADC_SAMPLE_PERIOD 1999 // 1999 = 50 kHz sampling w/ 100 MHz ePWM clock

    //
    // Globals
    //
    Uint16 AdcaResults[RESULTS_BUFFER_SIZE];
    Uint16 AdcbResults[RESULTS_BUFFER_SIZE];
    Uint16 AdcdResults[RESULTS_BUFFER_SIZE];
    Uint16 resultsIndex;
    Uint16 LoopCount; // from sci example
    volatile Uint16 bufferFull;

    void main(void)
    {
    Uint16 ReceivedChar; // from sci example
    char *msg;
    // char *msg1; // from sci example

    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xD_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xD_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    InitGpio(); // Skipped for this example

    GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1); // from sci example
    GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);
    GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
    GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC); // from sci example

    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
    DINT;

    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2837xD_PieCtrl.c file.
    //
    InitPieCtrl();

    //
    // Disable CPU interrupts and clear all CPU interrupt flags:
    //
    IER = 0x0000;
    IFR = 0x0000;

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example. This is useful for debug purposes.
    // The shell ISR routines are found in F2837xD_DefaultIsr.c.
    // This function is found in F2837xD_PieVect.c.
    //
    InitPieVectTable();

    //
    // Map ISR functions
    //
    EALLOW;
    PieVectTable.ADCA1_INT = &adca1_isr; //function for ADCA interrupt 1
    PieVectTable.ADCB1_INT = &adcb1_isr; //function for ADCA interrupt 1
    PieVectTable.ADCD1_INT = &adcd1_isr; //function for ADCA interrupt 1
    EDIS;

    //
    // Configure the ADC and power it up
    //
    ConfigureADC();

    //
    // Configure the ePWM
    //
    ConfigureEPWM();

    //
    // Setup the ADC for ePWM triggered conversions on channel 0
    //
    SetupADCEpwm(0);

    //
    // Enable global Interrupts and higher priority real-time debug events:
    //
    IER |= M_INT1; //Enable group 1 interrupts
    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM

    //
    // Initialize results buffer
    //
    for(resultsIndex = 0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++)
    {
    AdcaResults[resultsIndex] = 0;
    AdcbResults[resultsIndex] = 0;
    AdcdResults[resultsIndex] = 0;
    }
    resultsIndex = 0;
    bufferFull = 0;

    //
    // enable PIE interrupt
    //
    PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
    PieCtrlRegs.PIEIER1.bit.INTx2 = 1;
    PieCtrlRegs.PIEIER1.bit.INTx6 = 1;

    //
    // sync ePWM
    //
    EALLOW;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;

    //
    //take conversions indefinitely in loop
    //
    do
    {
    //
    //start ePWM
    //
    EPwm1Regs.ETSEL.bit.SOCAEN = 1; //enable SOCA
    EPwm1Regs.TBCTL.bit.CTRMODE = 0; //unfreeze, and enter up count mode

    //
    //wait while ePWM causes ADC conversions, which then cause interrupts,
    //which fill the results buffer, eventually setting the bufferFull
    //flag
    //
    while(!bufferFull);
    bufferFull = 0; //clear the buffer full flag

    //
    //stop ePWM
    //
    EPwm1Regs.ETSEL.bit.SOCAEN = 0; //disable SOCA
    EPwm1Regs.TBCTL.bit.CTRMODE = 3; //freeze counter

    //
    //at this point, AdcaResults[] contains a sequence of conversions
    //from the selected channel
    //

    //
    //software breakpoint, hit run again to get updated conversions
    //
    asm(" ESTOP0");
    }while(1);
    }

    //
    // ConfigureADC - Write ADC configurations and power up the ADC for both
    // ADC A and ADC B
    //
    void ConfigureADC(void)
    {
    EALLOW;

    //
    //write configurations
    //
    AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

    AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

    AdcdRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
    AdcSetMode(ADC_ADCD, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

    //
    //Set pulse positions to late
    //
    AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
    AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
    AdcdRegs.ADCCTL1.bit.INTPULSEPOS = 1;

    //
    //power up the ADC
    //
    AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
    AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
    AdcdRegs.ADCCTL1.bit.ADCPWDNZ = 1;

    //
    //delay for 1ms to allow ADC time to power up
    //
    DELAY_US(1000);

    EDIS;
    }

    //
    // ConfigureEPWM - Configure EPWM SOC and compare values
    //
    void ConfigureEPWM(void)
    {
    EALLOW;
    // Assumes ePWM clock is already enabled
    EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC on up-count
    EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
    EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts, it was 0*0800
    EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts, it was 0*1000
    EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter
    EDIS;
    }

    //
    // SetupADCEpwm - Setup ADC EPWM acquisition window
    //
    void SetupADCEpwm(Uint16 channel)
    {
    Uint16 acqps;

    //
    //determine minimum acquisition window (in SYSCLKS) based on resolution
    //
    if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
    {
    acqps = 14; //75ns
    }
    else //resolution is 16-bit
    {
    acqps = 63; //320ns
    }

    //
    //Select the channels to convert and end of conversion flag
    //
    EALLOW;
    AdcaRegs.ADCSOC0CTL.bit.CHSEL = channel; //SOC0 will convert pin A0
    AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
    AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
    AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
    AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
    EDIS;

    //determine minimum acquisition window (in SYSCLKS) based on resolution
    //
    if(ADC_RESOLUTION_12BIT == AdcbRegs.ADCCTL2.bit.RESOLUTION)
    {
    acqps = 14; //75ns
    }
    else //resolution is 16-bit
    {
    acqps = 63; //320ns
    }

    //
    //Select the channels to convert and end of conversion flag
    //
    EALLOW;
    AdcbRegs.ADCSOC0CTL.bit.CHSEL = channel; //SOC0 will convert pin A0
    AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
    AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
    AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
    AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
    EDIS;


    //determine minimum acquisition window (in SYSCLKS) based on resolution
    //
    if(ADC_RESOLUTION_12BIT == AdcdRegs.ADCCTL2.bit.RESOLUTION)
    {
    acqps = 14; //75ns
    }
    else //resolution is 16-bit
    {
    acqps = 63; //320ns
    }

    //
    //Select the channels to convert and end of conversion flag
    //
    EALLOW;
    AdcdRegs.ADCSOC0CTL.bit.CHSEL = channel; //SOC0 will convert pin A0
    AdcdRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
    AdcdRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
    AdcdRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
    AdcdRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
    AdcdRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
    EDIS;

    }

    //
    // adca1_isr - Read ADC Buffer in ISR
    //
    interrupt void adca1_isr(void)
    {
    AdcaResults[resultsIndex++] = AdcaResultRegs.ADCRESULT0;
    if(RESULTS_BUFFER_SIZE <= resultsIndex)
    {
    resultsIndex = 0;
    bufferFull = 1;
    }

    AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }


    // adcb1_isr - Read ADC Buffer in ISR
    //
    interrupt void adcb1_isr(void)
    {
    AdcbResults[resultsIndex++] = AdcbResultRegs.ADCRESULT0;
    if(RESULTS_BUFFER_SIZE <= resultsIndex)
    {
    resultsIndex = 0;
    bufferFull = 1;
    }

    AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }


    // adcd1_isr - Read ADC Buffer in ISR
    //
    interrupt void adcd1_isr(void)
    {
    AdcdResults[resultsIndex++] = AdcdResultRegs.ADCRESULT0;
    if(RESULTS_BUFFER_SIZE <= resultsIndex)
    {
    resultsIndex = 0;
    bufferFull = 1;
    }

    AdcdRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }



    //
    // Step 4. User specific code:
    //
    LoopCount = 0;

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

    msg = "\r\n\n\nHello World!\0";
    scia_msg(msg);

    /* char values[5] = {'1', '0', '2', '5', '5'}; // I added lines 182 - 191
    int z;
    for (z=0; z<5 ;z++) {
    *msg1 = values[z];
    // msg1 = "\r\nThe Value of an array index is \n\0", z, values[z];
    scia_msg(msg1);
    msg = "\r\nThe Value of an array index is \n\0";
    // }*/

    int values[5] = {'1', '2', '2', '5', '6'}; // I added lines 185 - 192
    int z;
    for (z=0; z<5 ;z++) {
    int num = values[z];
    // printf("\n num\n");
    // msg1 = "\r\nThe Value of an array index is \n\0", z, values[z];
    scia_xmit(num);
    // msg = "\r\nThe Value of an array index is \n\0";
    }




    msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";

    scia_msg(msg);

    for(;;)
    {
    msg = "\r\nEnter a character: \0";
    scia_msg(msg);

    //
    // Wait for inc character
    //
    while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state

    //
    // Get character
    //
    ReceivedChar = SciaRegs.SCIRXBUF.all;

    //
    // Echo character back
    //
    msg = " You sent: \0";
    scia_msg(msg);
    scia_xmit(ReceivedChar);

    LoopCount++;
    }
    }

    //
    // scia_echoback_init - Test 1,SCIA DLB, 8-bit word, baud rate 0x000F,
    // default, 1 STOP bit, no parity
    //
    void scia_echoback_init()
    {
    //
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
    //

    SciaRegs.SCICCR.all = 0x0007; // 1 stop bit, No loopback
    // No parity,8 char bits,
    // async mode, idle-line protocol
    SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
    // Disable RX ERR, SLEEP, TXWAKE
    SciaRegs.SCICTL2.all = 0x0003;
    SciaRegs.SCICTL2.bit.TXINTENA = 1;
    SciaRegs.SCICTL2.bit.RXBKINTENA = 1;

    //
    // SCIA at 9600 baud
    // @LSPCLK = 50 MHz (200 MHz SYSCLK) HBAUD = 0x02 and LBAUD = 0x8B.
    // @LSPCLK = 30 MHz (120 MHz SYSCLK) HBAUD = 0x01 and LBAUD = 0x86.
    //
    SciaRegs.SCIHBAUD.all = 0x0002;
    SciaRegs.SCILBAUD.all = 0x008B;

    SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
    }

    //
    // scia_xmit - Transmit a character from the SCI
    //
    void scia_xmit(int a)
    {
    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    SciaRegs.SCITXBUF.all =a;
    }

    //
    // scia_msg - Transmit message via SCIA
    //
    void scia_msg(char * msg)
    {
    int i;
    i = 0;
    while(msg[i] != '\0')
    {
    scia_xmit(msg[i]);
    i++;
    }
    }


    // scia_fifo_init - Initialize the SCI FIFO
    //
    void scia_fifo_init()
    {
    SciaRegs.SCIFFTX.all = 0xE040;
    SciaRegs.SCIFFRX.all = 0x2044;
    SciaRegs.SCIFFCT.all = 0x0;
    }


    //
    // End of file
    //


    When I built up the program, I received long list of error as given below:

    #148 declaration is incompatible with "Uint16 LoopCount" (declared at line 58) adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 400 C/C++ Problem

    #148 declaration is incompatible with "void scia_echoback_init(void)" (declared at line 36) adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 403 C/C++ Problem

    #148 declaration is incompatible with "void scia_fifo_init(void)" (declared at line 37) adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 402 C/C++ Problem

    #148 declaration is incompatible with "void scia_msg(char *)" (declared at line 39) adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 406 C/C++ Problem
    #148 declaration is incompatible with "volatile struct SCI_REGS SciaRegs" (declared at line 218 of "C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_headers\include\F2837xD_sci.h") adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 488 C/C++ Problem

    #171 expected a declaration adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 419 C/C++ Problem
    #171 expected a declaration adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 434 C/C++ Problem
    #171 expected a declaration adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 457 C/C++ Problem
    #171 expected a declaration adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 489 C/C++ Problem

    #66 expected a ";" adc_soc_epwm_cpu01.c /adc_soc_epwm_cpu01 line 488 C/C++ Problem

    gmake: *** [adc_soc_epwm_cpu01.obj] Error 1 adc_soc_epwm_cpu01 C/C++ Problem
    gmake: Target 'all' not remade because of errors. adc_soc_epwm_cpu01 C/C++ Problem


    I don't know if this is a correct way, if not can you advice me on a better way to avoid the problem of defining main twice
    regards
  • Hello Hayder,

    In the code you've shared, the code section (copy/pasted below) starting with the LoopCount initialization and ending with the implementation of void scia_echoback_init() is not contained in a function. Based on your project needs, I suggest one of the following: add this section of code to the main(), add to another existing function, or add a function for this and include a function call where appropriate.

    //
    // Step 4. User specific code:
    //
    LoopCount = 0;

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

    msg = "\r\n\n\nHello World!\0";
    scia_msg(msg);

    /* char values[5] = {'1', '0', '2', '5', '5'}; // I added lines 182 - 191
    int z;
    for (z=0; z<5 ;z++) {
    *msg1 = values[z];
    // msg1 = "\r\nThe Value of an array index is \n\0", z, values[z];
    scia_msg(msg1);
    msg = "\r\nThe Value of an array index is \n\0";
    // }*/

    int values[5] = {'1', '2', '2', '5', '6'}; // I added lines 185 - 192
    int z;
    for (z=0; z<5 ;z++) {
    int num = values[z];
    // printf("\n num\n");
    // msg1 = "\r\nThe Value of an array index is \n\0", z, values[z];
    scia_xmit(num);
    // msg = "\r\nThe Value of an array index is \n\0";
    }




    msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";

    scia_msg(msg);

    for(;;)
    {
    msg = "\r\nEnter a character: \0";
    scia_msg(msg);

    //
    // Wait for inc character
    //
    while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state

    //
    // Get character
    //
    ReceivedChar = SciaRegs.SCIRXBUF.all;

    //
    // Echo character back
    //
    msg = " You sent: \0";
    scia_msg(msg);
    scia_xmit(ReceivedChar);

    LoopCount++;
    }
    }

    Regards,
    Elizabeth
  • Hi Elizabeth

    I managed to use the last option of your recommendation by creating another function for the Sci and then I called it in the main. I placed the call function after the ADC conversion as my intention is to transmit the ADC conversion result through the serial port. I managed to send a simple array I created within the Sci.c  as in the following code: 

    msg = "\r\n\n\nHello World!\0";
    scia_msg(msg);

    5] = {'1', '2', '2', '5', '6'};  

    int z;
    for (z=0; z<5 ;z++) {
    int num = values[z];
    scia_xmit(num);
    }

    But when I tried to do the same but using the AdcaResults as following code, it showed an error:

    int values[256] = AdcaResults; 
    int z;
    for (w=0; z<256 ;z++) {
    int num1 = values[z];
    scia_xmit(num1);

    }

    The error I received is: 

    >> Compilation failure
    subdir_rules.mk:79: recipe for target 'Sci.obj' failed
    "../Sci.c", line 212: warning #522-D: initialization with "{...}" expected for aggregate object
    "../Sci.c", line 212: error #20: identifier "AdcaResults" is undefined
    "../Sci.c", line 123: warning #179-D: variable "ReceivedChar" was declared but never referenced
    1 error detected in the compilation of "../Sci.c".
    gmake: *** [Sci.obj] Error 1
    gmake: Target 'all' not remade because of errors.

    **** Build Finished ****

    where should I define the AdcaResults as it's already defined in the main file. 

    Regards

    Hayder

  • Hi Hayder,

    This is incorrect C syntax as 'values' is declared as an array of integers so the initialization is expected to be a list of integers that is of the array size specified, or if the initialization isn't done at declaration, each item of the array can be assigned individually later. Please see a C programming reference on arrays as needed.

    Regards,
    Elizabeth
  • Hi Elizabeth, 

    I will have a look at any C programming reference. 
    I have another question and I'm wondering what is the sampling frequency in this example, is it 12kHz. see this code from the example: 

    EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC on up-count
    EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
    EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts
    EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts
    EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter

    I guess that the ADC clock in this example is 50MHz, because I converted a 2kHz input single and it resulted in 6 samples per cycle as in the figure below: 

    How can I check that the ADC clock  or the epwm clock used to trigger the ADC is 50MHz . and If I want to change the sampling frequency, do I just need to change the TBPRD above from 1000h to any value represent the frequency I need? for example if I need 25kHz, I make TBPRD = 0x800. 

    Regards 

  • Hi Hayder,

    To verify system clock, you can use XCLOCKOUT and configure the clock out source to be SYSCLK using the CLKSRCCTL3 Register's XCLKOUTSEL bits. This can be muxed to a GPIO pin and then observed on the oscilloscope.

    Yes, you can modify the TBPRD to adjust the EPWM frequency.
    For up count or down count mode: the period (and in turn frequency as the inverse) can be calculated: T(of PWM) = (1+TBPRD)*T(of TBCLK). where TBCLK = EPWMCLK/(HSPCLKDIV*CLKDIV)
    For up-down count mode: T(ofPWM) = 2*TBPRD*T(ofTBCLK)
    The Technical Reference Manual describes these registers in detail.

    Regards,
    Elizabeth