We are developing with the DSP TMS320F28335 PGF controlCARD Release 1.0 (and USB-EMU R3 docking station) and we are having trouble reading the ADC.
We tried using the sample code from the "C2833x C/C++ Header Files and Peripheral Examples" and we are still getting unexpected values from the ADC.
We are using the Example_2833xAdcSoc.c (ADC SOC example), and we have put a 1V DC voltage on ADC A3. According to the documentation - we should see a value of 1365 (4096 * 1 / 3) in the ADCMIRROR.ADCRESULT_MIRROR0 register.... However we get a values of between 37 and 85.
Furthermore - if we change the code to use a different channel we get different values again, even though the voltage is the same.
What am I missing? Any 28x ADC experts out there...Can anyone suggest what my issue could be?
I've included my register values (after ACDRESULT_MIRROR is read) and code listing below FYI.
Thanks in Advance.
ADCTRL1 = 0x0000
ADCTRL2 = 0x0900
ADCTRL3 = 0x00E0
ADCST = 0x0001
ADCMAXCONV = 0x0000
ADCCHSELSEQ1 = 0x0003
ADCASEQSR = 0x0001
ADCREFSEL = 0x1B1D
ADCOFFTRIM = 0x0009
ADCRESULT = 0x0450
ADCRESULT_MIRROR_0 = 0x0045
main()
{
InitSysCtrl();
EALLOW;
#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
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
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
InitAdc(); // For this example, init the ADC
// Enable ADCINT in PIE
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;
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 1 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
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
// Wait for ADC interrupt
for(;;)
{
LoopCount++;
}
}
interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcMirror.ADCRESULT0;
// If 40 conversions have been logged, start over
if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;
// 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;
}