---
+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 5
    Points: 743, Level: 5

    Join Date
    Jan 2009
    Posts
    9
    Helped
    0 / 0
    Points
    743
    Level
    5

    pic16f877 adc

    I have decided to use the PIC16F877 C to convert a 4-20mA analog signal. I went through the manual and came accross the ADCON 1 register. I found out that it has two parts; a single bit ADFM and a 4-bit PCFG3:PCFG0. There was a table which I had was to use in order to determine what to set PCFG3:PCFG0 to. I came up with two solutions: "0101" or "1110". In both cases, Vref- is Vss but Vref+ is RA3 and Vdd respectively. Could anyone shed some light on which one i should use and why? Also, I need this data to be displayed on a LCD (every 5s or so) and at the same time be made availiable to a GPRS modem with a SIM card. Any ideas? Lastly, if you have any form of code or schematic diagram of how i should go about doing this task please let me know... Thanks

    •   Alt8th January 2009, 13:28

      advertising

        
       

  2. #2
    Full Member level 5
    Points: 3,628, Level: 14

    Join Date
    Jun 2006
    Location
    Some place Hot - Not an Island
    Posts
    255
    Helped
    42 / 42
    Points
    3,628
    Level
    14

    a/d pic16f877

    Here is a simple adc program from melabs in picbasic pro. It is using the 877 and displaying it on an LCD.

    ' PicBasic Pro program to read pots on 16F877 ADC

    ' Define LOADER_USED to allow use of the boot loader.
    ' This will not affect normal program operation.
    Define LOADER_USED 1

    ' Define LCD pins
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 0
    Define LCD_EREG PORTE
    Define LCD_EBIT 1

    ' Allocate variables
    x var byte
    y var byte
    z var byte

    ADCON1 = 4 ' Set PortA 0, 1, 3 to analog inputs

    Low PORTE.2 ' LCD R/W line low (W)
    Pause 100 ' Wait for LCD to start

    Goto mainloop ' Skip subroutines


    ' Subroutine to read a/d convertor
    getad:
    Pauseus 50 ' Wait for channel to setup

    ADCON0.2 = 1 ' Start conversion
    Pauseus 50 ' Wait for conversion

    Return

    ' Subroutine to get pot x value
    getx:
    ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
    Gosub getad
    x = ADRESH
    Return

    ' Subroutine to get pot y value
    gety:
    ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
    Gosub getad
    y = ADRESH
    Return

    ' Subroutine to get pot z value
    getz:
    ADCON0 = $59 ' Set A/D to Fosc/8, Channel 3, On
    Gosub getad
    z = ADRESH
    Return


    mainloop:
    Gosub getx ' Get x value
    Gosub gety ' Get y value
    Gosub getz ' Get z value

    Lcdout $fe, 1, "x=", #x, " y=", #y, " z=", #z ' Send values to LCD
    Pause 100 ' Do it about 10 times a second

    Goto mainloop ' Do it forever

    End

    Hope it helps.

    regards

    dfullmer


    1 members found this post helpful.

  3. #3
    Advanced Member level 5
    Points: 16,294, Level: 30

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,891
    Helped
    423 / 423
    Points
    16,294
    Level
    30

    adc pic 16f877

    The A/D uses the ref voltage as its full scale value.
    If you choose to use Vdd for Vref, then the accuracy of the A/D result will depend on the stability and noise levels of the Micro's Vdd rail. This is adaquate in most cases.
    For a higher accurate A/D result, you could choose to use a Reference voltage input on RA3. The reference voltage could be generated by a stable band gap diode. You can buy these designed for this purpose. For example, using a 4.096 voltage ref with a twelve bit A/D convertor, the result is 1mV per bit.



    •   Alt8th January 2009, 18:37

      advertising

        
       

  4. #4
    Full Member level 4
    Points: 2,910, Level: 12
    saeed_pk's Avatar
    Join Date
    May 2006
    Location
    Islamabad, Pakistan
    Posts
    236
    Helped
    35 / 35
    Points
    2,910
    Level
    12

    pic 16f877 adc

    you can use VDD as VRef+ and VSS as VRef- in 4-20mA loop you can convert 4mA->1V and 20mA ->5v as it happens you can use entire VDD range.



    •   Alt8th January 2009, 18:56

      advertising

        
       

  5. #5
    Newbie level 5
    Points: 743, Level: 5

    Join Date
    Jan 2009
    Posts
    9
    Helped
    0 / 0
    Points
    743
    Level
    5

    pıc16f877 4 20 ma

    Well i decided to use a 250Ω pot in order to vary the voltage from 1V to 5V which corresponds to 4mA - 20mA. Should I use the internal osc of the PIC or should I use an external one? I have read somwhere that the external osc is more accurate than the internal one found in the PIC. Also, I am using Assembly language so if anyone has ASM code to share I will really appriciate it.
    Any ideas on the GPRS part?

    P.S Thanks dfullmer for your time and effort...



  6. #6
    Advanced Member level 1
    Points: 9,564, Level: 23
    mrcube_ns's Avatar
    Join Date
    Apr 2002
    Location
    Europe
    Posts
    453
    Helped
    47 / 47
    Points
    9,564
    Level
    23

    pic16f877 adc lcd

    Hi S_51,

    ADC:
    I usualy use VDD and VSS as reference voltage. PIC has 10bit ADC, this means an unprecise measurement in term of number conversion of bits. So, I think that precise voltage reference, with 10bit ADC doesn't have much sence.


    Internal/external osilator:
    Internal osilator is temperature dependant, so in project where you do not need accurate time measurement, internal osc. is quite OK. If you use external osilator with XTAL (with 10ppm or similar) your clock on PIC will be very same over temperature working range.

    GPRS:
    This depends of GPRS modem you use. In most cases today, GPRS modems are capable to make TCP/IP connection, so you have "black box" with serial port.

    MCU --- Max232 --- GPRS modem - - - - - - - GPRS modem --- other device which expecting analog measurement.

    In that case you just need to make message (convert your analog value to ascii caracters) and to send it via seria port to GPRS modem.


    Best regards,

    Mr.Cube



  7. #7
    Advanced Member level 5
    Points: 16,294, Level: 30

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,891
    Helped
    423 / 423
    Points
    16,294
    Level
    30

    pic16f877 a/d conversion

    Some time ago I wrote a small program to help with writing assembler code, posted here.

    www.elektroda.pl/eboard/viewtopic.php?p=205856

    Give it a try.



  8. #8
    msm
    msm is offline
    Junior Member level 1
    Points: 2,007, Level: 10

    Join Date
    Jul 2002
    Posts
    16
    Helped
    0 / 0
    Points
    2,007
    Level
    10

    a/d converter in pic16f877a using three channels

    Hello there.

    To help me learn Picbasic I used the files that were published for the Lab-x1 devopment board. Instead of purchasing the board I built it in Proteus and then simulated the program/hardware. Included in the files below are the example from the second post.

    bas/hex files
    http://rapidshare.com/files/21008002...sic_lab-x1.rar

    Proteus schematic
    http://rapidshare.com/files/210079846/msm_lab-x1.rar

    I will be adding files and updating schematic for temperature/rtc operations over the next few days.

    Hope these files have been helpful.



  9. #9
    Member level 5
    Points: 1,951, Level: 10

    Join Date
    Nov 2006
    Posts
    92
    Helped
    12 / 12
    Points
    1,951
    Level
    10

    a/d pic16f877a

    which programming language you are using???



+ Post New Thread
Please login