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.

CCS/TMS320F28377D: 28377D:sample rate

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

If I want to set sample rate as 4kHz,what the TPBRD value should be? what  mapping relationship between the sampling frequency and the TPBRD?

  • Hi Tianyi,

    Please let us know which peripheral you are referring to, so that I can forward this query to the right person.

    Regards,
    Veena
  • Sorry, I refer to the adc, My design for adc is Differential signal。and I know that TBPRD control the sample rate;
  • Please refer to Figure 15-6 in the TRM for this device (spruhm8h) to see the relationship between TBPRD and frequency.  Presumably you are triggering the ADC from a PWM module.  Note that the sampling frequency will depend on the clock frequency you have chosen for the PWM module (typically 100 MHz on this device) and whether you are using symmetrical or up-/dn-counting for the time-base.  All this is explained in section 15.4.3 of the TRM, which you can find here:

    http://www.ti.com/lit/ug/spruhm8h/spruhm8h.pdf

    Regards,

    Richard

  • Thanks for your suggestion, and I want to know how to confirm my up or down count mode,and how to confirm the TTBCLK in "TPWM = (TBPRD + 1) x TTBCLK",and FPWM is my adc sample frequency?
    I am not really understand this chapter,especially how to confirm The parameters in the formula,could you give a example to calculate adc sample frequency?
  • I think you will find it useful to follow the recording of the 1-day workshop on this device, here:

    https://training.ti.com/c2000-f2837xd-microcontroller-1-day-workshop-series

    Section 1.6 in particular covers how to configure the PWM module.

    To determine which count mode is active, you can inspect the CTRMODE field (bits 0-1) in the TBCTL register for the relevant PWM module.  You can view this register in a CCS registers window.  The logic is:

    00: Up-count mode

    01: Down-count mode

    10: Up-down count mode

    The settings which determine clock frequency and ADC triggering are all in chapter 15 of the TRM I linked in my last post.  

    Hope this helps.

    Regards,

    Richard

  • Thank you,
    And my last question is that what relation between TBPRD and CMPA? for example ,when I set TBPRD as 4096, why the rutine "ADC_SOC_epwm" set the CMPA as 2048?
    what's more, the TTBCLK is 1/(system clock) or not?

    BEST,
    Tianyi
  • Tianyi,

    You're welcome!  The author of the example configured the PWM to generate SOCs for the ADC when there is a CMPA match and the timer timer is counting up.  This is done in the line:

        EPwm1Regs.ETSEL.bit.SOCASEL    = 4;   // Select SOC on up-count

    He chose to set the CMPA value at half the period value:

    EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts
    EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts

    I don't think there was any special reason for that choice.  Since neither TBPRD not CMPA are modified afterwards, the sample rate remains fixed.

    The program does not modify the TBCLK so the default of /1 is taken inside the PWM module.  However, there is a pre-scalar outside the module which is set by the PERCLKDIVSEL register (see Figure 15-5 in the TRM).  The default setting for that is /2, so the TB is being clocked at half the system clock - i.e. 100 MHz.

    Regards,

    Richard

  • thank you for your reply,
    And I found that TPWM = (TBPRD + 1) x TTBCLK,FPWM = 1/ (TPWM),and TTBCLK= 1/ EPWMCLK / (HSPCLKDIV X CLKDIV), so in this example TTBCLK =100MHz.
    I used this example to sample a Sinusoidal signal which frequency is 2kHz,And I set my FPWM as 5KHz(According to the above formula), Sampling points is 1024.But I got the result nearly 12-bit 0 or 12-bit 1.such as sampling point one is 0,sample point two is nearly 4095(or a little small),and point three is 0.......
    I want to know why I can not get the value between them? And I use matlab to figure out the 1024 point not get a Sinusoidal signal, after use fft to calculate the frequency, I also not get 2k frequency.
    1.Why I have not get a Sinusoidal signal after adc sample?
    2.the gpio used in adc to sample data is Analog and digita Multiplex or not(if yes, how to set as analog?)?

    thanks and best,
    Tianyi
  • Tianyi,

    I cannot answer your first question - you will have to do some investigation. I suggest you begin by verifying your sample rate: you can do this by configuring the PWM module you are using as the trigger to generate a PWM signal, and then physically measuring at the pin to be sure it really is 5 kHz. Then, measure the incoming sine wave at the ADC pin to ensure it is the expected frequency and lies within the allowable input range of the ADC (0-3V in this case). I recommend also that you test the sampling of d.c. and lower frequencies first before moving on to 2 kHz.

    The ADC input pins are dedicated analogue inputs, not GPIO.

    Regards,

    Richard
  • Thank you for your reply,

    and I will up load the program, can you help me to check the sample rate is 5254 or not? All I changed  is the value of TBPRD and CMPA.And I ensure that my sine wawe is right(3V,2kHz).

    In addition, You mean that ADC input pins are default analogue inputs and I need not to change it?

    thanks and best,

    Tianyi

    adc_soc_epwm_cpu01.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    //###########################################################################
    // FILE: adc_soc_epwm_cpu01.c
    // TITLE: ADC triggering via epwm for F2837xS.
    //
    //! \addtogroup cpu01_example_list
    //! <h1> ADC ePWM Triggering (adc_soc_epwm)</h1>
    //!
    //! This example sets up the ePWM to periodically trigger the ADC.
    //!
    //! After the program runs, the memory will contain:\n
    //! - \b AdcaResults \b: A sequence of analog-to-digital conversion samples from
    //! pin A0. The time between samples is determined based on the period
    //! of the ePWM timer.
    //
    //###########################################################################
    // $TI Release: F2837xS Support Library v190 $
    // $Release Date: Mon Feb 1 16:59:09 CST 2016 $
    // $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
    // http://www.ti.com/ ALL RIGHTS RESERVED $
    //###########################################################################
    #include "F28x_Project.h" // Device Headerfile and Examples Include File
    void ConfigureADC(void);
    void ConfigureEPWM(void);
    void SetupADCEpwm(Uint16 channel);
    interrupt void adca1_isr(void);
    //buffer for storing conversion results
    #define RESULTS_BUFFER_SIZE 512
    int16 AdcaResults[RESULTS_BUFFER_SIZE];
    Uint16 resultsIndex;
    volatile Uint16 bufferFull;
    void main(void)
    {
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xS_SysCtrl.c file.
    InitSysCtrl();
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xS_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    InitGpio(); // Skipped for this 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 F2837xS_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 F2837xS_DefaultIsr.c.
    // This function is found in F2837xS_PieVect.c.
    InitPieVectTable();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Tianyi,

    I think your SOC rate is half what you are aiming for: you are actually sampling a 2 kHz sine wave at 2.627 kHz.  

    The TBCLK is 100 MHz, and you have set the TBPRD to 0x94B1 = 38,065, which is twice what it should be.  TBPRD is what determines the frequency, not CMPA. You need to change TBPRD to 0x4A58 = 19,032 and set CMPA to a value smaller than that, say 0x252C = 9,516.  Then I think it will work.

    EPwm1Regs.CMPA.bit.CMPA = 0x252C;
    EPwm1Regs.TBPRD = 0x4A58;

    You cannot change the function of the analogue pins.  They are not GPIOs.

    Regards,

    Richard

  • Hi Richard,

    I have set the CMPA and TBPRD as your command.

    EPwm1Regs.CMPA.bit.CMPA = 0x252C;

    EPwm1Regs.TBPRD = 0x4A58;

    And sampled both in Differential-signal and single-signal mode, The sampled data and it' correspding matlab figure and fft frequency will be upload, I doubt that my data is not correspd to 2kHz sine wave at the  5254 sample rate. Could you help me analysis whether my data is right or not and why? It seems like that the fft frequency is not 2kHz.

    best and thanks,

    Tianyi

    data1.datdata12.dat

  • Hi Tianyi,

    I agree the spectrum is not what you would expect. Did you try what I suggested in an earlier post: physically measuring the incoming signal at the ADC pin to be sure it is the expected frequency and within the ADC range? Also, did you take the PWM to an output and physically verify that is it switching at 5.254 kHz?

    I would start there, and then sample and log some different frequencies to be sure you are getting what you expect. If these things aren't correct the FFT certainly won't deliver the right results.

    Regards,

    Richard
  • Hi Richard,
    I ensure that signal in adc pin is 2kHz, and I don't know how to take the PWM to an output and physically verify that is it switching at 5.254 kHz,could you guide me to do this?
    thanks an best,
    Tianyi
  • Tianyi,

    You just need to enable the appropriate GPIO pin to have EPWM1A, like this:

    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;
    EDIS;

    Then measure the signal at that pin with a 'scope and you should see a 5.254 kHz square wave. There are examples of PWM configuration in C2000Ware. See, for example, "epwm_up_aq_cpu01" at:
    C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f2837xd\examples\cpu1\epwm_up_aq\cpu01

    Regards,

    Richard
  • Hi Tianyi,

    Just wondering if you were able to measure the PWM frequency using the technique I suggested?

    Please let me know if you are still in difficulty and if I can help further. Thanks.

    Regards,

    Richard