Other Parts Discussed in Thread: CONTROLSUITE
Hi,
I am using the F28335 experimenters kit to sample a high-frequency signal. The highest frequency component of the signal is 5Mhz so I need to sample with at least 10MSPS. I have writted a short program based on the example adc_seqmodetest included in controlSUITE.
I want to:
1) Sample 1000 ADC values on A0 with 12.5MSPS and store the values in an array
2) Send the array to my PC via SCI
3) repeat
For test purposes I am sampling the serial TX of an arduino that sends '10101010' with 115200 baud. The pulse width is about 10us and with 12.5MSPS there should be approximately 100 samples/pulse. However, I only get 50 samples/pulse (see image below), suggesting that my sample rate is 5MSPS.
Someone in the forum mentioned that I need to write the sampling loop in assembler to get the necessary performance, but it feels like it should be possible to get 12.5MSPS without assembler programming. Does anyone know how to achieve 12.5MSPS?
Here is my code:
//###########################################################################
//
// Original source by: S.S.
//
// $TI Release: 2833x/2823x Header Files and Peripheral Examples V133 $
// $Release Date: June 8, 2012 $
//###########################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x1 // ADC module clock = HSPCLK/2*ADC_CKPS = 25.0MHz/(1*2) = 12.5MHz
#define ADC_SHCLK 0x0 // S/H width in ADC module periods = 0 ADC clocks?
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 2048 // Sample buffer size
// Prototype statements for SCI functions
void scia_echoback_init(void);
void scia_fifo_init(void);
void scia_xmit(int a);
void scia_msg(char *msg);
// Ruis functions
void printNum(Uint16 num);
void pause(int time);
//char* int2str(Uint16 num);
// Global variable for this example
Uint16 SampleTable[BUF_SIZE];
int printTable[4];
main()
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Specific clock setting for this example:
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
// Step 2. Initialize GPIO:
// For this example, only init the pins for the SCI-A port.
// This function is found in the DSP2833x_Sci.c file.
InitSciaGpio();
// 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 DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Output on GPIO34
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // output
EDIS;
// For this example, init the ADC
InitAdc();
// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
// Step 5. User specific code, enable interrupts:
scia_fifo_init(); // Initialize the SCI FIFO
scia_echoback_init(); // Initalize SCI for echoback
// Clear SampleTable
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
// Take ADC data and log the in SampleTable array
for(;;)
{
GpioDataRegs.GPBSET.bit.GPIO34 = 1; // GPIO34 is high
//for (i=0; i<AVG; i++)
for(i = AVG;i>0;--i)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[i] =AdcRegs.ADCRESULT0;
}
//msg = "\r\n\n\nSampling complete!\0";
//scia_msg(msg);
for(i = AVG;i>0;--i)
{
SampleTable[i] = SampleTable[i]>>4;
if(i%10 == 0)
scia_msg("\r\n");
else
scia_msg(" ; ");
printNum(SampleTable[i]);
}
scia_msg("\r\n...done!\r\n");
GpioDataRegs.GPBCLEAR.all = 0x4; // GPIO34 is low
pause(100);
}
}
Thanks,
Rui
