4-20mA on a PIC 16f690

Discussion in 'Embedded Systems and Microcontrollers' started by Maketronic, Mar 9, 2014.

  1. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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

    [​IMG]
     
  2. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
  3. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    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
     
  4. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2.  program BasicPumpControl
    3.  ' Declarations section
    4. symbol pump = porta.2
    5. dim counts as integer
    6. dim level_raw as word
    7. dim level_text as char[5]
    8.  main:
    9. '   Main program
    10. intcon.gie = 0
    11. ansel.2 = 0
    12.  trisa.2 =0
    13. uart1_init(9600)
    14. adc_init()
    15. uart1_write_text("CS0")
    16. uart1_write(10)
    17. uart1_write(13)
    18. delay_ms(100)
    19. level_raw = 0
    20. while true
    21. level_raw=adc_read(7)
    22. wordtostr(level_raw, level_text)
    23. uart1_write_text("CL")
    24. uart1_write(10)
    25. uart1_write(13)
    26. uart1_write_text("TTLevel_Raw:")
    27. uart1_write_text(level_text)
    28. uart1_write(10)
    29. uart1_write(13)
    30. pump = not pump
    31. delay_ms(1000)
    32.  
    33. wend
    34. end.
    35.  
    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
     
  5. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    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
     
  6. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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
     
  7. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    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.?
     
  8. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
  9. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    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
     
  10. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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?
     
  11. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    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.
     
  12. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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
     
  13. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi Bruce,
    Ok, lets know what you find and we will take it from there.
    E
     
  14. Maketronic

    Thread Starter Active Member

    Mar 21, 2009
    49
    0
    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
     
Loading...