16f877 A/D help


Closed Thread
Results 1 to 2 of 2

Thread: 16f877 A/D help

  1. #1
    3adam's Avatar
    3adam Guest

    Default 16f877 A/D help

    hi
    im new user in this forum.And my english is not good.I hope you can understand me.
    ı use the 16f877 and this code:TRISA = %00001011
    trisb=1
    portb=0

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

    ADCON1 = 4 ' Set PortA 0, 1, 3 to A/D 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 converter
    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
    pwm portb.0,x,1
    pwm portb.1,y,1
    pwm portb.2,z,1

    Goto mainloop ' Do it forever

    End
    ı connect the 3 led from the portb.0 portb.1 and portb.2
    its working but its not come to 0v.All led is not come to off.This problem is burn to code or hardware please help me
    thx

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by 3adam View Post
    hi
    im new user in this forum.And my english is not good.I hope you can understand me.
    ı use the 16f877 and this code:

    ı connect the 3 led from the portb.0 portb.1 and portb.2
    its working but its not come to 0v.All led is not come to off.This problem is burn to code or hardware please help me
    thx
    16F877 or 16F877A? Not that it matters much in the hardware for this application...but the mistake has been made before.

    Are you sure you voltage inputs are actually going to 0v? Ground them out to make sure.

    X,Y,Z....looks like an accelerometer input to me. Don't forget that just because an accelerometer isn't moving, doesn't mean it's not sensing something...if this is actually an accelerometer. And some accelerometer outputs are ratiometric and have outputs on the order of mV, and need to be amplified correctly to get a 0-5v output signal.

Similar Threads

  1. PIC 16f877 A/D conversion Allegro ACS712
    By DavyJones in forum General
    Replies: 32
    Last Post: - 4th June 2011, 04:54
  2. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 02:16
  3. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 14:39
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. A/D on 16F877. How fast can I go?
    By atomski in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th April 2004, 06:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts