AD Conversion 8bit 10bit


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2006
    Posts
    6

    Unhappy AD Conversion 8bit 10bit

    I am using a pic16f870 with picbasic to read an analog input from a temp sensor. The 870 has a 10 bit AD converter but I am only geting 8 bits. How can I change my code to get the full 10 bits. Here is my code

    Poke $1f, $45
    pause 1
    peek $1e, w3

    when I put a pot on the analog pin and vary the voltage from 0 to 5 volts I get a number from 0 to 255 so I know I am only geting 8 bit instead of 10 bit like I want.

    Thanks

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eric123 View Post
    Poke $1f, $45
    pause 1
    peek $1e, w3

    when I put a pot on the analog pin and vary the voltage from 0 to 5 volts I get a number from 0 to 255 so I know I am only geting 8 bit instead of 10 bit like I want.

    Thanks
    That's because you've got your A/D converter set up for Left-Justified operation (see the PIC16F870 datasheet, section 11.0, Register 11-2, left-justified is the default operation).
    You're peeking $1E, which is ADRESH (A/D result High), the upper 8 bits of the A/D result. You have to peek the other, lower, 2 bits out of the upper 2 bits of $9E.

    So try this (I assume you're using PicBasic, and not PicBasicPro, and I'm not 100% with the limitations of PicBasic):

    Poke $1f, $45
    pause 1
    peek $1e, w3
    peek $9e, w4
    w3 = w3 * 256 'put adresh BYTE into upper 8 bits of w3 (that's a word variable right?)
    w3 = w3 + w4 'add adresl into adresh word
    w3 = w3 / 64 'shift the whole result down by 6 bits for a 0-1023 result

  3. #3
    Join Date
    Jul 2006
    Posts
    6


    Did you find this post helpful? Yes | No

    Smile works

    Thanks that is exactly what I needed.

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. AD works in Porta.0 but not in porta.1
    By ruijc in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 19th February 2008, 20:22
  4. 16f877 AD Conversion...
    By jesterhoz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th February 2005, 03:38
  5. ADC problem
    By NacNud in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th December 2004, 02:27

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