4-20mA on a PIC 16f690

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Hi All

Firstly apologies if this has already been covered here and I have missed it.

The project I am working on is a deep well pump controller.
It uses a loop powered pressure transducer (voltage range 10 to 55V) to measure tank water level (current between 4 and 20mA proportional to water level).
Normally in industrial control to convert from 4-20mA to 1-5V you just measure the voltage a series 250 ohm resistor.
The circuit also has a serial lcd on the uart, amosfet connected to a 5v relay and a standard 6 pin icsp header all not shown here because I don't believe the problem is with them.
The power supply is an ATX PC power supply.
I have approximated the pressure transducer here as a Pot.
Problem is when I connect the Transducer the voltage on my 5v rail drops pretty much right off (approx 2V).
Do I have to isolate my analog input given that it is supplied with a higher voltage?
I cant quite work out what is happening here.
Any help would be much appreciated.
Regards Bruce

 

ericgibbs

Joined Jan 29, 2010
18,865
I have approximated the pressure transducer here as a Pot.
Problem is when I connect the Transducer the voltage on my 5v rail drops pretty much right off (approx 2V).
Do I have to isolate my analog input given that it is supplied with a higher voltage?
You have to ensure that the ADC input voltage cannot be higher than +5V,
We need more information also some circuit values.

Also is the ADC PIC pin actually configured as Analog in the program.?
E
 

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Hi

The 12V Supply, Pressure Transducer and 250 Ohm as I understand it form a series loop.

The Transducer will only 'output' between 4 and 20mA

Max of 20mA Series current through the 250 Ohm = 5V

I cant quite see where I am going wrong.

Please see my code below.

Rich (BB code):
 program BasicPumpControl
 ' Declarations section 
symbol pump = porta.2
dim counts as integer
dim level_raw as word
dim level_text as char[5]
 main:
'   Main program 
intcon.gie = 0
ansel.2 = 0
 trisa.2 =0
uart1_init(9600)
adc_init()
uart1_write_text("CS0")
uart1_write(10)
uart1_write(13)
delay_ms(100)
level_raw = 0
while true
level_raw=adc_read(7)
wordtostr(level_raw, level_text)
uart1_write_text("CL")
uart1_write(10)
uart1_write(13)
uart1_write_text("TTLevel_Raw:")
uart1_write_text(level_text)
uart1_write(10)
uart1_write(13)
pump = not pump
delay_ms(1000)
 
wend
end.
I would show you the pcb file too but it seems that I have deleted it.

The code is not yet final of course, that's why I am just toggling my pump relay and not controlling it based on a setpoint
 

ericgibbs

Joined Jan 29, 2010
18,865
hi bruce,
If I am reading your information correctly you appear to be using AN7 as ADC input but the program is Ansel.2 sets a lower pin for ADC input.??
E
 

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Hi.
I thought that the anlog inputs default to that so you set ansel where you want to use a pin for digital io. I am using ansel.2 to setup the pump output as a digital output.
Regards Bruce
 

ericgibbs

Joined Jan 29, 2010
18,865
hi,
I see that now on your program listing. [ its not a basic a am familiar with]

If R2 is 250R whats the value of R1 pot.?
 

ericgibbs

Joined Jan 29, 2010
18,865
hi M,
I have often used 4-20mA loops, so I do have a good working knowledge of this technique.

I would suggest the following tests.

Disconnect the output from the 250R resistor and your Pot thats is connected to your PIC's ADC input pin.

Using a DVM check the Range of the voltages that can be measured at the junction of the 250R and the Pot, by varying the Pot over its full range of travel. [you MUST have a fixed resistor in series with the Pot, so that junction voltage cannot exceed +5V]

You should be able to measure 0V thru +5V on the top of he 250R relative to 0V, by varying the Pot over its full rotation... tell me what you measure.

Also ensure that the 0V/Common of the PIC's supply voltage is connected to 0V/Common of the +12V driving the 4-20mA loop.

Next step, turn the Pot to give +5V on the top of the 250R, connect the junction of the 250R and Pot to the PIC's ADC input pin.
Power up the PIC/Loop and Run the program, then measure the voltage at the top of the 250R... tell me what you measure, it should still be +5V.

If you have been previously testing by adjusting the Pot,without a fixed series resistor, you may have greatly exceeded the +5V on the ADC pin, you will have forward biased the +V clamp diode within the PIC. IF the current into the clamp diode has exceeded 25mA there is a possibility than you have damaged the diode on the ADC input pin.

E
 

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Hi Eric.

The 12v for the current loop and the 5v for the pic do share a common ground.
I have only used the pot for the cct diagram here because I didn't have a suitable symbol for the transducer. Some of the actual testing has been done on the actual pressure transducer in situ.
I will pop out the pic from its socket and test the voltages at the analog input pin tomorrow.
I was starting to wonder if the diodes on the input pin might have been damaged.
Given that the max current of 20mA is being dropped over the 250 ohm resistor why would the voltage at the input ever exceed 5v?
 

ericgibbs

Joined Jan 29, 2010
18,865
Given that the max current of 20mA is being dropped over the 250 ohm resistor why would the voltage at the input ever exceed 5v?
hi,
I thought you had been testing using a Pot connected to the 250R, if you had, it would be possible to adjust the Pot to give as much as 12V if the Pot had been set to zero Ohms.

As you say providing the loop current does not exceed 20mA thru the 250R, you should never exceed +5V on the PIC pin.

To check to see if the diode is blown on AN7, you could change the program to read another ADC pin.?

What is that version of Basic you have used for the program.?

E.
 

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Hi. Version of Basic is Mikrobasic from www.mikroe.com.

Circuit is on pcb not breadboard so not so easy to test on another input.

Other thing that is possible is that my pcb design isnt exactly like the cct diagram and I have an error on that and are tying the input straight onto the 12v rail.

Will have a bit more of a look and come back with my findings.
Thanks
Bruce
 

Thread Starter

Maketronic

Joined Mar 21, 2009
49
Eureka.....

Thanks to Eric for helping me work through this.

Problem was.... wouldn't have been a problem if the pcb matched the circuit diagram posted earlier.

I started measuring voltages and things were weird to say the least.
Turns out my Vss pin went no further than the corresponding pin on the icsp header.
Somehow the PIC was dragging a ground back from its IO (only 2 x IO used; a logic level mosfet switching a relay and an analog in with a pull-down resistor)

If I had to guess I suspect the ground was via the pull down on AN7.

Any ways, I soldered in a jumper tying VSS to ground and it worked like a charm.

Thanks once again.

Regards

Bruce
 
Top