Working with Analog Pins in PIC16F877 (C language)

Discussion in 'Embedded Systems and Microcontrollers' started by Gtofig, Feb 6, 2008.

  1. Gtofig

    Thread Starter Member

    Jan 4, 2008
    14
    0
    Hello. I am very new to PIC programming. I am using MikroC compiler for PIC. The problem I have is:
    I have a distance sensor, which will give me a range of voltages from 0 to 3 Volts. I need to get this value as a float variable in the program, so that I can use it in my C program. How do I work with Analog inputs? I think I should connect sensor to the RA0, for example. Then I set TRISA.F0=1 (declare as input). What should I do next? How to read the sensor data into variable of float type? I know that I should somehow tell the PIC that it is analog input, not digital.
    Any advise would be appreciated.
    Thank you,
    Gtofig
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The 16F877 has 8 A to D inputs that make analog voltages into digital values. The info about them appears starting on page 111 of the data sheet.
     
  3. Gtofig

    Thread Starter Member

    Jan 4, 2008
    14
    0
    Thank you. This seems to be very well explained there indeed.
     
  4. ramar

    New Member

    Jan 13, 2010
    1
    0
    Hi ,i m using pic 16f877a for my project.i want to know maximum input current and voltage rating of pic 16f877a(i want to measure input current of 5Amps).if i need to reduce means,what type of circuit should i need to use ,,,,Please give suggestion..
     
  5. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    5 amps will fry your pic. did you mean 5 mA?

    If not, you want to divide your current by 100 using a circuit, then measure that. In your code you can multiply the measured number by 100 to get the actual number.

    [ed]
    Here is information on current dividers:
    http://en.wikipedia.org/wiki/Current_divider

    also, you should have the datasheet for your PIC onhand at all times. You can find all the information on current maximums and many other important facts.
    the datasheet is located here:
    ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf

    PAGE 1 shows the MAX sink-source current at 25 mA
     
    Last edited: Jan 13, 2010
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your PIC do not have a current sensing input. But analog to digital converters for voltage. Current measurement is usually done by inserting a small resistor in the current path. Then we measure the resulting voltage drop over this resistor. An Instrumentation amplifier is ideal for such a task. http://en.wikipedia.org/wiki/Instrumentation_amplifier
     
Loading...