Hi,
I have connected a 10K multi turn pot to FRDM-KL25Z platform, I'm using keil and tried this code to read the Pot voltage, But my readings are not stable enough, they will jump around 10% of the value, How can I achieve the 14.5 ENOB from the ADC?
Here is my main code
int analog_in; char txt_buff[20]; SystemCoreClockUpdate(); /* Get Core Clock Frequency */ uart0_init(); ADC_Init(); Calibrate_ADC(); while(1) { analog_in=0; for(int i=0;i<16;i++) { analog_in+=adc_read(0); } analog_in=analog_in/16; sprintf(txt_buff,"analog = %d\r\n",analog_in); uart0_puts(txt_buff); }
The code for ADC driver is attached,
Original Attachment has been moved to: ADC.h.txt.zip
Original Attachment has been moved to: ADC.c.txt.zip
Ignore the calibration routine?
I have had similar problems with the SAR ADC on a K20. Double check your calibration routine, if you can set a break point after it is completed and check the CALF bit manually. I had to use the COCO bit, instead of the CAL bit, on a K20 to make sure the calibration was completed. I also software average hundreds of ADC conversions before using a value. Also, the time constant of the input RC on the ADC pin is very important, make sure it is under 1nS.
Hi Ali,
The ADC on the KL25 requires a very low source resistance to attain the best results possible. I can't tell you specifically what to do to get to your requested ENOB, but I can tell you that you should make sure your source resistance is well below 5 kOhms. My recommendation would be to use a unity gain operational amplifier circuit to drive your ADC pin. Of course, even in this scenario, you will want to select an operational amplifier that has a low output resistance. In addition, you will want to make sure that the RC time constant of the operational amplifier output pin is less than 1ns. All of this information is documented in the KL25Z data sheet in chapter 6.6.1 (ADC electrical specifications) under note 4 of Table 19 16-bit ADC operating conditions.
Thanks,
Chris
I have added a unity gain op amp in front of The Pot, Using LM358, I get this results,It's better but They vary a lot too.
analog = 11639
analog = 11621
analog = 11801
analog = 11661
analog = 11669
analog = 11725
analog = 11677
analog = 11800
analog = 11577
analog = 11647
analog = 11578
analog = 11575
analog = 11423
analog = 11674
analog = 11613
analog = 11221
analog = 11517
analog = 11778
analog = 11635
analog = 11660
analog = 11674
analog = 11717
analog = 11903
analog = 11687
analog = 11817
analog = 11643
analog = 11710
analog = 11676
analog = 11703
analog = 11538
analog = 10996
analog = 11639
analog = 11702
analog = 11613
analog = 11727
analog = 11797
analog = 11083
analog = 11784
analog = 11682
This data gives me this info
Min value= 10996
Max Value = 11903
Mean Value= 11630
Max Error= 5.5%
And here is the Graph
Still I got very High errors ( it's worse than a 8bit ADC!) what is the problem?
Has anybody get stable results? I'm Still struggling getting a salable result,