This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello Everyone!
Observing the voltage on the variable resistor with a properly calibrated multimeter gives different value, as the one detected by the AD in the controller, and it is not a constant offset, neither seems to be a DC-gain error. I've made some measurements:
Multimeter voltage [V] | ADC counter value [1] | ADC voltage [V] | Multimeter voltage - ADC voltage difference [V] |
2.9999 | 897 | 2.89072275 | 0.10917725 |
2.0002 |
574 | 1.84980464 | 0.15039536 |
1.0001 | 290 | 0.934570313 | 0.065529687 |
What can cause the difference and how could I solve it or minimize it down below 0.01? Tried it with and without the calibration functions, even tried to set it to a 12-bit ADC, neither of them helped. Thanks in advance for your reply.
I include the code, too:
/* USER CODE BEGIN (0) */ /* USER CODE END */ /* Include Files */ #include "HL_sys_common.h" /* USER CODE BEGIN (1) */ #include "HL_esm.h" #include "HL_adc.h" #include "HL_gio.h" adcData_t adc_data[1]; void wait(uint32 time); /* USER CODE END */ /* USER CODE BEGIN (2) */ /* USER CODE END */ int main(void) { /* USER CODE BEGIN (3) */ uint32 ch_count=0; uint32 id =0; uint32 value =0; float voltage = 0, valuefloat = 0; /* initialize gio */ gioInit(); gioSetDirection(gioPORTB, 1); /* initialize sci/sci-lin : even parity , 2 stop bits */ sciInit(); /* initialize ADC */ /* Group1 -> Channel 0 and 1 */ /* HW trigger trigger source as GIOB Pin 0 */ adcInit(); adcCalibration(adcREG1); adcMidPointCalibration(adcREG1); /* start adc conversion */ adcStartConversion(adcREG1,adcGROUP1); while(1) /* ... continue forever */ { /* trigger using gio port b, pin 0 */ gioSetBit(gioPORTB, 0, 1); /* ... wait and read the conversion count */ while((adcIsConversionComplete(adcREG1,adcGROUP1))==0); ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]); ch_count = ch_count; id = adc_data[0].id; value = adc_data[0].value; gioSetBit(gioPORTB, 0, 0); voltage = ((float)value / 1024) * 3.3; wait(0xFFFFF); }; /* USER CODE END */ return 0; } /* USER CODE BEGIN (4) */ void wait(uint32 time) { while(time){time--;}; } /* USER CODE END */
Thank you both, you were both right. The voltage was really different on Vin and ADrefhi, and neither of them were 3.3V sharp, and I needed to increase the sampling time to get more exact ADC values, too.
Regards,
Zsolt