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


Results 1 to 6 of 6

Threaded View

  1. #1
    Accelerator's Avatar
    Accelerator Guest

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

    Hi ladies and gentlemen,

    I'm very new to this forum, as well as the PIC world, and I have a simple code below to test my PIC16F819 's ADC function. I am trying to set the ADC as a 8-bit converter, however, it turned out that the value only goes up to 127, not 255 (if you refer to the code below, the value of "counter" only displayed up to 4, instead of 9, and my servo only turned half way...). By the way, my analog test input for PORTA.0 is from 0v to 5v.

    I'm stuck and I have no clue of what I have done wrong, would anyone please help me out?!

    Thanks in advance!

    regards,
    Accelerator

    ================================================== ===
    @ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF

    include "modedefs.bas"

    DEFINE OSC 8 'set the clock to 8 Mhz
    OSCCON = $70 'set the clock to 8 Mhz, 60 for 4MHz
    'set up the analog to digital converters
    DEFINE ADC_BITS 8 'set # of bits
    DEFINE ADC_CLOCK 1 'set clock source(1=internal 8MHz, 3=rc)
    DEFINE ADC_SAMPLEUS 50 'set sampling time in ms
    ADCON1 = 0 'set PORTA pins to analog
    TRISA = %00000001
    TRISB = %00000000

    COUNTER var PORTA
    LED var PORTB.7
    POTENTIAL var byte

    high led

    SENSOR01:

    ADCIN 0,potential

    If potential>0 and potential<26 then counter = 0
    If potential=>26 and potential<51 then counter = 1
    If potential=>51 and potential<76 then counter = 2
    If potential=>76 and potential<101 then counter = 3
    If potential=>101 and potential<126 then counter = 4
    If potential=>126 and potential<151 then counter = 5
    If potential=>151 and potential<176 then counter = 6
    If potential=>176 and potential<201 then counter = 7
    If potential=>201 and potential<226 then counter = 8
    If potential=>226 and potential<255 then counter = 9

    pulsout PORTB.0, potential

    goto sensor01
    ================================================== ===
    Last edited by Accelerator; - 18th June 2006 at 07:05.

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 : 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