Reply
Posts: 21
Registered: ‎08-31-2016
Accepted Solution

How to read 4-20mA current loop input via ADC on a c8051F850?

Hi All,

I am using the "TS_F85x-86x_ADC0_ExternalInput" sample project (F850DC_ADC0_ExternalInput.c) included with Simplicity Studio as my template to read a 4-20mA current input. The relevant snippet from the schematic is attached (J11 is the input). With a potentiometer, i read P1.3 to get a 10-bit value (0-1023) and everything works ok. With the current loop input i read P1.0 and am expecting the same set of values i.e 4mA and less maps to 0 while 20mA and above maps to 1023. But that is not what seems to be happening (the 0-1023 range seems to be shifted down). How exactly does the current loop input range map to the 0-1023 ADC range?

I would appreciate any and all suggestions.

 

Regards,

--Ram

 

Posts: 8,080
Registered: ‎08-13-2003

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

i.e 4mA and less maps to 0 

 

with U4A as a voltage follower, you will never get 0 for 4mA

erik
Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

@erikm

I am not expecting 0 for 4mA. I need to do some shifting adjustment calculations to map the 4-20mA to 0-1023 in software(i need this since i map this range to another application specific range).

I think i may have figured it out :-) The ADC is configured to map 0-3.3v (REF0CN=0x08) to 0-1023. If i read the schematic right the 4-20mA is converted to voltage across a 10ohm resistor(is this correct?) Thus the voltage range for 4-20mA is 40-200mV which is a subset of the full 0-3300mV range. Therefore 4-20mA corresponds to a subset within the 0-1023 range which can be calculated. I can even spread it across the entire range if needed (like a quantization scale).

However, can i configure the ADC to do the mapping of 0-1023 across 40-200mV range instead of the 0-3.3v?

Posts: 8,080
Registered: ‎08-13-2003

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

the chips that have 'gain' gor the ADC actually scale the reference volatge.  with 40-200mV you will, most likely end up with a bunch of noise.  a better idea would be to change the voltage follower to have some gain

erik
Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

The hardware is frozen and i cannot make any changes for this rev. Hence what ever i need to do has to be done in software utilizing the best that the C8051F850 can offer.

 

Posts: 8,080
Registered: ‎08-13-2003

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

14.2.5. Gain Setting The ADC has gain settings of 1x and 0.5x. In 1x mode, the full scale reading of the ADC is determined directly by VREF.

 

thus, to get any decent resolution (is the micro hardware fixed as well?) you need a lower vref - welcome to noise city

 

clearly you are in the - unfortunately too frequent - situation that someone did some hardware with no consulting of what the software could do.

 

 

erik
Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

There is nobody in hardware :-( It is all on me (hence a crash course in electronics). One question though, what is the relationship between the circuits on P1.0 and P1.1?

 

Posts: 8,080
Registered: ‎08-13-2003

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

no 'relationship'

 

one is fd by the 4-20, the other by the 'resistor switch'

erik
Posts: 3,021
Registered: ‎02-07-2002

Re: How to read 4-20mA current loop input via ADC on a c8051F850?


Ramanathan_R wrote:

I think i may have figured it out :-) The ADC is configured to map 0-3.3v (REF0CN=0x08) to 0-1023. If i read the schematic right the 4-20mA is converted to voltage across a 10ohm resistor(is this correct?)


No. The 4-20mA is converted to a voltage across a 120 Ohm resistor (R15). The 10 Ohm R14 does not carry any significant current. This gives 480-2400mV. So use the internal voltage reference instead of VCC and you have practically full range.

Posts: 8,080
Registered: ‎08-13-2003

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

Maarten

your math is better than mins Robot Happy 

erik
Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

@vanmierlo

No. The 4-20mA is converted to a voltage across a 120 Ohm resistor (R15). The 10 Ohm R14 does not carry any significant current. This gives 480-2400mV. So use the internal voltage reference instead of VCC and you have practically full range.

 

One final clarification please. Bear with me since i don't understand the schematic (trying to understand Op-Amp circuits now :-) From the schematic it seems if i read P1.0 then it goes over the 10ohm R14 whereas if i read P1.1 it goes over 120ohm R15. Thus i should be reading P1.1 in my code. This will translate 4-20mA to 480-2400mV.

 

From the datasheet i see that if i set the IREFLVL bit to 1 (REF0CN=0x80) then my ADC voltage range becomes 0-2400mV which is mapped to 10-bit 0-1023 range. That means i don't have to set the REFSL bits at all i.e. this defaults to the VREF which is what we set above.

 

Is my understanding correct?

Posts: 2,108
Registered: ‎10-14-2014

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

It seems like U4A is a voltage follower.

For amplifier the current flow into pin 3 of U4A should be very small, I agree with @vanmierlo that the current was converted to voltage across a 120 Ohm resistor (R15). 

I don't know how RMC4 J12 is connected (jumper?) so it is hard to know how U4B works. What signal you connected on pin 2 of RMC4 J12? My wild guess is that U4B works as a voltage follower and the output voltage is same as the voltage on pin 2 of RMC4 J12.

My views are my own and do not necessarily represent the views of Silicon Labs

 

WeiguoLu
Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

@delu

A 3-lead potentiometer is connected to J12 via a 4-pin connector. Pin2 of J12 is NOT connected to the potentiometer and thus is unused. Thus with a potentiometer, J12-Pin1 goes to GND and J12-Pin4 is 3V thus giving me 0-3v on P1.3 via J12-Pin3.

 

With the J11 4-20mA input is what i am confused since i see it connected to both P1.0 and P1.1 via two different circuits.

 

btw - From the datasheet (C8051F85x-86x.pdf page-106) it seems that i need to set REF0CN=0x98 to have the ADC use the internal voltage reference of 2.4v.

Posts: 2,108
Registered: ‎10-14-2014

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

------------------

With the J11 4-20mA input is what i am confused since i see it connected to both P1.0 and P1.1 via two different circuits.

-------------------

How?

It looks like U4B input is pin 2 on J12.

 

---------------------

From the datasheet (C8051F85x-86x.pdf page-106) it seems that i need to set REF0CN=0x98 to have the ADC use the internal voltage reference of 2.4v.

----------------------

Where you get the datasheet? If you look the datasheet here  how to configure the internal reference for ADC is explained in page 97 section 14.8.2 . you should configure REFSL (4:3 bit of REF0CN ) to 11 and IREFLVL (7 bit of REFOCN ) to 1. But the register is in page 112 of the datasheet. You could try code like

        REF0CN |= 0x98;

WeiguoLu
Posts: 3,021
Registered: ‎02-07-2002

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

The 4-20mA signal on J11 is not connected to P1.2 or P1.3. I agree that the schematic is a bit of a mess. It could be drawn much clearer.

 

Also J12 pin3 is only almost directly to P1.3, not to U4B or P1.2. Depending on the resistance of the potentiometer the 10k of R17 can have a significant effect on any measurement on P1.3. I suggest to use J12 pin2.

 

I suggest to try to redraw the U4A voltage follower in a much clearer way, if only on paper, to better understand its working. Leave out J12 and U4B. When you have more questions, show the drawing and ask away.

Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

Thanks guys.

 

I got It to work by reading P1.0. 4-20mA over 120ohms gives me 480-2400mv. I configured ADC to range between 0-2.4v (REF0CN=0x98) and adjusted the lower bound of 10-bit ADC from 0-1023 to 205-1023 in code.

 

Still don't understand the schematic but that can only be learned in time :-)

 

Posts: 21
Registered: ‎08-31-2016

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

@vanmierlo@erikm @delu

I am still having some problems and would appreciate it if you could take a look and let me know what i might be doing/understanding wrong. As i mentioned in my previous post, i configured the ADC to use the internal VREF of 2.4v and map [0-2.4v] onto [0-1023] 10-bit ADC. The current loop 4-20mA should translate to [400-2400mV] based on the above circuit which should translate to [205-1023] ADC on P1.0. At the lower end of 4mA i get around 205 ADC but on the higher end of 20mA i get only around 600 ADC. I am not clear as to why. Here is the code for the init;

void ADC0_Init (void)
{
   ADC0CN0 = 0x02;                     // ADC0 disabled, conversions triggered
                                       // on Timer2 overflows

   ADC0CF = (((SYSCLK*2)/12250000)-1)<<3; // Set SAR clock to 12.25 MHz

   ADC0CF |= 0x01;                     // 1x gain, normal tracking mode,
                                       // 10-bit mode

   ADC0AC = 0x00;                      // 12-bit mode disabled, accumulation
                                       // disabled, right-justified, repeat
                                       // count set to 1

   ADC0PWR = 0x00;                     // Low power mode disabled

   if(IsCurrentLoopInput)
   {
	   ADC0MX = 0x08;		//ADC0 positive input = ADC0.8 or P1.0 for current input
    
           //[0-2.4v] mapped to [0-1023] 10-bit ADC
	   REF0CN = 0x98;		//Use internal voltage reference of 2.4v
   }
   else
   {
     ....
   }

   EIE1 |= 0x08;                       // Enable ADC0 conversion complete
                                       // interrupt

   ADC0CN0_ADEN = 1;                           // Enable ADC0
}

 

Highlighted
Posts: 3,021
Registered: ‎02-07-2002

Re: How to read 4-20mA current loop input via ADC on a c8051F850?

I'd start by measuring the pin when it should read 2.4V to check it actually does.