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.

TMS320F28027: How should one change the sampling rate during operation?

Part Number: TMS320F28027

Hello,

I am trying to use C2000 LaunchPadXL with TMS320F28027 to as a part of my project simultaneously sample two channels. My goal is to store say 50 samples at a given sampling rate, then change sampling rate and store another 50, and do this for say 10 cycles. Other things that I am doing and are not directly related here are to program a DDS via SPI and send data via SCI. So, it is important for me to make sure interrupts do not interfere when other things are happening.

I am using ePWM to set the sampling frequency. 

After initializing things I have a forever loop as below:

for(;;)

{

if(push button is not press) {do nothing;}

else

{

for (i=0;i<10<i++)

{

>>Something should be enabled here (ADC, General interrupt, PMW Clk?) [??????] <<main question

>>PWM period should change

while(conversation<50)

{

Loop++; // wait for interrupt and in interrupt store the values and increment conversion

}

>>something should be disabled here

}

}

}

What is not clear to me is that in each cycle, what should be enabled and after that what should be disabled. I was thinking of something like ADC_enable(myAdc) and ADC_disable(myAdc) which does not seem to work. But should I disable/enable anything else as well or clear or reset anything?

Many thanks,

Arsam

  • Arsam,

    There are many ways to approach this.  It doesn't sound like you have strict synchronization requirements so I think the simplest approach is:

    1. Initialize the ADC to sample on EPWM SOC triggers
    2. Enable ADC EOC interrupts
    3. Use an ADC ISR to count and store conversion results to an array
    4. Initialize the EPWM to generate SOC triggers on PRD
    5. Configure TBPRD shadow mode TBCTL[PRDLD]=0 so that you can change the TBPRD register to the new value whenever you need to
    6. Start/Stop ADC conversions by changing the EPWM counter mode between Up-Count and Stop-Freeze; the ADC can be left enabled

    You can reference the adc_soc example to get an idea for most of the settings.

    -Tommy

  • Thanks Tommy. I tried an alternative including disabling PIE just after sampling and enabling it just prior to sampling and changing the period before enabling. It seemed to be working at lower sampling rates and forcing the device into an unknown state at higher ones. Your solution though seems to be working fine and is more intuitive.

    Many thanks,
    Arsam
  • Arsam,

    Glad it's working for you.  Don't forget to check the device Errata Document to avoid ADC issues.

    -Tommy