What's A Microcontroller?
Keith Hilton
Posts: 150
In 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?·
[noparse][[/noparse]Subject Added by Moderator]
Post Edited By Moderator (Chris Savage (Parallax)) : 2/8/2007 5:01:43 PM GMT
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?·
[noparse][[/noparse]Subject Added by Moderator]
Post Edited By Moderator (Chris Savage (Parallax)) : 2/8/2007 5:01:43 PM GMT
Comments
Try adding the highlighted statement to your code:
Set_Ud_Pin:
IF newTapSetting > oldTapSetting THEN
HIGH UdPin
PAR
Then·open What's a Microcontroller? Errata v1.3 (.pdf)
It contains corrections for WAM.
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.
(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
"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?
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 -->
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.