shifting ADC VRef- for PIC16F876A

Status
Not open for further replies.

aljamri

Member
Hi,
I am trying to use ADC to read a signal of 4 to 20 mA. With the help from two superb ETO members in This Thread. , the software part is accomplished.

I've tested the circuit both using OshonSoft IDE and on a bread board using 0 to 5 volts (0 to 20mA) signal, The Vref- is connected to Vss (0v) and Vref+ to VDD (5V) . The circuit works as expected.

When I tried to shift the Vref- from 0v into 1v using two resistors as voltage divider between Gnd and 5V. The resistors were 10k and around 7.5k. Then applied the signal, (1 to 5V) into RA0, and it woks fine too.

THE PROBLEM:
When I tried to replace the input voltage with mA signal ( 4 to 20 mA ), and by using a 250 Ohm shunt resistor, the things went wrong, as I've connected the shunt resistor between the Gnd and AN0 ( as what I did in all the previous succeeded tests ).

I'm wondering what is wrong, is it where I have to connect the signal or something else.
 
Ah yes... A problem.. the 4 - 20 ma should also be referenced to 1v.. But if you connect the shunt resistor to 1V then it will no longer be 1V.. The best I can suggest (this is what I do ) is use a 1.2V reference chip (I don't think you can get a 1V reference chip)
 
Hi Ian,
Oh my God, I've read this once in Application Note (AN546) and thanked my god that what I thought that I'm not going to need them.

Anyway, in that there is no reference to 1V, they started by 3.3V using 1N746. Is there any way to overcome this problem, as if I ordered any part, it takes almost one month to get it.
 

If you're shifting the references for the A2D, have a good read of the datasheet, there are considerable restrictions on what you can do.

However, I would suggest doing the shift in your software - doing it in the hardware means you've no test for there been no connection, which is the point of the 4-20mA range (instead of 0-20mA)
 
Last edited:
hi aljamri
How did it go wrong.?

The 1V on -Vref, should make the adc ignore voltages below 1V

The 250R is correct from adc0 and 0V., it should have a voltage of 1 thru 5V for a loop current of 4 to 20mA.

The Span of the 1023 counts should be from 1V thru 5V.

Whats the problem.?

EDIT:
I assume that you programmed the PIC pins so that they are active as +/-Vref
EDIT:
 
Last edited:
Here some thing to look at
 

Attachments

  • mA.jpg
    120 KB · Views: 179
  • Volts_like this.jpg
    113.6 KB · Views: 198
I thought the whole purpose of the 4-20mA signaling was to clear the residual .6 of a volt in op-amps and such. I total agree this should be done in software.
 
Last edited:
Hi everybody and very good morning for all of ETO members, I’m happy for two reasons.

First of all, that my thread attracts the attention of this number of ETO experts .

Secondly, that my problem has a software solution.
Before I start this thread, I remembered Eric said he would solve it in software, so I read a lot in its datasheet searching for port setting or alike ( remembering software reference in PIC comparators ) and found nothing in this regard except the attached part .

Thanks for all.
 

Attachments

  • A2D01.JPG
    80.3 KB · Views: 169


Simply subract the 4mA reading from the actual reading in the code, it's only a couple of lines - it's nothing to do with the hardware or datasheet. You could also check if the reading is less than that minimum, which would signify an error - probably no connection somewhere.
 
The 1V on -Vref, should make the adc ignore voltages below 1V
The 250R is correct from adc 0 and 0V., it should have a voltage of 1 thru 5V for a loop current of 4 to 20mA. The Span of the 1023 counts should be from 1V thru 5V. Whats the problem.?
I don't know what happen, all of the sudden, when I connected the mA source, the LCD reads 00.00 and not change .

I assume that you programmed the PIC pins so that they are active as +/-Vref
I am not sure that I understood this, Burt (be80be) offered me the attached code and I used it with minor changes. How to know which is which.

green is be80be code
rest is me

Code:
[COLOR=seagreen]//char message1[] = "ADC Value= ";
[/COLOR] char *value = "00.00 %";
 unsigned int ADC_Value;
void main() {
  ADCON0 = 0b11000000;
  ADCON1 = 0b10001111;
  TRISA  = 0xFF;              // PORTA is input
  TRISB  = 0;                 // PORTB is output
  TRISC  = 0;                 // PORTC is output
  
  [COLOR=seagreen]//Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);
[/COLOR]  Lcd_Init(&PORTB);           // Initialize LCD
 [COLOR=seagreen] //Lcd_Cmd(Lcd_CURSOR_OFF);    // Turn cursor off[/COLOR]
  do {
       adc_value = ADC_Read(0);
       PORTC = ADC_Read(0);
    [COLOR=seagreen]// value[0] = adc_value/1000 + 48; // Add 48 to get character value
[/COLOR]      value[0] = adc_value/100 + 48; // Add 48 to get character value
   
  [COLOR=seagreen]//  value[1] = (adc_value/100)%10 + 48;
[/COLOR]     value[1] = (adc_value/10)%10 + 48;
     value[2] = '.';
   [COLOR=seagreen]//value[2] = (adc_value/10)%10 + 48;
[/COLOR]      value[3] = (adc_value/1)%10 + 48;
   [COLOR=seagreen]//value[3] = adc_value%10 + 48;
[/COLOR]      value[4] = adc_value%10 + 48;
   Lcd_Out(1,5,value);
    [COLOR=seagreen] //Lcd_Out(2,5,value);
[/COLOR]       Delay_ms(2000);
  } while(1);
       }
 
Hi,

ADCON1 = 0b10001111; gives AN7 ... AN0 .... D,D,D,D, +Vref, -Vref, D, A.

So Vref pins are active and only ADC0 is analog.

What have you connect +Vref too.???
 
I've connected it to the VDD (5V), and the input as in the attached circuit.
 

Attachments

  • A2D02.JPG
    10.5 KB · Views: 181
Assuming the meter shown there is a real ammeter, then it's connected wrongly and will short out the 250 ohm.

The two resistors are also completely the wrong values, it won't give anything near a 1V reference - you need a 4K at the top, and a 1K at the bottom (or at least a 4 to 1 ratio).
 
Hi Nigel,

This is my mA source not Ammeter.

Frankly speaking, I was a bit lazy to find the proper Resistors, so what I did is connected a 10k Resistor and a variable resistor and turn it with a voltmeter until i got the 1v .
 
Hi Nigel,

This is my mA source not Ammeter.

Frankly speaking, I was a bit lazy to find the proper Resistors, so what I did is connected a 10k Resistor and a variable resistor and turn it with a voltmeter until i got the 1v .

Well assuming you're using those values, it's way off 1V.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…