12F675 ADC 'Issues'


Closed Thread
Results 1 to 3 of 3
  1. #1
    harrisondp's Avatar
    harrisondp Guest

    Default 12F675 ADC 'Issues'

    Hello everyone,

    I have read that the 10bit reading from the onboard ADC on the 12F675 should range from 0 to 1023 (1024 steps). I can never achieve this. I have tried two different ways of reading the adc value (one with the built in adc command and one with messing with the registers directly). I have also tried different test boards (one is a homemade pcb etched with the toner transfer method and another was built on a standard breadboard).

    The ADC's vref is set to vcc. I can get 0 whenever I set the AN0 pin to GND. I get around 1012 - 1013 when I set the AN0 pin to VCC (+5v). My vcc is a stable 5v dc (checked with two meters).

    My current code for reading the adc is:

    Code:
    reading var word
    avgloop var byte
    avgtotal var word
    
    CMCON = 7 ' Comparators OFF 
    ANSEL = %00100001 ' AN0 enabled (last 4 bits are enable bits {AN3:AN0}
    ADCON0 = %10000001 ' VCC Vref / Turn On ADC Module
    
    readadc:
    	' Take 20 readings and average them for accuracy
    	avgtotal = 0
    	for avgloop = 1 to 20
    		ADCON0.1 = 1 ' Start ADC
    		loopadc:
    			if ADCON0.1 = 1 then goto loopadc ' Check to make sure ADC conversion finished..
    		pause 5 ' Give ADC Settling Time
    		reading.highbyte = ADRESH
    		reading.lowbyte = ADRESL
    		avgtotal = avgtotal + reading
    	next avgloop
    	reading = avgtotal / 20
    return
    I am using a 12F675 with pbp 2.44.

    Harrison

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    What's the Pause 5 in aid of? You want to give the ADC time to settle after you first switch it on (ADCON0 = %10000001 statement)... not AFTER it's taken the result (kinda after the event in my opinion!).

    The rest of your code looks good, but that messy 'If...goto' in the middle of your For...Next loop could be replaced with a simple...

    While ADCON0.1=1:Wend

  3. #3
    harrisondp's Avatar
    harrisondp Guest


    Did you find this post helpful? Yes | No

    Default

    I don't think that would be a problem since the readadc sub isn't called until the 12F675 has been up for 30 seconds.

    Thanks for the helpful hint on the while:wend usage. I would have never thought of that.

    Harrison

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. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  4. ADC on 12f675?
    By peu in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th March 2005, 17:44
  5. Serial LCD on 12F675
    By anj in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st March 2004, 23:11

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