Stable Adc Reading Routine


Results 1 to 28 of 28

Threaded View

  1. #13
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Stable Adc Reading Routine

    Me ... again ...
    Tried to use Mr.Darell (RIP ) routine :
    Code:
    include "D:\PBP\average_DT.pbp"
    
    Main:
    ADCON0 = %10001001 
    		Pauseus 50			' Wait for channel to setup
    	        ADCON0.1 = 1			' Start conversion
    		While ADCON0.1=1:Wend		' Wait for conversion
    		value.HighByte=ADRESH		' Read variable from ADC and save
    		value.LowByte=ADRESL
    gosub Average
    advalue=value
        if (advalue < 650) then
    	IF (advalue > 450) AND (advalue < 640) THEN gosub do_1 ...
    	IF (advalue > 320) AND (advalue < 440) THEN gosub do_2 ...      
            ...   
        endif
    
    Goto Main
    ...but something is wrong - always is executed do_1 subroutine

    Note : the code in his "simple" variant, works just fine . Just I want more "accuracy" ...
    Code:
    advalue  var word
    advaloop var byte
    advaltot var word
    
    pause 200
    
    Main:
    advaltot=0
    advaloop=0  
    
    ADCON0 = %10001001 
            PAUSEuS 50                      	' Wait for A/D channel acquisition time
            ADCON0.1 = 1
    for advaloop = 1 to 20
            WHILE ADCON0.1 = 1 : WEND
            advalue.HighByte = ADRESH
            advalue.LowByte = ADRESL
            advaltot=advaltot + advalue
    next advaloop
    
    advalue=advaltot / 20
    
        if (ADvalue < 650) then
    	IF (ADvalue > 470) AND (ADvalue < 640) THEN gosub do_1
    	IF (ADvalue > 320) AND (ADvalue < 450) THEN gosub do_2    
            ...           
        endif
    Goto Main
    Last edited by fratello; - 10th May 2015 at 13:15.

Similar Threads

  1. Reading A Photo Resistor using ADC
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2007, 10:28
  2. adc reading ac
    By Ruben Pena in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th December 2005, 22:57
  3. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 02:55
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 17:46
  5. Reading multiple ADC channels FAST
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st April 2004, 23:37

Members who have read this thread : 2

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