Other Parts Discussed in Thread: C2000WARE
Hi,
I have set up SOC2 on my microcontroller to trigger on the ePWM1 SOCA output signal.
There is a varying voltage on my input pin (A2), but despite the ISR being entered frequently (checked with a counter variable) the value of the ADC result register doesn't change. It just stays fixed at 2045-2046.
Here is my initialisation code and ISR code. Please help me figure out what I'm missing.
void init_adc(void) { EALLOW; CpuSysRegs.PCLKCR13.bit.ADC_A=1; EDIS; ADC_setVREF(ADCA_BASE, ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V); EALLOW; AdcaRegs.ADCCTL1.bit.ADCPWDNZ=1; // Power on the ADC AdcaRegs.ADCCTL2.bit.PRESCALE = 2; // ADCCLK=50MHz for SYSCLK=100MHz //SOC2: triggered by EPWM1-SOCA, 270ns acquisition window, sampling on channel 2 AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 0x5; AdcaRegs.ADCSOC2CTL.bit.ACQPS = 26; AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; AdcaRegs.ADCCTL1.bit.INTPULSEPOS=1; // Interrupt pulse generation occurs at the end of conversion, 1 cycle before result latching on to the result reg AdcaRegs.ADCINTSEL1N2.bit.INT2SEL=2; // Set EOC2 as interrupt trigger for ADCINT2 AdcaRegs.ADCINTSEL1N2.bit.INT2CONT=0; AdcaRegs.ADCINTSEL1N2.bit.INT2E=1; EDIS; DEVICE_DELAY_US(5000); } __interrupt void ADC2_ISR(void) { adcval_raw = AdcaResultRegs.ADCRESULT2; adcval = 3.3*(((float)adcval_raw)/4096); soaCurrent = ((1.65-adcval)/(20*0.004)); EPwm1Regs.ETCLR.bit.SOCA=1; AdcaRegs.ADCINTFLGCLR.bit.ADCINT2=1; PieCtrlRegs.PIEACK.bit.ACK10=1; }
Thanks in advance.
Regards,
Vishnu