Shop OBEX P1 Docs P2 Docs Learn Events
Some suggested resolution/control improvements for Andy Lindsay — Parallax Forums

Some suggested resolution/control improvements for Andy Lindsay

Keith HiltonKeith Hilton Posts: 150
edited 2007-02-26 17:22 in Learn with BlocklyProp
tongue.gif·I have been working with Andy Lindsay's book, "What's A Microcontroller? I got involved with doing the project on page 276 and 277, and 278 of "What's A Microcontroller?"· Discovered the code was printed wrong, and Parallax issued a correction. I got the code and circuit working.· Even though it worked,·I could not get great resolution/control, from the photo-resistor controlling the brightness of the LED.· I wanted to find out if I could get better control and resolution, so I went back to various Parallax instruction books and read about RC Time.· The capacitor, resistor hookup to pin 2, on page 277 of the book "What's A Microcontroller?, was not listed as a suitable RCTime circuit in the "Basic Stamp Manual Version 2.0, page 256.· On page 256 there are two circuits, A and B.· Circuit arrangement A has a span of 5 volts to 1.5 volts, or 3.5 volts.· Circuit arrangement B has a span of 0 volts to 1.5 volts, or 1.5 volts.·· Circuit A has a much greater span, and this seems like it would help with resolution and control.· Neither Circuit A or B in the "Basic Stamp Manual Version 2.0, page 256, is like the circuit Andy Lindsay used on page 277 of the book, "What's A Microcontroller?" Fact is none of the information I read for RC Time uses the circuit arrangement to pin 2 on page 277 of the book,"What's A Microcontroller?"· Andy what is the voltage span of the circuit RC Time circuit to pin 2 you used on page 277, in your book "What's A Microcontroller?"· If you look on page 141 of Andy Lindsay's book,"Basic Analog and Digital", the diagram to pin 15 is the same as the circuit A on page 256 of the "Basic Stamp Manual Version 2.0."· Seems to me there would be a lot more voltage span, thus resolution/control using the circuit A in the Basic Stamp Manual Version 2.0", page 256.· Maybe Andy could tell us why he didn't use the circuit that seems to have more resolution for RC Time?· The other thing that seems obvious to me to increase control/resolution for RC time, is to increase the capacitor value.· It has been my experience working with photo resistors that they can be difficult to control, and ambient light can play heck with the resistance values.· If we were to replace the variable resistor in circuit A, on page 256, of the "Basic Stamp Manual Version 2.0,· with a infrared photo transistor, we could control it like a variable resistor.· That is by shinging varing amounts of infrared light on it from a infrared LED.· Ambient light does not bother infrared.· I have had much better luck using infrared LEDs and infrared photo transistors, than photo resistors.· Andy let me know if I am thinking straight?· Respectfully· Keith Hiltonidea.gif

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-19 15:24
    It would be much easier to read your input if you gave us a paragraph break from time to time.
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-20 19:02
    Allanland5, I agree with your paragraph idea. Got so involved with trying to make the cirucuit work better, I forgot about paragraph breaks.
    I am just wondering why Andy used that particular resistor/capacitor arrangement for RC time? Seems to me there is a better arrangement of parts to get more voltage space for the RC Time command. Like the suggested arrangement in the "Basic Stamp Manual 2.0 version". I am especially curious why Andy used that particular hookup arrangement of the resistor and capacitor in RC TIME. Would also like to hear of anyone's experience in replacing a photo resistor, with a infrared photo transistor for RC TIME. I know I can get the infrared photo transistor to act like the photo resistor.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-20 20:39
    If you click that little 'pencil' icon in the top right, that opens your message in an 'edit' window. You can then insert line-feeds to your heart's content.

    Just a thought.
  • edited 2007-02-20 23:53
    Hi Keith,
    ·
    Keith·said...
    Even though it worked,·I could not get great resolution/control, from the photo-resistor controlling the brightness of the LED.· I wanted to find out if I could get better control and resolution, so I went back to various Parallax instruction books and read about RC Time.

    ·
    Your RCTIME measurement from What's a Microcontroller, Chapter 5, Activity #3 should have returned a value from 1 to 650 (ish) that corresponds to your potentiometer’s position (the resistance between the A and W terminals).· That should be ample resolution for LED brightness control.· Is that what you got from the Debug Terminal?··If yes, there may be a problem with your LED brightness code and/or circuit.· If no, there may be an error in your RC circuit and/or code.· In either case, post your code and circuit so we can take a look.
    ·
    I wanted to find out if I could get better control and resolution, so I went back to various Parallax instruction books and read about RC Time.· The capacitor, resistor hookup to pin 2, on page 277 of the book "What's A Microcontroller?, was not listed as a suitable RCTime circuit in the "Basic Stamp Manual Version 2.0, page 256.· On page 256 there are two circuits, A and B.· Circuit arrangement A has a span of 5 volts to 1.5 volts, or 3.5 volts.· Circuit arrangement B has a span of 0 volts to 1.5 volts, or 1.5 volts.·· Circuit A has a much greater span, and this seems like it would help with resolution and control.· Neither Circuit A or B in the "Basic Stamp Manual Version 2.0, page 256, is like the circuit Andy Lindsay used on page 277 of the book, "What's A Microcontroller?" Fact is none of the information I read for RC Time uses the circuit arrangement to pin 2 on page 277 of the book,"What's A Microcontroller?"· Andy what is the voltage span of the circuit RC Time circuit to pin 2 you used on page 277, in your book "What's A Microcontroller?"·
    ·
    The span of the RC circuit in What's a Microcontroller, Chapter 5, Activity #3 is the same as Circuit A on the page you are referencing in the 2.0 version of the BASIC Stamp Manual.· The circuit might look more like circuit B in the BASIC Stamp manual, but it's not the same circuit.· The circuit in What's a Microcontroller behaves identically to circuit A.· We are migrating Stamps in Class textbook revisions to the RC circuit in What's a Microcontroller because it matches a circuit that is commonly discussed in educational texts.·
    ·
    Some folks might want to point out that the BASIC Stamp Manual circuit applies the same voltage regulator output noise to both the RC circuit and the BASIC Stamp's I/O pin threshold.· Well, maybe it does and maybe it doesn't.· Since the RC nature of the circuit incorporates some delay,·I'm not so sure·that's a valid argument.· I haven't tested it, but perhaps somebody who reads this post has and will chime in.··Also, both the BASIC Stamp and Board of Education use pretty nice voltage regulators, so the noise we are talking about is·negligible, especially with regards to measurements for controlling LED brightness.
    ·
    If you look on page 141 of Andy Lindsay's book,"Basic Analog and Digital", the diagram to pin 15 is the same as the circuit A on page 256 of the "Basic Stamp Manual Version 2.0."· Seems to me there would be a lot more voltage span, thus resolution/control using the circuit A in the Basic Stamp Manual Version 2.0", page 256.· Maybe Andy could tell us why he didn't use the circuit that seems to have more resolution for RC Time?···
    ·
    Nope, same voltage span.· The HIGH signal to the I/O pin has the same effect on both circuits.· You can verify this by building/testing both circuits·and displaying their measurements in the Debug Terminal.· They should behave the same.·
    ·
    The other thing that seems obvious to me to increase control/resolution for RC time, is to increase the capacitor value.·
    ·
    After trying the Your Turn sections on What’s a Microcontroller pages 152 and 192, I would hope so.
    ·
    It has been my experience working with photo resistors that they can be difficult to control, and ambient light can play heck with the resistance values.· If we were to replace the variable resistor in circuit A, on page 256, of the "Basic Stamp Manual Version 2.0,· with a infrared photo transistor, we could control it like a variable resistor.· That is by shinging varing amounts of infrared light on it from a infrared LED.· Ambient light does not bother infrared.· I have had much better luck using infrared LEDs and infrared photo transistors, than photo resistors.· Andy let me know if I am thinking straight?
    ·
    Well, in the context of your post critiquing What’s a Microcontroller RC decay measurements, the thinking is not “straight”.··The photoresistor in What's a Microcontroller is being used to measure ambient light.· So substituting a phototransistor and IR LED to eliminate the effects of ambient light would defeat the purpose of the example photoresistor circuit.·
    ·
    Now, if your stated goal is to instead measure some property of an up-close surface, the thinking would be “straight”.· It is true that swamping the ambient light source with a local light source will work well when you want to reduce ambient light's interference on close-up surface measurements.· It is also true that an IR LED and phototransistor can be used in this fashion in an RC circuit.··Parallax' QTI sensor uses this circuit and principle.· While it was designed for detecting the white perimeter around a black SumoBot ring, but it has lots of other uses.· Here is a link to the QTI page:
    ·
    http://www.parallax.com/detail.asp?product_id=555-27401·
    ·
    One final note on ambient light measurements: A more precise ambient light measurement technique that uses photodiodes is introduced in Tracy Allen's Applied Sensors text.
    ·
    Regards, Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 2/21/2007 12:32:46 AM GMT
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-21 17:57
    Vdd----Capacitor----I----photo resistor---Ground·· ·Pin 2 Basic Stamp--220 Ohm
    I
    capacitor
    Ground
    ··························· ^······················································································· ^
    ······················ 220 Ohm·········································································· Photo resistor
    ·························· ^························································································· ^
    ························· Pin 2 Basic Stamp·································································· Ground
    Andy, I tried to draw a diagram of the two RC TIME circuits you say give the same result. Hard for me to see how they give the same result, but who am I to argue with the guy that wrote the book. In the diagrams, the I
    and dotted lines point
    ································································································································^····································· to circuit connections.
    I smiled when you said I was critiquing What's a Microcontroller. Andy, I'm just a dumb hillbilly from the Ozark Mountains, I am not smart enough to critique anything. Thanks for letting me know the infrared arrangement will work. Yes, I am trying to measure the property of an up close surface. The surface being a film that goes from light to dark, in other words a gradient. I plan on ordering the Parallax part you mentioned, and also the Parallax sensor book. You mentioned the use of photodiodes. Don't photodiodes tend to come on all at once? I think of them more as a switch, instead of something that can come on gradually like a photo transistor?tongue.gif

    Post Edited (Keith Hilton) : 2/21/2007 6:06:32 PM GMT
  • edited 2007-02-21 23:08
    Make sure to straighten your potentiometer’s pins with a needle nose pliers if they are kinked and make sure they are well seated in their sockets.· If the pins weren’t making good contact with the sockets, it could account for your apparently insufficient measurements.

    Figure 1 shows the two circuits we've been talking about.· The one on the left is from What's a Microcontroller; the one on the right is from the BASIC Stamp Manual.· Given a variable resistor (R) and fixed capacitor (C), the RCTIME command can be used to measure a voltage decay time that varies with R.· This works well for measuring potentiometer and photoresistor values.· For capacitive sensors, R can be fixed, and C can be varied.· In that case, the voltage decay time will vary with C.· Other variations use current dependent devices such as photodiodes and phototransistors to charge or discharge a capacitor, and again the decay (or rise) time will vary with the amount of current flowing into/out of the capacitor.· Both circuits in Figure 1 are designed to measure voltage decay time.·

    Figure 1
    attachment.php?attachmentid=45567

    Before measuring decay time, the circuit has to be "primed" for decay.· This typically involves setting the I/O pin to an output value for a while to either charge or discharge the capacitor (which doesn’t take very long for either of these circuits).· After that, the RCTIME command causes the I/O pin to become an input, shown in the Figure 2 below as the switch going from 5 V to input buffer.· The input buffer has no effect on the circuit.· All it does is monitor whether the voltage applied to the I/O pin is above or below 1.4 V.·

    While the circuit on the left is connected to 5 V (HIGH ioPin), the capacitor charges up to almost 5 V.· PAUSE 1 gives the capacitor plenty of time to charge.· A command like RCTIME ioPin, 1, time switches the I/O pin from output-high to input buffer state and starts tracking time.· As a buffered input, the I/O pin no longer has any effect on the capacitor's voltage.· So the RCTIME command waits for the voltage to drop below 1.4 V while the charge the capacitor built up drains through the variable resistor, sort of like a small battery would.· As the capacitor looses its charge, the voltage across its terminals decays.· When the voltage drops to 1.4 V, the RCTIME command saves its time measurement in a variable.·

    Figure 2
    attachment.php?attachmentid=45568

    How long that voltage drop takes depends on how large (long discharge time) or small (short discharge time) the value of R is.· So the variable with the decay time measurement stores a value that corresponds to how much R resists the flow of electrons.· If R is large, the capacitor discharges slowly and the time value is large.· If R is small, the capacitor will drain quickly and the time measurement will be small.·

    While the RC decay time is the same for the circuit on the right of Figure 2, it works very differently.· When the I/O pin is set high, the voltage at the capacitor’s lower plate is pushed toward 5 V.· This discharges the capacitor instead of charging it.· PAUSE 1 gives the capacitor time to discharge to almost 0 V.· That means the voltage at the capacitor’s lower plate is at almost 5 V, just like the circuit on the left.· When the RCTIME command is executed and the right circuit’s I/O pin becomes an input, the voltage on the lower plate of the capacitor drops as the capacitor charges.· The value of R slows the rate the capacitor on the right charges in the same way it slows the discharge rate of the capacitor in the circuit on the left.··

    In either case, the timing is the same if the values of R and C are the same.· Figure 3 shows how it works.· The Vpin and Vcap voltage graphs correspond to the measurement probe points shown in the Figure 2 circuits.· Notice how Vpin jumps right from 0 to 5 V, but Vcap takes a little while to catch up as the capacitor charges (or discharges if it's the circuit on the right).· The Vcap voltage gets really close to 5 V, but not quite there.· The value it reaches is labeled Vi, and that value is determined by the ratio of the 220 ohm resistor and R (discussed next).· The charge time is typically pretty small compared to 1 ms.· When the RCTIME command executes, the circle in the Vpin voltage graph indicates that the I/O pin changed from output-high to input.· From that point onward, Vcap = Vpin.· The Vcap voltage decays down to 1.4 V in an amount of time determined by the size of R X C.· Since C is fixed in this example, R dicates the amount of time it takes the voltage to decay from Vi to Vf.·

    Figure 3
    attachment.php?attachmentid=45569

    Here are the equations for Vi and Vf.· The reason that the decay time isn’t directly proportional to R is because of the 220 ohm resistor.· If it weren’t there, Vi would·approach 5 V, and the decay time would be directly proportional to R.· By using large variable resistors, the value of 220 becomes negligible.· On the other hand, when the value of R approaches 220 ohms, the result of Vi is affected less by R and more by 220.· For example, if R happens to be also be 220 ohms, Vi will only be 2.5 V.· So the decay measurement becomes smaller for two reasons, first because R is small, and second because Vi is closer to Vf and so there's less volts to decay.· Large R values are desirable for this circuit, so that it swamps the 220 ohm resistor.· BTW, that 220 ohm resistor has to be there to protect the I/O pin from sourcing too much current as it charges the capacitor.

    attachment.php?attachmentid=45570
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 2/22/2007 12:50:23 AM GMT
    528 x 182 - 18K
    528 x 180 - 24K
    528 x 300 - 61K
    357 x 51 - 8K
  • Aristides AlvarezAristides Alvarez Posts: 486
    edited 2007-02-21 23:11
    Hello Keith,

    If the different setups are confusing you, I’d recommend you to stick to the version from WAM. Every time we revise our Educational material we change to this circuit.

    In the version from WAM (which looks similar to RC circuits from most Educational resources), you charge the capacitor with a HIGH (5 Volts), then disconnect the BASIC Stamp pin and let it discharge until the threshold drops below about 1.4 Volts. If you are following the book and you look at the circuit, everything should be very clear. This circuit is very stable and easy to follow and understand.

    On the contrary, the original circuit from the BASIC Stamp Manual is not as easy to understand and it usually generates some confusion (as it happened with you). In the BS Manual circuit, you “discharge” the capacitor with a HIGH (yes, you’re discharging it while applying 5 Volts) and then you disconnect the BASIC Stamp pin, letting it “charge by itself.” In that process the pin goes down from 5 Volt towards ground.

    Both circuits have the same voltage span. I encourage you to try both circuits with the same components and post your results. They should be around the same values (you may use a potentiometer instead of an LDR to make sure you can duplicate the values without depending on light intensity).

    Once you verify that both circuits generate the same results, try to explain how they work to someone else. Talk to a neighbor, girlfriend/wife or anyone else, and try to explain them how these circuits work. You will be able to verify quickly that the circuit from WAM is easy to explain and everybody will understand how it works and they will be able to customize it for other applications. In the case of the other circuit, you will find that your audience will find hard to follow you when you get to the part about “discharging the capacitor with 5 Volts”….

    I see that Andy just did a reply with illustrations, so maybe everything was clarified by the time you got to this message.

    Regards,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aristides Alvarez
    Education Manager
    Parallax, Inc.
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-26 17:22
    tongue.gif·Thanks for all your help.· I got everything working.· I even replaced the photo resistor with the infrared photo transistor and got it working.· I checked on that sensor Andy suggested and it was a infrared LED and infrared photo transistor used in RC TIME.· After I saw the sensor circuit all my suspicions were confirmed.· Thanks again for all your help.tongue.gif
Sign In or Register to comment.