HELP!: I need a simple encoder using my photoresistor and a PBASIC program.
itsme_melb
Posts: 5
I need Help with this project.....any help would be great I am really dumb when it comes to coding...
Use your photoresistor and a PBASIC program to make a simple encoder. An encoder is a device that reads spokes on a wheel as they pas by. Use your photoresistor as the sensor that reads the spokes and use your hand as the spokes. By waving your hand past the photoresistor, you can emulate spokes passing by the sensor. Using the DEBUG terminal to display how many times you pass youyr hand over the photoresistor. With some calibration, you can also hold your fingers wide apart and pass them over the photoresistor to emulate spokes.
Use your photoresistor and a PBASIC program to make a simple encoder. An encoder is a device that reads spokes on a wheel as they pas by. Use your photoresistor as the sensor that reads the spokes and use your hand as the spokes. By waving your hand past the photoresistor, you can emulate spokes passing by the sensor. Using the DEBUG terminal to display how many times you pass youyr hand over the photoresistor. With some calibration, you can also hold your fingers wide apart and pass them over the photoresistor to emulate spokes.
Comments
since I'm sure you have Pbasic, look up the COUNT command.
This should work well enough for you.· As for hooking up the circuit....I quickly edited this image (robbed it from an optoisolator setup--works the same).
No doubt there are other ways to set this up....someone else may have a better circuit too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I did notice that steve_b posted a schematic using an phototransistor and LED.· This is the more appropriate way to go.· The transistor can switch alot faster, and will often have a smaller aperture for the light to pass through, so with an adjacent LED, it will more accurately detect the spokes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
Didn't pay enough attention to that.
Also, to melb....VCC in my schematic is 5Volts.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
·· Sub-conciously you must've thought about it, otherwise you'd have posted a schematic of what he was looking for, instead of what he should be using.· So you were on some level thinking about it...
Did any of this help the original poster?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
It's true that the IR LED/Transistor combo is the most common optical encoding method.· It's reliable and can work at much higher speeds and resolutions than photoresistors.· However, I couldn't include it in What's a Microcontroller because it was already covered in Industrial Control.· The most I could do was include it as an optional project at the end of the photoresistor chapter.· My reasoning behind this project was that writing a PBASIC program to track the number of black/white, white/black,... transitions is·still a valuable lesson.
Even thought the most common use for photoresistors seems to be rough ambient light measurements, they actually do work pretty well as encoders at lower speeds and resolutions.· With fenders to block out the light and LEDs to illuminate the stripes, they're alright.· A pair of them can be used for quadrature, and with RCTIME measurements, a software Schmidt trigger can also be implemented.··Fun!
I don't want to derail any instructors by posting the solution, but here are some hints.·
Now that you know the light and dark measurements, you can modify TestPhotoresistors.bs2 to count the black/white, white/black transitions.
Post Edited (Andy Lindsay) : 12/8/2004 7:39:08 PM GMT
DO
HIGH 2
PAUSE 100
RCTIME 2, 1, time
DEBUG HOME, "time = ", DEC5 time
IF time <= 12 THEN
stateNow = 0
ELSEIF time => 30 THEN
stateNow = 1
ENDIF
IF stateNow <> stateOld THEN
counter = counter + 1
DEBUG CR, "Spoke Count·= ", DEC counter
stateOld = counter
ENDIF
LOOP
I have now clue to what I am doing...but I am trying....
it still doesn't work right....when I pass my hand over the photoresistor it adds 1 to the counter and when my hand·isn't over the photoresistor it still adds 1 to the counter....what am I doing wrong?...also I don't think my IF then statements are correct....
Post Edited (itsme_melb) : 12/8/2004 4:51:38 PM GMT
stateOld = counter
to
stateOld = stateNow
it should start to work better.
My instructions incorrectly told you to set stateOld equal to counter, stateOld should instead be set equal to stateNow.· Sorry.· I will edit those instructions so that they do not lead others astray.
The program·should add 1 to the counter when you place your hand in front of it, and add another 1 when you remove your hand, then another 1 when you place your hand in front of it again, etc...
The·PAUSE 100 is in there so that slower computer's don't suffer from serial buffer overload.· When you are using it in an application that's counting stipes moving by at faster rates, reduce the PAUSE 100 TO PAUSE 1, and comment out the debug commands.
For·motor speeds, the Industrial Control text has a better design that uses·infrared parts and the COUNT command.· Industrial Control is available from the www.parallax.com -> Downloads -> Stamps in Class Tutorials page.
Post Edited (Andy Lindsay) : 12/8/2004 7:51:50 PM GMT
I have another question...How can I use a potentiometer circuit to control the tempo of this program. Any suggestions would be great....
Here is the code for the program so far:
Notes DATA "C", "C", "G", "G", "A", "A", "G"
Frequencies DATA Word 2093, Word 2093, Word 3136, Word 3136,
Word 3520, Word 3520, Word 3136
Durations DATA Word 500, Word 500, Word 500, Word 500,
Word 500, Word 500, Word 1000
index VAR Nib
noteLetter VAR Byte
noteFreq VAR Word
noteDuration VAR Word
DEBUG "Note Duration Frequency", CR,
"----
", CR
FOR index = 0 TO 6
READ Notes + index, noteLetter
DEBUG " ", noteLetter
READ Durations + (index *2), Word noteDuration
DEBUG " ", DEC4 noteDuration
READ Frequencies + (index * 2), Word noteFreq
DEBUG " ", DEC4 noteFreq, CR
FREQOUT 9, noteDuration, noteFreq
NEXT
END
Also, it would be better to post these questions to the Stamps in Class Forum.· It is intended for questions like these, to help students collaborate on solutions.·
Last but not least, this subject is not encoder related, so it would be best to start a new thread in Stamps in Class.
Post Edited (Andy Lindsay) : 12/9/2004 12:41:25 AM GMT