Maximum value of ADCIN


Closed Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582

    Default Maximum value of ADCIN

    I try to find myself the answer on this question, but I am not sure if I understand correct. Please, help me ! I read, for 7 seconds, the value of ADCIN, using 12F675 ; I need to memorize
    the maximum (the highest) value of reading. It's like this OK ?
    Code:
     for cnt=1 to 70       			
    	adcin 3, v_cal
      	v_cal=v_cal * 5000            ' I use VDD as Vref
      	v_cal=div32 1023
     ' 	vmax=0 max v_cal             ' it's this
          or
     '    vmax=vmax max v_cal         ' or this correct ?
      	pause 100
     next cnt

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Why not using a simpler way?

    Code:
    for cnt=1 to 70       			
    	adcin 3, v_cal
      	v_cal=v_cal * 5000            ' I use VDD as Vref
      	v_cal=div32 1023
    
    If cnt = 1 then
    vmax = v_cal  
    else
    If v_cal > vmax then vmax = v_cal
    endif
    
    pause 100
     next cnt
    Cheers

    Al.
    Last edited by aratti; - 12th November 2010 at 14:02.
    All progress began with an idea

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Fratello,

    The result should be in mVolts.
    Last edited by rsocor01; - 12th November 2010 at 16:36. Reason: Incorrect statement
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You almost had it right Fratello.
    And the timing will be more accurate if you don't do the math on each loop.
    Code:
    vmax = 0
    for cnt=1 to 70       			
        adcin 3, v_cal
        vmax=vmax max v_cal
        pause 100
    next cnt
    v_cal=vmax * 5000            ' I use VDD as Vref
    v_cal=div32 1023
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thank You all for reply !
    Both variant (mine = 0 max v_cal and variant of Mr.Robert ) give me the same results : 24 .
    According of my math, I think this is the value of 24 mVolts. I am right ?
    Now I try the variant of Mr.Darrel (remember ? My guardian angel in PBP problems ...).
    I post the results.
    LE : Something strange...with this variant, I read only 5 mV ?!
    Maybe the schematic help...
    Attached Images Attached Images  
    Last edited by fratello; - 12th November 2010 at 16:16. Reason: schematic added

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Oops, disregard my comment. Yes, you should get your result in millivolts.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

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


    Did you find this post helpful? Yes | No

    Default

    Tested and re-tested today both variant : Mr.Darrel's and Mr.Aratti.
    Still different results : 5mV vs. 24 mV. It's so strange for me...

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    fratello,
    I'm not sure what you've done in your code, but I've tested it here and it works.

    <object id='stUkhdQ01IR1FWRltYU1tYUVNR' width='425' height='344' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name='movie' value='http://www.screentoaster.com/swf/STPlayer.swf'/><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='flashvars' value='video=stUkhdQ01IR1FWRltYU1tYUVNR'/></object>
    Attached Files Attached Files
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Wow, Thank You again Mr.Darrel !
    Maybe my code it's wrong ; I use
    Code:
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    instead
    Code:
    DEFINE ADC_BITS 10     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 1     ' ADC clock source  (Fosc/8)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
    This is the explanation, don't ?
    NO, I think this is NOT the explanation ! My math teacher it's verry, verry angry ...
    I learn more here : http://www.darreltaylor.com/DT_Analog/
    1 step=0.0048875. So, if I have Max_result 450, Volts= 450 * 0.0048875 =2.199 Volts; for 696 --> Volts= 696 * 0.0048875 =3.401 Volts...
    Stupid me, again
    Last edited by fratello; - 13th November 2010 at 16:54.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    No, that won't matter.

    Can you post your Proteus files (zipped)?
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Yes, all is OK now !
    If v_cal is 1023 (maximum 5.000V) it's correct this command for memorise in EEPROM :
    write 0, v_cal
    I read the PBP help, but I find only this : write 5,B0 ' Send value in B0 to EEPROM location 5.
    And I can read them when I need, with this command :
    read 0, v_cal ???
    It's enough like these or need more ?
    Thanks in advance and sorry for my ignorance...

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If v_cal is 1023 (maximum 5.000V) it's correct this command for memorise in EEPROM :
    write 0, v_cal
    ...
    read 0, v_cal ???
    It's enough like these or need more ?
    If you have PBP 2.60, then you could ...

    Code:
    write 0, WORD v_cal
    
    read  0, WORD v_cal
    If you don't have 2.60 yet, you'll need to ...

    Code:
    write 0, v_cal.LowByte
    write 1, v_cal.HighByte
    
    read  0, v_cal.LowByte
    read  1, v_cal.HighByte
    DT

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


    Did you find this post helpful? Yes | No

    Default

    I understand now ; I read 10 pages of search "eeprom".
    Of course, the answer it's simple if somebody help ! Thanks, Mr.Darrel !
    ....
    So, if eeprom it's like in picture :
    75 (hex) = 117 (dec)
    v_cal = 117 * 4,8875 = 572 mVolts ?
    Attached Images Attached Images  
    Last edited by fratello; - 14th November 2010 at 16:31. Reason: adding picture

  14. #14
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    So, if eeprom it's like in picture :
    75 (hex) = 117 (dec)
    v_cal = 117 * 4,8875 = 572 mVolts ?
    Yes, if you saved the MAX A/D value instead of the converted value.

    In that case, be sure to use the previous formula to convert it to voltage.
    Code:
    v_cal=v_cal * 5000            ' I use VDD as Vref
    v_cal=div32 1023.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    I use this code :
    Code:
        vmax = 0
        for cnt =1 to 70       			
            adcin 3, v_cal
            vmax =vmax max v_cal
            pause 100
        next cnt
    
        v_cal=vmax * 5000            ' I use VDD as Vref
        v_cal=div32 1023
    
    write 0, v_cal.LowByte
    pause 10
    write 1, v_cal.HighByte
    pause 10

  16. #16
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Then you have saved the value as a Voltage.
    And 117 means 117mV.

    Since I = E / R ... with a 0.02 ohm resistor ...

    0.117 / 0.02 = 5.85 Amps

    Dividing by 0.02 is the same as multiplying times 50.

    117 * 50 = 5850 or 5.850 Amps.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    One truck with e-beer for Mr.Darrel ! With thanks for fratello !
    Now another worm walk to my convolutions ! If at start of colecting samples, my motor give me one peek (or "n" peeks) of voltage , but the real v_cal ( from the end of route) it's smaller than peek(s) , it's possible to reject them ? Something like here : http://www.picbasic.co.uk/forum/showthread.php?t=12183
    It's possible to use :
    Code:
    AvgCount	CON  70		' Number of samples to average
    FAspread	CON  50 	' Fast Average threshold +/-
    Reject          CON  2          ' Spurious Rejection level
    ...etc - see post
    Attached Images Attached Images  
    Last edited by fratello; - 15th November 2010 at 17:07.

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


    Did you find this post helpful? Yes | No

    Default

    Since the whole code don't fit into 12F675, I give up...till hw upgrade...
    So, I put in my code one little delay (pause 500) before starting ADC reading...I hope it's enough.

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


    Did you find this post helpful? Yes | No

    Default

    It's ok with "pause'... I have though just one question...
    If I use this code:
    Code:
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    ....
    Code:
     for cnt = 1 to 3
     	adcin 3, adval
     	vt=adval * 5000
     	vt=div32 1023
     	grup=vt+grup
     	pause 20
     next cnt
     vs=grup / 3
    how small can be "pause' for correct reading of ADC ?
    Thanks in advance !

  20. #20
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It can be zero.
    Dave
    Always wear safety glasses while programming.

  21. #21
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You will still get correct A/D readings without any pause at all in there.

    I guess it depends on how much the signal is changing, as to whether the average will be accurate or not.
    DT

Members who have read this thread : 0

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