Shop OBEX P1 Docs P2 Docs Learn Events
RcTime Voltage Measurement — Parallax Forums

RcTime Voltage Measurement

alnajjar1alnajjar1 Posts: 110
edited 2011-02-03 09:40 in BASIC Stamp
I am using a BS2 to measure DC voltage. My reference was an article EME System (http://www.emesystems.com/BS2rct.htm) to design the circuit. I had to amplify incoming voltage from 0-21 mV to 0 - 3.7V using an LM359 Op Amp, and this works perfectly. The circuit diagram and code are attached.

When I read the RC value, I am getting wild numbers that eventually stabilize to 1 and then nothing happens. I tried changing the delay time in the loop but that didn't do anything.

Can anyone spot what I am doing wrongly? The amplification works and the RcTime circuit and code are very simple. Not sure what is going on! Thanks in advance for any help..

Al
788 x 554 - 44K

Comments

  • bsnutbsnut Posts: 521
    edited 2011-02-02 02:02
    The problem is with your code.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' RCtime stuff
    Sig     PIN             14
    rcSig   VAR             Word
    
    LOW Sig
    
    again:
      RCTIME Sig, 0, rcSig ' measure RC discharge time
      LOW Sig
      DEBUG CLS, HOME, DEC ? rcSig ' display result
      PAUSE 500
    GOTO again
    
    This is the RCTIME code that you should be trying and can you see the differences in Basic Stamp Editor help file and your code above.
    ' RCTIME1.BS2
    ' This program shows the standard use of the RCTIME instruction measuring
    ' an RC charge/discharge time. Use the circuit in the RCTIME description
    ' (in the manual) with R = 10K pot and C = 0.1 uF. Connect the circuit to
    ' pin 7 and run the program.  Adjust the pot and watch the value shown on
    ' the Debug screen change.
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    RC              PIN     7
    
    result          VAR     Word
    
    
    Main:
      DO
        HIGH RC                             ' charge the cap
        PAUSE 1                             '   for 1 ms
        RCTIME RC, 1, result                ' measure RC discharge time
        DEBUG HOME, DEC result              ' display value
        PAUSE 50
      LOOP
      END
    
    
    Just remember that the RCTIME command isn't the only way for Stamp to measure voltage and they are.
    1) Analog Digital Converters(ADC) which uses SHIFTIN command (From Stamp Works PDF)
    2) Using a 555 Timer IC which uses PULSIN command (From Stamp Works PDF)
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-02-02 18:25
    Thanks, I switched to ADC0831 and I am getting great results.

    Al
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-02-03 09:40
    I just want to follow up on your RCtime circuit. In your diagram you show a 680Ω resistor with a 0.1µF capacitor to determine the time. That should really be a value around 1000 times higher, 680 kΩ, which slows down the response to a point where the RCTIME command can measure it. Even so, that circuit as is not a good option for measuring voltages that go from zero up to say 4V. That is because there is a cusp at around 1.4V as the input passes through the Stamp threshold. The math for that is horrendous. That same page at EME Systems has a different circuit using an op-amp and a transistor to generate a current proportional to a small input voltage, suitable for use with RCTIME.

    Still, The ADC0831 is the best way to go, and you have success with that. Stick with it!
Sign In or Register to comment.