+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 41 to 57 of 57
  1. #41
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,196

    Default Re: Stable Adc Reading Routine

    Why not just use a LOWPASS filter like this?

    ' ************************************************** ******************
    LOWPASS0: 'LOW PASS FILTER (256 = NO FILTER)
    ' ************************************************** ******************
    PASTVAR = (PASTVAR - (PASTVAR */ FILTER)) + INVAR
    OUTVAR = PASTVAR */ FILTER 'FINAL DRIVE OUTPUT COMPUTED
    RETURN
    Dave Purola,
    N8NTA
    EN82fn

  2. #42
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    LOL what I actually need is ROUND statement which will round, for example, 799 to 800.

  3. #43
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    Hysteresis idea is great and I've done in fact PID algorithm on pic by myself, but I don't see how it is related. All I want is to have rough, 80 position input from ADC, without data flickering, that's all.

  4. #44
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,914

    Default Re: Stable Adc Reading Routine

    What are you doing with that data? Are you just displaying it and you are annoyed by the flicker?

    Ioannis

  5. #45
    Join Date
    May 2013
    Location
    australia
    Posts
    1,716

    Default Re: Stable Adc Reading Routine

    LOL what I actually need is ROUND statement which will round, for example, 799 to 800.
    what would you "round" 798 to ?
    This is more entertaining than Free to Air TV

  6. #46
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    This data is feedback from position of camera slider. For the rounding, I'm dividing it by 10, and PBP does it wrong - instead of rounding to nearest big, it rounds to nearest small value.

  7. #47
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    I mean, 796/10 should be 80, but PBP returns 79.

  8. #48
    Join Date
    May 2013
    Location
    australia
    Posts
    1,716

    Default Re: Stable Adc Reading Routine

    I mean, 796/10 should be 80, but PBP returns 79.
    so (796+5)/10 = ?
    This is more entertaining than Free to Air TV

  9. #49

    Default Re: Stable Adc Reading Routine

    For the rounding, I'm dividing it by 10, and PBP does it wrong -
    It doesn't do it wrong. Integer division doesn't round... it truncates. If you want to round the number you need to do something before the division.

    so (796+5)/10 = ?
    Thank you.

  10. #50
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    796 will keep changing, so there always will be then case than final result will be less again.

    Regarding how it does, in school I was taught that if something is above 5, it is rounded to nearest big, and if less than 5, then to nearest small. I mean, 79.6 should be rounded to 80 and 79.4 to 79.

  11. #51

    Default Re: Stable Adc Reading Routine

    That's how rounding works when you have fractional numbers.

    Most (all?) uC's only represent numbers using integers so there's no fractional part for it to "round". Division always throws away what would be the fractional part.

  12. #52
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    308

    Default Re: Stable Adc Reading Routine

    Do your division first looking at the integer result (796 / 10 = Result) then do it again looking at the remainder/modulus (796 % 10 = Modulus). If modulus >= 5 Then Result += 1.

    That will give you the control of your rounding issues.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  13. #53
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,196

    Default Re: Stable Adc Reading Routine

    I have been following this thread for some time and you say this in post #46 "This data is feedback from position of camera slider." What are you doing with the feedback data? Using it to close loop on the position? WOW I can see it now, the camera jittering back and forth because of rounding of the position data. When I mention a lowpass filter in post #41 you "LOL". What kind of position timing are you looking for? In an earlier post you talked about controlling the position from some position data entered into eeprom or ram and recalling it. Once again I have to ask, What kind of response timing are you looking for as far as positioning the slide to the commanded data? Personally I would use a lowpass filter for the feedback data to do a closed loop and not have the camera moving back and forth due to rounding of the position data. It also looks like you have significant noise problems with the target system as Richard mentioned in post #38.
    Dave Purola,
    N8NTA
    EN82fn

  14. #54
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,235

    Default Re: Stable Adc Reading Routine

    Quote Originally Posted by mpgmike View Post
    Do your division first looking at the integer result (796 / 10 = Result) then do it again looking at the remainder/modulus (796 % 10 = Modulus). If modulus >= 5 Then Result += 1.

    That will give you the control of your rounding issues.
    in Post #35 , I tried to explain the same thing in a different way; but I think he could not get it work.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  15. #55
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    I tried that thing with modulus and +5, but in real code it causes more noise. Say digit is jumping between 699-700, with that code, I occasionally see it jumping to 707. For the noise, in ADC reading in 0-1023 range, I only have last digit having noise issues, and that is also only sometimes.

    But meanwhile I run into an speed issue.

    Code:
    dremo:
    gosub sadc 'read ADC and get SPS as result
    if SPS>350 and SPS<480 then
    high SST
    @nop
    @nop
    @nop
    low SST
    endif
    if SPS<360 then high SEN
    if SPS>470 then low SEN
    goto dremo
    
    SADC: 'slider adc read
    adcin 0,st1
    pause 1
    adcin 0,st2
    St3=abs(st1-st2)
    if St3=0 then 
    SPS=St1
    else 
    SPS=SOL
    endif
    SOL=SPS
    return
    Driving SST pin high and low generates pulses to stepper motor. On PIC16F886, this code runs fine with speed of around 200Hz. Considering this is for only one axis and similar code should be added for another axis, speed will be even lower, which is not enough for my uses (need at least 200Hz on both axes). So I have either to switch to at least 32mhz chip, or optimize code above?

  16. #56
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Stable Adc Reading Routine

    Replaced Pause 1 in ADC subroutine with 5 NOPs and speed is now 780Hz. I guess if I interleave both ADC reading operations, can get total speed of 400Hz, which should be enough...

  17. #57
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    308

    Default Re: Stable Adc Reading Routine

    An approach I use to reduce UART transmissions of redundant data is to use a simple filter:

    Code:
    AdcVal VAR BYTE
    OldAdcVal VAR BYTE
    
    ;Do ADC read into AdcVal
    IF AdcVal != OldAdcVal THEN
      ;Do Something
      OldAdcVal = AdcVal
    ENDIF
    Expanding this you might try something like this:
    Code:
    VarCnt VAR BYTE
    AdcVal VAR BYTE
    OldAdcVal VAR BYTE
    
    ;Do ADC read into AdcVal
    IF AdcVal != OldAdcVal THEN
      VarCnt = VarCnt + 1
      IF VarCnt = 10 THEN
        ;Change Camera Angle
        OldAdcVal = AdcVal
        VarCnt = 0
      ENDIF
    ENDIF
    This would reduce the jitter, and with fast ADC reads, latency might not be an issue.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

Similar Threads

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

Members who have read this thread : 25

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