Shop OBEX P1 Docs P2 Docs Learn Events
RCTIME - Urgent Help Needed — Parallax Forums

RCTIME - Urgent Help Needed

fragefrage Posts: 2
edited 2006-02-18 20:05 in BASIC Stamp
Hey, I' ve constructed a colour sensor which uses a differential op-amp to amplify the output·signal·and want to convert the analogue voltage to a digital valve using RCTIME. The output from the debug terminal was fixed at 18, and would not change with varying voltage.

Any help would be greatly appreciated

This is the code that i have been using:

' {$STAMP BS2sx}
' {$PBASIC 2.5}

'Prog 4G: Monitoring RCTime
Pot VAR Word· 'Variable to hold results

rc PIN 0
Main:
··· LOW rc··· 'Discharge network
··· PAUSE 1··· 'Time to fully discharge
··· RCTIME rc,0,Pot· 'Read charge time and store in Pot
··· DEBUG ? Pot··· 'Display value of Pot
··· PAUSE 500··· 'Short pause
GOTO Main··· 'Jump back to beginning

And this is the circuit setup:

[size=-1] 681 kohm 470 ohm
Vx ----/\/\/\---o
/\/\/\----P0 to stamp
unknown |+
voltage ===== 0.01 uF Cap
|
Vss[/size]

Post Edited (frage) : 2/17/2006 4:19:33 PM GMT

Comments

  • Terry KingTerry King Posts: 12
    edited 2006-02-17 21:28
    Frage, I'm sorry but I don't think this will work...

    What RCTime does is wait until the capacitor is DIScharged below the voltage where the microcontroller
    senses a Zero instead of One - (about 1.4 volts) . So the MOST you could do is sense something about the
    voltage you are sourcing between 0 volts (Time = R*C) and 1.3999 volts (Where you would take a VERY long time to
    dischage the capacitor.

    What is the range of voltage your device puts out??

    You probably need to add an Analog-to-digital converter...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards, Terry King ...On The Mediterranean in Carthage, Tunisia, North Africa
    American Cooperative School of Tunis
    terry@terryking.us
  • KC8DKTKC8DKT Posts: 76
    edited 2006-02-17 21:33
    One thing you should try is RCT with a HIGH 1. With 0 LOW it only have 0v to 1.3v to scall. High has 1.3v to 5v. I do not have the info on this PC but this is in the HELP under RCT I beleave.
  • fragefrage Posts: 2
    edited 2006-02-18 02:01
    Hey,

    My sensor output is approximately 2 - 3 volts but can be amplifed to whatever is required.

    I understand that rctime measures the time for the I/O pin to change state, as you said to go from 5v to 1.4 volts or from 0v to 1.3 as the capacitor is charged or discharged.

    my question is if RC stays constant should n't rctime be affected by a changing voltage as this will also effect the charge time

    Regards,
    James
  • Terry KingTerry King Posts: 12
    edited 2006-02-18 15:49
    Look at the book or Help explanation of RCTIME.

    One possibility, IF your output values can be kept in the region of 2 to 3 (or preferably 3 to 4 or 3 to 5) then you
    may be able to use the "Circuit B" version. The Help file says:

    "With Circuit B, the voltage will start at 0V and rise to 1.4V (spanning only 1.4V) before RCTIME stops. For the same combination of R and C, Circuits A will yield a higher count, and therefore more resolution than Circuit B. "

    If you connect your Voltage to be measured thru a suitable resistance to the I/O Pin, (Your source takes the place of "Vdd" in the diagram for option "B" in the Help), and use RCTIME in that mode where it measures CHARGE (up toward +) time, you may get useable data. You will have to calibrate the system for the values that mean something to you.

    Give it a try??

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards, Terry King ...On The Mediterranean in Carthage, Tunisia, North Africa
    American Cooperative School of Tunis
    terry@terryking.us
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-18 17:17
    Typically people use an in-expensive 8-pin ADC0832 A to D converter for this purpose.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-02-18 18:11
    With that circuit and component values the RCTIME value from a BS2 should be around 2200 (4400 microseconds) when the input of that circuit is 3 volts. And around 3000 (6000 microseconds) when the input is at 2.5 volts. That is based on the chart at this URL:
    emesystems.com/BS2rct.htm#B_voltage
    It should work. It would be better if you can amplify the signal more, to a higher voltage range above the 1.4 volt threshold, simply because the RCTIME formula then will be simpler and the result will be more stable. I don't see anything wrong with your code. Recheck the wiring. What happens if you connect the top of the 681kohm resistor to +5 volts Vdd? On a BS2 the RCTIME reading should be around 1200 (2400 microseconds).

    Is this sensor a photodiode? If so, you can dispense with the op amp transconductance (I->V) amplifier and use the photodiode in reverse bias mode directly in the RCTIME circuit. The charging of the capacitor is a then a linear function of current, not exponential, so it becomes easier to calculate exact results. And the circuit is simpler.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-18 20:05
    · Here's a circuit that I worked out.· Don't know if anybody has done anything similar.· I'm using our friend the transistor as a voltage-controlled "variable resistor" (imagine that.)· It's a mock ADC, for people who want "counts".
    · This is basically·the·state=1 circuit.· Test program incl. (no extra charge.)
    · Go ahead and experiment with different values of C and the Emitter resistor.

    Post Edited (PJ Allen) : 2/19/2006 4:14:08 PM GMT
    718 x 420 - 64K
Sign In or Register to comment.