Other Parts Discussed in Thread: C2000WARE
Hi there,
i am using ADC on F28004x to capture some analog values. Unfortunately, I run into trouble when doing the first read after starting up my device.
Please see the following - a bit simplified problematic code:
float32 adCapture( void ) { Uint16 buff_hi; Uint16 buff_lo; float32 ret_val; //start of conversion AdcaRegs.ADCSOCFRC1.all = 0x000CU; //set SOC flags for SOC2 and SOC3 //wait for end of conversion while(AdcaRegs.ADCINTFLG.bit.ADCINT3 == 0U) { }; // reset flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT3 = 1U; //capture vals buff_hi = AdcaResultRegs.ADCRESULT2; buff_lo = AdcaResultRegs.ADCRESULT3; //Do some calculations ret_val = (CON_AD_FAC * ((float32)buff_hi - (float32)buff_lo)); ret_val = ret_val / 4.7; return ret_val; }
When I read the ADC results from the result regs to the temporary variables buff_hi and buff_low, I run into trouble because buff_lo seems to be 0. When I set a breakpoint on the first line of my calculations, I can definitely examine this: buff_lo is 0, but ADCRESULT3 is not equal 0!
Is it possible that we got some timing problem here? Maybe that ADCRESULT3 is not loaded yet when I want to fetch the value from this register?
My colleague has experienced a similar behavior using another ADC instance on F28004x, where it seemed like the End of conversion flag is set some time before the results are loaded to ADCRESULTx.
This seems always to depend on the timing behavior of the whole code!
Do you know about such a behavior or did some other customers report this behavior, too?
Can you suggest a workaround?
Best regards,
Chris