adc averaging readings


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

    Default adc averaging readings

    hello,
    for a alternator regulator using 12f683 pwm, i want to smooth a/d readings by taking 3 readings and discard the high and low reading to make next pwm calc. I'm trying to keep math calculations from slowing down process too much. any fast way to check 3 readings and discard high and low reading?

    also working on a self tuning PID. seems like the micro and program could tune itself to simply reduce/increase P,I or D to stop or set overshoot .am i missing too many brain cells?

    don
    american generator

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by amgen
    any fast way to check 3 readings and discard high and low reading?
    Code:
    X1 VAR word  ;1st data point
    X2 VAR word  ; 2nd data point
    X3 VAR word  ; 3rd data point
    Xtemp VAR word  ; temp variable
    
    ;******************
    Gosub X2X1Compare
    
    If X3 < X2 THEN ; swap if true
         Xtemp = X2
         X2 = X3
         X3 = Xtemp
    ENDIF
    
    Gosub X2X1Compare
    
    X2 is now your keep value ; <- here is your answer
    
    END
    ;******************
    X2X1Compare:
         If X2 < X1 THEN ; swap if true
              Xtemp = X1
              X1 = X2
              X2 = Xtemp 
         ENDIF
    Return
    ;******************
    However, it is would be much easier and computationally faster to sample 4 values, add them together, and divide by 4 (using shift right)
    Code:
    Xtemp = X1+X2+X3+X4
    Xtemp = Xtemp >> 2 ; <- here is your answer
    Paul Borgmeier
    Salt Lake City, Utah
    USA

  3. #3
    amgen's Avatar
    amgen Guest


    Did you find this post helpful? Yes | No

    Default ad averaging

    Paul,
    Thankyou for your suggestion to take 4 readings etc. I will use that routine. Its always better the simpler.
    don
    american generator

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 Averaging
    By Sach_1979 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st September 2009, 06:53
  4. 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
  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