16F819 ADC 8bit=127, Not 255?Help!


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    A couple things to watch out for.

    1.
    Place ADCON1 = %01001110 in the init section of your code. Now only RA0
    is configured as an analog input, and the rest can be used for digital I/O.

    Some pins you're trying to use as digital outputs are still configired as analog
    inputs. ADCON1 = 0 sets them "all" to analog inputs.

    2.
    You need a different A/D conversion clock if you're running at 8MHz. With
    ADCON1.6 = 1 this sets the conversion clock to 16 which is what you need
    for any osc over 5MHz up to 10MHz MAX. See the data sheet table Tad vs.
    max device operating frequency.

    3.
    If you're using RA0 for the A/D input, and RA5 is input only, you're never
    going to see from 0 to 255 output on your LED's on porta. You could use all
    of portb for the LED's and output your pulse on one of the porta pins like RA1,
    2,3,4,6 or 7.

    4.
    PULSOUT toggles the pin twice, so the initial state of the pin used determines
    the polarity of your pulse. If you want a high-going pulse, then clear the pin
    you're using first. Just above TRISB = %00000000 place PORTB = %00000000.

    PULSOUT resolution at 8MHz is 5uS. Assuming your A/D reading is from 0-255,
    your MAX servo pulse can only be 5uS x 255 = 1.275mS.

    You could use pulsout PORTB.0, potential*2 to compensate. That increases
    your pulse out to ((255*2)*5uS) = 2.55mS MAX. Your servo should move full
    range in both directions. You may want to add a short delay just after your
    PULSOUT to get somewhere between 50-60Hz update rates.
    Last edited by Bruce; - 18th June 2006 at 16:27.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    1. mistake:
    You defined the variable COUNTER on PARTA. Why ?
    If you read this 8 bits back, they represent the digital attached signals from the pins.
    You should define it as a simple variable (Var byte).

    2....:
    you write to Counter, but never read it back ?

    3....:
    maybe you can throw away the if-thens by using counter=Potenzial*10/256 with some other steps
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    Accelerator's Avatar
    Accelerator Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you very much for all the comments!!!! I do appreciate them! You guys are masters!!

    I have not tried you guys advises yet, I have been busy these couple days. But I will surely try them out once I free up myself!

    To reply the questions #2 from BigWumpus, I connected my PORTA.1~4 to a single digit display through a decoder; and since its just a display, I don't need to read it back. I do like your #3 suggestion though! Thanks a lot!


    Quote Originally Posted by BigWumpus
    1. mistake:
    You defined the variable COUNTER on PARTA. Why ?
    If you read this 8 bits back, they represent the digital attached signals from the pins.
    You should define it as a simple variable (Var byte).

    2....:
    you write to Counter, but never read it back ?

    3....:
    maybe you can throw away the if-thens by using counter=Potenzial*10/256 with some other steps

  4. #4
    Accelerator's Avatar
    Accelerator Guest


    Did you find this post helpful? Yes | No

    Default

    I finally have time to work on my code, and YES! I got it work!!

    There are few things I changed:
    1. For the single digit display, I changed my output from PORTA, to PORTB.0~3. Since then, it displayed numbers from 0-9!!!

    2. For the servo, I changed the PULSOUT signal from potential to potential*2, because, the full motion range 0-255 is for 4MHz, but I'm using 8MHz indeed.

    Thank God!!!

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. 16F819 ADC problems
    By MUC in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 22nd March 2008, 18:36
  4. Need help with 16f819 10 bit ADC
    By bannrikae in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th September 2005, 15:20
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 0

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