Part Number: TMS320F28335
Tool/software: Code Composer Studio
Hello
I have used the example of ADC_SOC to read three A/D channels and I have used two functions "Start_Timer" and "Stop_Timer" to measure the time it takes to read these channels. It takes almost 0.005 s to do this however in the data sheet of TMS320F28335 it is stated that the conversion time of ADC is 80ns. Could you please check my code and see why it takes this long?
void main(void)
{
InitSysCtrl();
EALLOW;
#define ADC_MODCLK 0x3
EDIS;
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitCpuTimers(); // For this example, only initialize the Cpu Timers
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
StartTimer();
InitAdc(); // For this example, init the ADC
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//
LoopCount = 0;
ConversionCount = 0;
//
// Configure ADC
//
AdcRegs.ADCMAXCONV.all = 0x0003; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x2; // Setup ADCINA2 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x3; // Setup ADCINA3 as 2nd SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x4;
//
// Enable SOCA from ePWM to start SEQ1
//
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
//
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
//
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
StopTimer();
delta_time=cpuTime*6.66e-9;
void StartTimer(void)
{
// cpuTime1 = 0;
EALLOW;
CpuTimer2Regs.TCR.bit.TRB = 1; // Reset CPU timer to period value
CpuTimer2Regs.TCR.bit.TSS = 0; // Start or reset CPU timer 2
cpuTime1 = CpuTimer2Regs.TIM.all; // Get value of CPU Timer 2 before code
EDIS;
}
void StopTimer(void)
{
EALLOW;
cpuTime2 = CpuTimer2Regs.TIM.all; // Get value of CPU Timer 2 after code
cpuTime = cpuTime1 - cpuTime2; // Calculate time using cpuTimer2
CpuTimer2Regs.TCR.bit.TSS = 1; // Start or reset CPU timer 2
EDIS;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
__interrupt void
adc_isr(void)
{
Voltage1 = AdcRegs.ADCRESULT0 >>4;
Voltage2 = AdcRegs.ADCRESULT1 >>4;
Voltage3 = AdcRegs.ADCRESULT2 >>4;
current = Voltage1- Voltage2;
voltage = Voltage2- Voltage3;
//
// If 40 conversions have been logged, start over
//
//
// Reinitialize for next ADC sequence
//
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}