Fizzel 0 Posted February 3, 2011 Report Share Posted February 3, 2011 Hello there, I'm trying to use the AN3, AN2 as reference voltage for the 10bit ADC. On AN3 i have 2.5V and on AN2 i have 2V. But i don't get any valid data. When I use VSS and VDD as Vref everything works fine... This is my code: void Ini_ADC(void) //Initialisierung des 10bit-ADC (siehe DB) { trisa.0=1; trisa.1=1; trisa.2=1; trisa.3=1; adcon2 =0x94; adcon1 =0x3b; //AN2, AN3=Vref adcon0 =0x01; //use AN0, ADC=on } void start_ADC() { adcon0 |= 0x2; //start conversion while((adcon0 & 0x02)>=1); tmp_h=adresh; tmp_l=adresl; tmp_h=tmp_h << 0x08; tmp_value_m=tmp_h | tmp_l; delay_ms(1); _EEPROMWrite(0x39,tmp_value_m); } The value of tmp_value_m is always FFFF, so where is my failure? THX for help Fizzel Quote Link to post Share on other sites
davidb 0 Posted February 3, 2011 Report Share Posted February 3, 2011 The value of tmp_value_m is always FFFF, so where is my failure? THX for help Fizzel You haven't told us which part you are using or shown your variable definitions. Also the maximum result from the ADC should only be 0x03ff. Your code for converting adresl and adresh to 16 bits is long winded and unless both tmp_h and tmp_value_m are defined as shorts then it will not work. If you use: tmp_value_m = (tmp_h <<8) | tmp_l; instead then that should work. However, the code would be more efficient if you re-define adresl as a short or alternatively use a union: unsigned short adresult @adresl; then simply copy the result: tmp_value_m = adresult; Regards davidb Quote Link to post Share on other sites
IanM 0 Posted February 3, 2011 Report Share Posted February 3, 2011 (edited) Hello there, I'm trying to use the AN3, AN2 as reference voltage for the 10bit ADC. On AN3 i have 2.5V and on AN2 i have 2V. But i don't get any valid data. When I use VSS and VDD as Vref everything works fine... This is my code: void Ini_ADC(void) //Initialisierung des 10bit-ADC (siehe DB) { trisa.0=1; trisa.1=1; trisa.2=1; trisa.3=1; adcon2 =0x94; adcon1 =0x3b; //AN2, AN3=Vref adcon0 =0x01; //use AN0, ADC=on } void start_ADC() { adcon0 |= 0x2; //start conversion while((adcon0 & 0x02)>=1); tmp_h=adresh; tmp_l=adresl; tmp_h=tmp_h << 0x08; tmp_value_m=tmp_h | tmp_l; delay_ms(1); _EEPROMWrite(0x39,tmp_value_m); } The value of tmp_value_m is always FFFF, so where is my failure? THX for help Fizzel For MOST PIC16 and PIC18 parts, the MINIMUM VREF (VREF+ - VREF-) is approx VDD_MAX/2. Check your datasheet for the minimum Vref for YOUR PIC! It will NEVER work properly with only 0.5V difference. Edited February 3, 2011 by IanM Quote Link to post Share on other sites
Fizzel 0 Posted February 4, 2011 Author Report Share Posted February 4, 2011 ok what i found in the datasheet is: ΔVREF Reference Voltage Range (VREFH – VREFL) min=1.8V @ VDD < 3.0V max=3V @ VDD ≥ 3.0V I have VDD=3.3V so in my understanding delta_Vref has to be min 3V, right? The problem is that i have a temperature sensor with a resolution 1,48mV/Kelvin, so with 3V for delta_Vref i have a resolution of nearly 2Kelvin/count, what isn't very detailed. Do I have any other solution for getting a resolution like 0.5Kelvin/count? THX for Re Fizzel Quote Link to post Share on other sites
trossin 0 Posted February 7, 2011 Report Share Posted February 7, 2011 You could always add an external Operation Amplifier to multiply your input signal by a constant. There are many cheap ones out there to choose from. The end result will be a more accurate measurement than trying to play with the LSBs of the A/D as you will have too much noise in your readings without an amplifier when trying to measure tiny voltage differences. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.