Shop OBEX P1 Docs P2 Docs Learn Events
What's A Microcontroller? — Parallax Forums

What's A Microcontroller?

Keith HiltonKeith Hilton Posts: 150
edited 2007-02-05 19:43 in Learn with BlocklyProp
roll.gifIn the Parallax book, "What's A Microcontroller?", on pages 277 and 278 there is code for a Photo Controlled Digital Pot.· If you use the Subroutine Set_Ud_Pin, an error comes up when you run the program.· The error message says, "Error Expected a Label". Upon further attempts to get the program to work I noticed only a LOW for the UdPin. To move the resistance of the pot the other way, you need a HIGH for the UdPin. There is no HIGH for the UdPin in the subroutine code.· I tried to put one in and still could not get past error messages.· I am certain there is a mistake in the code. Can someone write out the correct main routine, and correct·subroutines for me.· I want the digital pot to track the photo resistor.· Help!··
Next question, relating to this same program, and same circuit, of page 277 and 278 in "What's A Microcontroller?":
Instead of using a photo resistor, what if you replaced the photo resistor with a photo transistor?· This relates back to page 145 in the book "What's A Microcontroller?".· Seems to me the Polled RC-Time would change as the photo transistor changed, because the amount of current through the photo transistor would act upon a capacitor the same way different currents would be acted upon by different resistances. Resistances reduce or increse the current, and so does a photo transistor.· Is my thinking screwed up??????????· Help?· smhair.gif

[noparse][[/noparse]Subject Added by Moderator]

Post Edited By Moderator (Chris Savage (Parallax)) : 2/8/2007 5:01:43 PM GMT

Comments

  • PARPAR Posts: 285
    edited 2007-02-02 03:53
    Keith Hilton said...
    roll.gifIn the Parallax book, "What's A Microcontroller?", on pages 277 and 278 there is code for a Photo Controlled Digital Pot.· If you use the Subroutine Set_Ud_Pin, an error comes up when you run the program.· The error message says, "Error Expected a Label". Upon further attempts to get the program to work I noticed only a LOW for the UdPin. To move the resistance of the pot the other way, you need a HIGH for the UdPin. There is no HIGH for the UdPin in the subroutine code.· I tried to put one in and still could not get past error messages.· I am certain there is a mistake in the code. Can someone write out the correct main routine, and correct·subroutines for me.· I want the digital pot to track the photo resistor.· Help!·· ....
    I didn't set up the hardware to test the book's code, and didn't examine the book's code for other possible problems, so ...
    Try adding the highlighted statement to your code:
    Set_Ud_Pin:
    IF newTapSetting > oldTapSetting THEN
    HIGH UdPin

    If that alone doesn't solve the problem, then let us know.

    PAR

  • AImanAIman Posts: 531
    edited 2007-02-02 04:21
    Parallax does make mistakes on occasion and the corrections are posted. WAM has had a few and you can check http://www.parallax.com/detail.asp?product_id=28123

    Then·open What's a Microcontroller? Errata v1.3 (.pdf)
    It contains corrections for WAM.
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-02 16:03
    Thanks for the help, I will try running the program and let you know how it works. I am wanting to use a infrared photo transistor instead of the photo resistor. I hope I can make it work with the RC-Time with the capacitor. Thanks again!
  • edited 2007-02-02 18:59
    Hi Keith,

    Are we both working from What's a Microcontroller v2.2?· I see a terminal controlled potentiometer on pages 277-278, but not a "photo controlled digital pot".

    If it's the terminal controlled digital pot, the code works as written for me.· Attached is a test file (TerminalControlledDigitalPot.bs2) you can try.

    Regards, Andy

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

    Education Department
    Parallax, Inc.
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-03 05:55
    Thanks for replying Andy. I see you wrote the book,"What's a Microcontroller", it is a great book Andy. Yes, I have the version 2.2. Don't really understand what you mean by the terms--"Terminal controlled potentiometer"? I thought all pots were controlled by their terminals? In the picture of the circuit on page 277, a photo resistor, sometimes called a Cds cell, is in parallel with a .01uf capacitor, and these hook to pin 2 of the Basic Stamp 2, through a 220 ohm resistor. Information from pin 2 on the Stamp controlls the terminals of the pot. At least that is how I see it. Type up the code as written on page 277 and 278, and hit "run". The program will not complete the run as it stops with an error message. The Basic Stamp 2 won't controll the pot terminals at all if the program won't run because of an error message. Havn't had time to try the two fixes for the program you guys have suggested. I should get to try them tomorrow. Once I get this program working, and the circuit working with the Basic Stamp 2, I want to replace the ---photo resistor/Cds cell---with a infrared photo transistor. Then shine a infrared LED on the infrared photo transistor. I personally thing a photo transistor can replace the photo resistor in this particular circuit. Both the photo resistor and photo transistor alter current, and that alters the .01 uf capacitor, so the RC-Time should work. Is my thinking screwed up Andy? Thanks for your help!
  • PARPAR Posts: 285
    edited 2007-02-03 07:36
    Keith Hilton said...
    ...·Type up the code as written on page 277 and 278, and hit "run". The program will not complete the run as it stops with an error message. The Basic Stamp 2 won't controll the pot terminals at all if the program won't run because of an error message....
    Please post the exact code you typed into the Stamp editor and attempted to "run".
    (You apparently copied (typed) the code provided on pp 277-278, rather than cutting and pasting that exact code from the book.)

    Be sure to post the exact code which generates the error message.

    PAR
  • Keith HiltonKeith Hilton Posts: 150
    edited 2007-02-05 17:07
    I got it working. I went to the Parallax posted corrections AIman posted, and used the corrected program. Since this is a learning experience, I would like someone to explain to me why these two things were in the program? "oldTapSetting = oldTapSetting +1" and
    "oldTapSetting = oldTapSetting -1". Andy, thanks for the program you posted. Andy, the book you wrote may not be the same way as you wrote it. The printer made some errors. Andy, Parallax has posted the errors as AIman posted. I also still have something on my mind. I know for RC-time, a resistor and capacitor are used. Why couldn't a photo-transistor replace the resistor? Where you could vary the output of the photo-transistor, thus vary the current. Seems to me a photo-transistor would cause a change in how a capacitor charged and discharged the same way a variable resistor does?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-05 19:10
    Keith -

    As regards the use of a photo-transistor, what you may be thinking of is a photo-resistor, or LDR (light-dependent resistor) for use in the R-C circuit, and for use with the PBASIC RCTIME instruction. With a photo-transistor, only the current varies, which isn't going to help you in an R-C circuit.

    An R-C requires a resistor (fixed or variable) and a capacitor. A properly consructed R-C circuit will provide a finite and predictable output, based on the values of the resistor and capacitor, as predicted by the time-constant formula.

    Just remember the precision needed (by your own critera) will be determined by the precision of the resistor and capacitor used. If one used a standard potentiometer, in lieu of a fixed resistor, then one might have a degree of variability. If (IF !) one could return a potentiometer shaft in the exact same position, after moving it to a different position, you might have some predicatabilty, repeatability and thus a meaningful circuit and a reasonably predictable time-constant. With a photo-resistor (or other variable resistance device), one would need to determine empirically the meaning of the results, and repeatability, I would suspect, could be a real problem.

    In a GO - NO-GO situation, these problems wouldn't exist. In a measurement environment they will exist.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • edited 2007-02-05 19:43
    Keith,

    Sorry about that. I thought I was working from the original document, but apparently not. My page 277 had a totally different program, so I was talking about the Debug Terminal controlled digital potentiometer example with the program that starts on printed page 273.

    Fortunately, AIman had already stepped in and posted the correct answer. Thanks AIman!

    Regarding the oldTapSetting = OltTapSetting + 1 and oldTapSetting = oldTapSetting - 1 question, take a look at the FOR...NEXT loop on page 275. (We should be "on the same page" now since I'm working from a printed copy!) The FOR...NEXT loop delivers one more pulse than we want. At a glance, we might expect FOR counter = 10 to 20...NEXT to deliver 10 pulses, but it would actually deliver 11 pulses. Same problem with FOR counter = oldTapSetting to newTapSetting, it delivers one more pulse than we want. By either adding 1 to, or subtracting 1 from, the value of the oldTapSetting variable before starting the FOR...NEXT loop, the number of pulses that get delivered is correct instead of being one too many.

    Regards, Andy

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

    Education Department
    Parallax, Inc.
Sign In or Register to comment.