Basic Stamp + ADC0838 + Sharp IR range finder
Lazarus_87
Posts: 7
Hi there, this·forum has been very helpful everytime I encounter a·question·on BS2. In the present, I am working on using five Sharp IR range finders, GP2D12, as obstacle sensors for an·autonomous mobile robot. Since BS2 has no analog input, I am using the ADC IC, ADC0838, to convert the analog output from the range sensor to digital so BS2 can read it. Below are details of the sensor, IC, and timer (just in case I have to use it).
Sharp IR Range Finder, GP2D12 ->[url=Sharp IR Range Finder, GP2D12 ->http://www.acroname.com/robotics/parts/R48-IR12.html]http://www.acroname.com/robotics/parts/R48-IR12.html[/url]
ADC IC, ADC0838 -> http://www.national.com/ds/DC/ADC0831.pdf
Timer IC, N555 -> http://www.kpsec.freeuk.com/555timer.htm
My questions are as below:
1. ADC IC requires a clock wave from clock pin to be used during SHIFTIN or SHIFTOUT. Can BS2 provide the clock wave? If yes, how?
2. I've tried PULSEOUT, is this the correct way? If yes, I am uncertain how much·DURATION is needed to provide adequate frequency for the conversion.
3. I am confused of the logic sequence of ADC conversion, what exactly do I need to write for the ADC0838? Can I have some guidelines?
I've attached two testing programs I've modified from samples, one with PULSEOUT to provide internal clock, the other waiting for external clock. I would really appreciate it if someone provides me guidance. In the meantime, I'll also try to figure out by myself.
Thanks alot.
Sharp IR Range Finder, GP2D12 ->[url=Sharp IR Range Finder, GP2D12 ->http://www.acroname.com/robotics/parts/R48-IR12.html]http://www.acroname.com/robotics/parts/R48-IR12.html[/url]
ADC IC, ADC0838 -> http://www.national.com/ds/DC/ADC0831.pdf
Timer IC, N555 -> http://www.kpsec.freeuk.com/555timer.htm
My questions are as below:
1. ADC IC requires a clock wave from clock pin to be used during SHIFTIN or SHIFTOUT. Can BS2 provide the clock wave? If yes, how?
2. I've tried PULSEOUT, is this the correct way? If yes, I am uncertain how much·DURATION is needed to provide adequate frequency for the conversion.
3. I am confused of the logic sequence of ADC conversion, what exactly do I need to write for the ADC0838? Can I have some guidelines?
I've attached two testing programs I've modified from samples, one with PULSEOUT to provide internal clock, the other waiting for external clock. I would really appreciate it if someone provides me guidance. In the meantime, I'll also try to figure out by myself.
Thanks alot.
bs2
424B
Comments
SHIFTIN and SHIFTOUT require two I/O pins. One is the data pin, and the or is the clock or "clock wave". That's all that's required.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
Thanks for your reply. My difficulty is how to provide this "clock wave", internal or external clock? Assuming BS2 can provide the internal clock, how to do that? PULSEOUT? Then what will be the DURATION for the PULSEOUT and how often do I need to write a PULSEOUT? Sorry for my inexperience.
Regards,
Lazarus
The point here is YOU don't need to do anything. The PBASIC Stamp PROVIDES the clock signal as needed on the second pin. As I noted earlier, TWO pins are used when utilizing the SHIFTIN or SHIFTOUT PBASIC instruction. One will be for the data, and the other is for the CLOCK. Take a look at either of those instructions in the PBASIC Help file, or the PBASIC Reference Manual, and the way it works it ought to become readily apparent.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
·· example:· SHIFTOUT Dpin, Cpin,Mode,[noparse][[/noparse] data........]
·················SHIFTIN· Dpin, Cpin,Mode,[noparse][[/noparse] data..........]
···
········· I've tried like what you said, the value read from the sensor does change. However the value is always on %111111 on most of the time. If I move the obstacle in front of it, it will return %10 or %10101. What does these suggest, you have any idea? I thought it's supposed to measure the distance·between the sensor and its reflector (the obstacle).
Regards,
Lazarus·
You may need to linearize the data as shown in this technical article:
http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html
If that's not the problem, both sunlight and fluorescent lights can sometimes affect the readings.
Why didn't you just use the digital version Sharp I/R sensor? It certainly would have been a lot easier to use. Above and beyond that is the I2C approach which would permit numerous I/R or ultrasonic sensors:
http://www.roboticsconnection.com/p-86-rangewizard.aspx
That may be a bit pricey, but it certainly leaves one with lots of sensor capacity for now and later.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
Post Edited (Bruce Bates) : 10/18/2008 8:37:44 AM GMT
cs_pin CON 0· ' pin 0 to CS
clk_pin CON 1· ' pin 1 to DI
di_pin CON 3 ' pin 2 to Clk
do_pin CON 3· ' pin 3 to DO
value VAR Word
DO
· LOW cs_pin
· SHIFTOUT di_pin, clk_pin, MSBFIRST, [noparse][[/noparse]%11000\5]
· SHIFTIN do_pin, clk_pin, MSBPOST, [noparse][[/noparse]value]
· HIGH cs_pin
· DEBUG ? value
LOOP
The value returned is most of the time 255, but the funny thing is this distance sensor is turning into displacement sensor. It only reacts when I move the blocking, but goes back to 255 in an instant.
Here are my connections, though I doubt it helps
Vcc··· -> Vdd
V+···· -> ???
~CS·· -> pin 0
DI····· -> pin 3
CLK··· -> pin 1
SARS· -> ???
DO···· -> pin 3 (same as DI)
~SE·· -> ???
Vref·· -> Vdd
AGND· -> Vss
DGND· -> Vss
COM·· -> ???
Ch0··· -> Vout of Sharp IR range finder
p/s: Do I need to connect those unused channels into ground?
············· Let's just say my school is very stingy. They only provide us with what they have so can't really do anything bout it. Order takes round 2 weeks. But my project is on due in another 4 weeks. I only realize how brutal is ADC till I confront it face-to-face
Regards,
Lazarus