Analog pin of ADC in PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by ecaits, Aug 25, 2014.

  1. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    Hello Friends,

    I am working on PIC16F877 controller based project where I am using ADC module and read the value of connected sensor's output. I am using different types of pressure sensor. I am using LCD to display the value of ADC. Pressure sensor is giving output 0 to 5VDC.

    Case 1:
    Now I want to detect the sensor in four different conditions.... given below...

    1. When Sensor is Open, I want to display "Sensor is Open" on LCD.
    2. When Sensor is short, I want to display "Sensor is Short" on LCD.
    3. Due to sensor defect, if sensor gives reverse voltage to Analog pin then I want to display "Sensor Fail" on LCD.
    4. Due to sensor defect, if sensor gives over voltage to Analog pin then I want to display "Sensor Fail" on LCD.

    How can I sense the sensor's failure condition given above???

    Case 2:
    Some sensor is giving 4-20 mA output which I need to convert it to 0-5V output. How Can I convert I2V??
    Plz provide me any circuit which helpful to me.

    Thank you in advance.....

    Nirav
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,504
    380
    hi,
    A simple circuit like this will do I2V.

    Have you considered combining failures 1 and 4 to a common failure , also 2 and 3 could be combined.

    Just set upper and lower limits for the ADC voltage in the program.

    It would be helpful if you posted the type/s of sensors you plan to use.
    E
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,398
    497
    First you say that sensor output 0-5 volts.
    Then you say that sensor can be open, can be short.
    You are not making sense.
     
  4. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    Yes, Sensor will give me 0-5V DC but some time sensor may open or short, at that time I want to detect that whether sensor is short or open....
     
  5. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,504
    380
    hi,
    Is this thread related to your other I2V thread.?

    You have to define what you mean by sensor may open or short, do you mean a break or short in the 4-20mA loop, or the sensor itself.?

    E


     
  6. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    If the sensor is shorted then 5 volts that power it will be shorted as well, so power will go to zero volts and MCU will die.

    Alberto
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Validating your sensor input is typically a good idea. It is based upon the premise of “garbage in, garbage out.” However, by restricting the input to the range of 0 to 5 V is going to cause you headaches in accomplishing this.

    Why? Because zero volts is a valid sensor reading, but it is the same reading as a shorted sensor. If the input goes below zero (as in a reversed sensor) the A2D will read this as zero… again a valid reading.

    What you want is a range of inputs clearly discernible between legitimate and failure values.

    Using a 250 ohm resistor in a 4/20mA loop is a good starting point: an open sensor will give you zero, which is below the lowest legit reading. The 5 V input is not optimal as it may be mistaken for an open sensor.

    I would start with the following:

    - use a good reference voltage such as one of the excellent 4.096 V devices.
    - use a 170 ohm resistor in the 4/20 loop for a legit range of 0.68 to 3.4 V

    That makes it simple to see out of bounds readings, but it throws away 1/3 of your range. So I would keep the reference, but increase the 170 to say 190 ohms. At the same time I would add a divider on the reference to make a –Vref signal of about .56 volts. This only leaves about .2 low end and .2 high end out of bounds, so you still get about 90% of your range back.

    Any other schemes will involve switching the input leads to test them individually. This lets you make a measurement and validate it every time in a simple way.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Come to think about it, one could switch the A2D reference pins to Vdd and Vss to perform a validation measurement, then switch to a bounded pair to achieve near 100% scale coverage, meaning 100% of the sensor range is measured in close to (but still a little less than) 100% of the A2D range.

    A bit longer but we're still not adding hardware.
     
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I like your logic but I would employ another method. I would test the impedance of the sensor.

    If a second PIC pin is connected to the ADC pin and both are set to analogue inputs the second pin won't have any effect on the sensor reading.

    Then if the second pin is changed in software to a digital output pin, and driven HI or LO, it will have a known pullup or pulldown effect on the sensor reading depending on the sensor impedance and drive ability.

    But if the sensor wire is shorted or open the second pin will have a very different effect on the ADC reading to a working sensor.

    This system will work better if the sensor has a highish impedance (>1k ?) but you could always put a 1k resistor on the sensor output wire at the sensor if it has a low impedance.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    I was also thinking along those lines too, but after repeated request on this and other threads the OP still refuses to discuss what his sensor is.

    I'm not so sure your idea will work with a very low impedance sensor: how do you resolve a working from a shorted sensor?

    Now if we actually knew what the sensor was these questions would not arise. :D
     
Loading...