Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Weird ADC Problem

$
0
0

Hello,

I am experiencing a weird issue with my ADC where every 8 or so samples, it "doubles up" on a sample, meaning that it skips the value that it should be at (assuming a sinusoid) and it instead places a point at the next value. The image below shows what I'm talking about. 

My code works the following way. I have a PWM with period of 80 clock cycles (at 80 MHz, so every 1 us) that triggers SOCA at count 0. SOC0 and SOC1 are set to trigger on the same PWM, with the RRPointer set at 15 so that SOC0 is always first. SOC0 triggers, then SOC1 does, and EOC1 is set to trigger ADCINT1, which I use to save the data into a buffer (which is where I am getting my data points). Does anybody know what might be wrong with this? I've attached 3 pieces of my code below: ADC initialization, PWM initialization, and Interrupt code. The background loop just waits for the buffer to fill up before exiting, there are no actions inside the background loop.

  --------ADC CODE-------------

EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power up band gap
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power up reference
AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power up rest of ADC
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // set timing to 13cycles as required by ADC module

for(i=0; i<10000; i++){} // wait 60000 cycles = 1ms (each iteration is 12 cycles)

AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;
AdcRegs.ADCCTL2.bit.CLKDIV4EN = 0;
AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Overlap is not allowed

AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 0;
AdcRegs.ADCINTSOCSEL1.bit.SOC0 = 0; // No ADCINT triggers SOC0. TRIGSEL field determines trigger.
AdcRegs.ADCINTSOCSEL1.bit.SOC1 = 0;
AdcRegs.SOCPRICTL.bit.RRPOINTER = 0xF;
AdcRegs.SOCPRICTL.bit.SOCPRIORITY = 0; // All SOCs handled in round-robin mode

// Configure ADC

AdcRegs.ADCSOC0CTL.bit.CHSEL = 1; //set SOC0 channel select to ADCINA1
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 9; //set SOC0 start trigger on EPWM3A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 8 ADC Clock Cycles, (8 ACQPS plus 1)

AdcRegs.ADCSOC1CTL.bit.CHSEL = 1;
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 9; //set SOC0 start trigger on EPWM3A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 8 ADC Clock Cycles, (8 ACQPS plus 1)

AdcRegs.INTSEL1N2.bit.INT1E = 1; // Enable ADCINT1
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; // EOC1 triggers ADCINT1

EDIS;

------------------PWM CODE------------------------------

EPwm3Regs.TBCTL.bit.CTRMODE = 0x3;
EPwm3Regs.TBPRD = period3; // Set timer period, PWM frequency = 1 / period
EPwm3Regs.TBPHS.all = 0; // Time-Base Phase Register
EPwm3Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // Set Immediate load
EPwm3Regs.TBCTL.bit.PHSEN = 1;
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;

// Setup shadow register load on ZERO
EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero

// Configure start of conversion event for ADC
EPwm3Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm3Regs.ETSEL.bit.SOCASEL = 1; // Select SOC when the timer is 0
EPwm3Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

----------------------INTERRUPT CODE----------------------------------

interrupt void ADCINT1_ISR(void) // PIE1.1 @ 0x000D40 ADCINT1
{
//--- Manage the ADC registers
TemporaryTime = EPwm1Regs.TBCTR;
TemporaryADC = AdcResult.ADCRESULT1 - NegOffset1; // Collect data into temporary variables

*ADC_Start_Ptr++ = TemporaryADC;
if (TemporaryADC > ADC_Max_Ref)
{
ADC_Max_Ref = TemporaryADC;
ADC_Time_Ref = TemporaryTime;
ADC_Index_Ref = AdcBufTimer;
}
AdcBufTimer++;

AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
PieCtrlRegs.PIEACK.all = 0xFFFF; // Must acknowledge the PIE group-- This controls repeat-ability
asm(" CLRC INTM, DBGM");
}

Thanks so much for your help,

Matthew


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>