Shop OBEX P1 Docs P2 Docs Learn Events
Measuring Capacitance — Parallax Forums

Measuring Capacitance

ArchiverArchiver Posts: 46,084
edited 2004-01-07 18:13 in General Discussion
Hi All,

Can anyone direct me to an article or link that shows how to measure
capacitance using a Stamp? I just think it would be neat to try. I'm
familiar with the famous equation V(t)=Vo*e^(-t/tau). The problem is
is after charging the capacitor to Vo, you then have to disconnect
the source so the cap starts to discharge through R, and start an
RCTIME command until the V(t) hits logic swing. I can't think of how
to do these two things at precisely the same time. Thanks for any
help.

-Dave

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 01:12
    Take a look at the Stamp RCTIME command.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: nuclearspin2000 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=sMr2lHJCXfR9HDEIrv9kf6e-lgkgwpzVbClZoP9j-ETUnadQIijYZIHoBXxDUp2MOdq3Cx-OxJz4eGZoJki9FsE]nuclearspin2000@y...[/url
    Sent: Tuesday, January 06, 2004 6:57 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Measuring Capacitance


    Hi All,

    Can anyone direct me to an article or link that shows how to measure
    capacitance using a Stamp? I just think it would be neat to try. I'm
    familiar with the famous equation V(t)=Vo*e^(-t/tau). The problem is
    is after charging the capacitor to Vo, you then have to disconnect
    the source so the cap starts to discharge through R, and start an
    RCTIME command until the V(t) hits logic swing. I can't think of how
    to do these two things at precisely the same time. Thanks for any
    help.

    -Dave


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Yahoo! Groups Links

    To visit your group on the web, go to:
    http://groups.yahoo.com/group/basicstamps/

    To unsubscribe from this group, send an email to:
    basicstamps-unsubscribe@yahoogroups.com

    Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 02:08
    Hi Jon,

    I read through that thoroughly. But there are fundamental problems
    with Parallax's description of the circuits used in the examples from
    the help file. As examples they present circuit A (preferred) and
    circuit B. Circuit A has two variations, the first one is:

    Vdd=+5
    |
    |
    C
    |
    |---220---I/O pin (7)
    R
    |
    |
    Gnd

    Example code from the help file:

    result VAR Word ' Word to hold result

    Main:
    HIGH 7 ' Discharge the cap
    PAUSE 1 ' for 1 ms
    RCTIME 7, 1, result ' Measure RC charge time
    DEBUG ? result ' Show value on screen
    END

    The problem is that the instruction HIGH 7 doesn't discharge the
    capacitor as long as the suggested 220 ohm resistance is there. The
    voltage at the lower side of the cap is whatever the voltage drop
    across R is when HIGH 7 is executed and it isn't +5V unless R is much
    greater than 220 and then it's still an approximation.

    Omitting the 220 ohm resistor fixes the above problem and I've done
    this in the past but I'm trying to measure a capacitor marked as
    1000uF. After working out about a page of calculations I get that R
    must be no more than about 43 ohms to keep the time constant small
    enough so that the value returned by RCTIME falls within the range
    for my BS2SX which is no more than 52.43mS based on 65535*(0.8uS),
    and that's also assuming a natural response RC circuit, maybe that's
    where I'm going wrong.

    Now if I omit the 220 ohm resistor and pull pin 7 high, the current
    flowing from the stamp pin is minimally 5V/43ohms=116mA and I fry my
    stamp pin.

    Maybe I'm making this too complicated but it doesn't seem like it has
    a simple solution to me. I guess I'll have to break out my circuits
    books.

    -Dave




    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > Take a look at the Stamp RCTIME command.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: nuclearspin2000 [noparse][[/noparse]mailto:nuclearspin2000@y...]
    > Sent: Tuesday, January 06, 2004 6:57 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Measuring Capacitance
    >
    >
    > Hi All,
    >
    > Can anyone direct me to an article or link that shows how to
    measure
    > capacitance using a Stamp? I just think it would be neat to try.
    I'm
    > familiar with the famous equation V(t)=Vo*e^(-t/tau). The problem
    is
    > is after charging the capacitor to Vo, you then have to disconnect
    > the source so the cap starts to discharge through R, and start an
    > RCTIME command until the V(t) hits logic swing. I can't think of
    how
    > to do these two things at precisely the same time. Thanks for any
    > help.
    >
    > -Dave
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    Subject
    > and Body of the message will be ignored.
    >
    >
    > Yahoo! Groups Links
    >
    > To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    > To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    > Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p...
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 02:37
    Your points are valid and RCTIME not intended for large capacitance
    values; for the reason you state: to keep the discharge timing in range
    your R value is way too low and you'll have problems. The whole point
    of the 220 is to protect the Stamp pin from a direct short to ground
    where R should be.

    What you may want to do is use your cap in a 555 circuit and measure the
    output with PULSIN.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: nuclearspin2000 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=AADbmbCc2-K0mDERH91aQLX7gzOgxOBXLdxdGiN2KtnpWDVwgRNgV_VexPOFQSagTgFXogFn15NXg27vMaFPJ6pJ]nuclearspin2000@y...[/url
    Sent: Tuesday, January 06, 2004 8:08 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: Measuring Capacitance


    Hi Jon,

    I read through that thoroughly. But there are fundamental problems
    with Parallax's description of the circuits used in the examples from
    the help file. As examples they present circuit A (preferred) and
    circuit B. Circuit A has two variations, the first one is:

    Vdd=+5
    |
    |
    C
    |
    |---220---I/O pin (7)
    R
    |
    |
    Gnd

    Example code from the help file:

    result VAR Word ' Word to hold result

    Main:
    HIGH 7 ' Discharge the cap
    PAUSE 1 ' for 1 ms
    RCTIME 7, 1, result ' Measure RC charge time
    DEBUG ? result ' Show value on screen
    END

    The problem is that the instruction HIGH 7 doesn't discharge the
    capacitor as long as the suggested 220 ohm resistance is there. The
    voltage at the lower side of the cap is whatever the voltage drop
    across R is when HIGH 7 is executed and it isn't +5V unless R is much
    greater than 220 and then it's still an approximation.

    Omitting the 220 ohm resistor fixes the above problem and I've done
    this in the past but I'm trying to measure a capacitor marked as
    1000uF. After working out about a page of calculations I get that R
    must be no more than about 43 ohms to keep the time constant small
    enough so that the value returned by RCTIME falls within the range
    for my BS2SX which is no more than 52.43mS based on 65535*(0.8uS),
    and that's also assuming a natural response RC circuit, maybe that's
    where I'm going wrong.

    Now if I omit the 220 ohm resistor and pull pin 7 high, the current
    flowing from the stamp pin is minimally 5V/43ohms=116mA and I fry my
    stamp pin.

    Maybe I'm making this too complicated but it doesn't seem like it has
    a simple solution to me. I guess I'll have to break out my circuits
    books.

    -Dave




    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > Take a look at the Stamp RCTIME command.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: nuclearspin2000 [noparse][[/noparse]mailto:nuclearspin2000@y...]
    > Sent: Tuesday, January 06, 2004 6:57 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Measuring Capacitance
    >
    >
    > Hi All,
    >
    > Can anyone direct me to an article or link that shows how to
    measure
    > capacitance using a Stamp? I just think it would be neat to try.
    I'm
    > familiar with the famous equation V(t)=Vo*e^(-t/tau). The problem
    is
    > is after charging the capacitor to Vo, you then have to disconnect
    > the source so the cap starts to discharge through R, and start an
    > RCTIME command until the V(t) hits logic swing. I can't think of
    how
    > to do these two things at precisely the same time. Thanks for any
    > help.
    >
    > -Dave
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    Subject
    > and Body of the message will be ignored.
    >
    >
    > Yahoo! Groups Links
    >
    > To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    > To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    > Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p...


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Yahoo! Groups Links

    To visit your group on the web, go to:
    http://groups.yahoo.com/group/basicstamps/

    To unsubscribe from this group, send an email to:
    basicstamps-unsubscribe@yahoogroups.com

    Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 03:27
    Actually I believe I've come to a workable solution, although it was
    anything but simple as I originally had suspected. A good value for R
    for this circuit was about 100 ohms which should be enough to limit
    the Stamp pin current to a safe level when discharging the capacitor,
    50mA safe? I used the equation for a first order step response of an
    RC circuit:

    Vc=Is*R+(Vo-Is*R)*e^(-t/RC)

    I replaced Is in my circuit with the Norton equivalent as dictated by
    the equation and then solved for C.

    A simple RCTIME command then gives the charge time of the capacitor
    from 0 to 1.4V (threshold). Since everything else is known I can then
    calculate C.

    By doing this I calculated a capacitance of 785uF for a 1000uF marked
    cap. That's a little more than then stated plus or minus 20% error
    but there's probably some round off error going on not to mention the
    resolution of the RCTIME command which could contribute as well.

    I like your idea of using the 555 timer, especially considering
    measuring larger caps would require lower resistances and result in
    higher currents through the Stamp pins using RCTIME. I'll try that
    next. Best regards,

    -Dave


    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > Your points are valid and RCTIME not intended for large capacitance
    > values; for the reason you state: to keep the discharge timing in
    range
    > your R value is way too low and you'll have problems. The whole
    point
    > of the 220 is to protect the Stamp pin from a direct short to ground
    > where R should be.
    >
    > What you may want to do is use your cap in a 555 circuit and
    measure the
    > output with PULSIN.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: nuclearspin2000 [noparse][[/noparse]mailto:nuclearspin2000@y...]
    > Sent: Tuesday, January 06, 2004 8:08 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Re: Measuring Capacitance
    >
    >
    > Hi Jon,
    >
    > I read through that thoroughly. But there are fundamental problems
    > with Parallax's description of the circuits used in the examples
    from
    > the help file. As examples they present circuit A (preferred) and
    > circuit B. Circuit A has two variations, the first one is:
    >
    > Vdd=+5
    >
    > |
    > |
    > C
    > |
    > |---220---I/O pin (7)
    > R
    > |
    > |
    > Gnd
    >
    > Example code from the help file:
    >
    > result VAR Word ' Word to hold result
    >
    > Main:
    > HIGH 7 ' Discharge the cap
    > PAUSE 1 ' for 1 ms
    > RCTIME 7, 1, result ' Measure RC charge time
    > DEBUG ? result ' Show value on screen
    > END
    >
    > The problem is that the instruction HIGH 7 doesn't discharge the
    > capacitor as long as the suggested 220 ohm resistance is there. The
    > voltage at the lower side of the cap is whatever the voltage drop
    > across R is when HIGH 7 is executed and it isn't +5V unless R is
    much
    > greater than 220 and then it's still an approximation.
    >
    > Omitting the 220 ohm resistor fixes the above problem and I've done
    > this in the past but I'm trying to measure a capacitor marked as
    > 1000uF. After working out about a page of calculations I get that R
    > must be no more than about 43 ohms to keep the time constant small
    > enough so that the value returned by RCTIME falls within the range
    > for my BS2SX which is no more than 52.43mS based on 65535*(0.8uS),
    > and that's also assuming a natural response RC circuit, maybe
    that's
    > where I'm going wrong.
    >
    > Now if I omit the 220 ohm resistor and pull pin 7 high, the current
    > flowing from the stamp pin is minimally 5V/43ohms=116mA and I fry
    my
    > stamp pin.
    >
    > Maybe I'm making this too complicated but it doesn't seem like it
    has
    > a simple solution to me. I guess I'll have to break out my circuits
    > books.
    >
    > -Dave
    >
    >
    >
    >
    > --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    > wrote:
    > > Take a look at the Stamp RCTIME command.
    > >
    > > -- Jon Williams
    > > -- Applications Engineer, Parallax
    > > -- Dallas Office
    > >
    > >
    > >
    Original Message
    > > From: nuclearspin2000 [noparse][[/noparse]mailto:nuclearspin2000@y...]
    > > Sent: Tuesday, January 06, 2004 6:57 PM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] Measuring Capacitance
    > >
    > >
    > > Hi All,
    > >
    > > Can anyone direct me to an article or link that shows how to
    > measure
    > > capacitance using a Stamp? I just think it would be neat to try.
    > I'm
    > > familiar with the famous equation V(t)=Vo*e^(-t/tau). The problem
    > is
    > > is after charging the capacitor to Vo, you then have to disconnect
    > > the source so the cap starts to discharge through R, and start an
    > > RCTIME command until the V(t) hits logic swing. I can't think of
    > how
    > > to do these two things at precisely the same time. Thanks for any
    > > help.
    > >
    > > -Dave
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > Subject
    > > and Body of the message will be ignored.
    > >
    > >
    > > Yahoo! Groups Links
    > >
    > > To visit your group on the web, go to:
    > > http://groups.yahoo.com/group/basicstamps/
    > >
    > > To unsubscribe from this group, send an email to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > >
    > > Your use of Yahoo! Groups is subject to:
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
    > > This message has been scanned by WebShield. Please report SPAM to
    > > abuse@p...
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    Subject
    > and Body of the message will be ignored.
    >
    >
    > Yahoo! Groups Links
    >
    > To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    > To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    > Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p...
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 09:37
    From: "nuclearspin2000" <nuclearspin2000@y...>

    > [noparse][[/noparse]...] A good value for R for this circuit was about 100 ohms
    > which should be enough to limit the Stamp pin current to a
    > safe level when discharging the capacitor, 50mA safe?

    No, it's not, Dave. You need to limit it to an absolute max of 25ma when
    sinking, and 20ma when sourcing. 220 ohms is the smallest recommended size
    of resistor.

    Gary
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 16:25
    I was reading that in the Stamp FAQ. I guess I got away with it
    because the line of code to discharge the cap takes place in just a
    couple of mS but I'll have to use more care in the future and rethink
    the design. Thanks for the warning.

    -Dave

    --- In basicstamps@yahoogroups.com, "Gary W. Sims" <simsgw@c...>
    wrote:
    > From: "nuclearspin2000" <nuclearspin2000@y...>
    >
    > > [noparse][[/noparse]...] A good value for R for this circuit was about 100 ohms
    > > which should be enough to limit the Stamp pin current to a
    > > safe level when discharging the capacitor, 50mA safe?
    >
    > No, it's not, Dave. You need to limit it to an absolute max of 25ma
    when
    > sinking, and 20ma when sourcing. 220 ohms is the smallest
    recommended size
    > of resistor.
    >
    > Gary
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-07 18:13
    The Stamp outputs are remarkably resilient and seem to be able to
    take a lot of abuse above the ratings. They will usually survive a
    direct short circuit. But, each instance may well shorten the life
    of the chip.

    In your calculations, remember that the SX stamp output resistance is
    around 60 ohms, both sinking and sourcing, and it will not output a
    full 5 volts under load.

    My approach to a big capacitor would be to make a long-period
    "RCtime" command out of a loop, and use a large resistor in the
    standard circuit. It would need a little calibration. Use standard
    RCTIME for small caps.

    ;
    o
    220---I/O pin (7)
    | |
    R C
    | |
    Gnd Gnd

    e.g. R=10k C=1000uF RC=10 seconds

    DO
    HIGH 7 ' charge C
    PAUSE 2000 ' RC=0.22 second
    ticks=0
    INPUT 7 ' C starts discharging thru R
    DO
    tick=tick+1
    PAUSE 9 ' increments of ~10 milliseconds
    LOOP WHILE IN7
    DEBUG ? ticks
    LOOP

    -- regards,
    Tracy Allen
    http://www.emesystems.com/BS2rct.htm



    >I was reading that in the Stamp FAQ. I guess I got away with it
    >because the line of code to discharge the cap takes place in just a
    >couple of mS but I'll have to use more care in the future and rethink
    >the design. Thanks for the warning.
    >
    >-Dave
    >
    >--- In basicstamps@yahoogroups.com, "Gary W. Sims" <simsgw@c...>
    >wrote:
    >> From: "nuclearspin2000" <nuclearspin2000@y...>
    >>
    >> > [noparse][[/noparse]...] A good value for R for this circuit was about 100 ohms
    >> > which should be enough to limit the Stamp pin current to a
    >> > safe level when discharging the capacitor, 50mA safe?
    >>
    >> No, it's not, Dave. You need to limit it to an absolute max of 25ma
    >when
    >> sinking, and 20ma when sourcing. 220 ohms is the smallest
    >recommended size
    >> of resistor.
    >>
    >> Gary
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >
    >Yahoo! Groups Links
    >
    >To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    >To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    >Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
Sign In or Register to comment.