Shop OBEX P1 Docs P2 Docs Learn Events
Good Evening All, — Parallax Forums

Good Evening All,

simpsonmichael1simpsonmichael1 Posts: 13
edited 2009-01-02 19:12 in BASIC Stamp
Good Evening All,


I need help with a DIY encoder system utilizing the bs2 micro-controller. Although, I saw kit encoders on the market, my robot is very large. My robot's rear wheels have a 6-inch diameter. I am using two scooter motors via chain drive. I have a simple light circuit using a flashlight and LDR connect the micro-controller. I'm using 2.5 PBASIC software to read in the input values, if true. However, when I try to code...it does not work well. See below.

desiredDX var word
count1 var word
Revcount1 var word



DO

Debug "Enter the distance desired", CR
DEBUGIN desiredDx

FOR count1 1 to 48

If (in3 = 1) then //sensor setup to provide a high on pin 3
count1 = count1 +1
Else
Debug "No input because no light on sensor", CR
Endif
Next

If (count1 > 47) then
RevCount1 = RevCount1 +1 //RevCount would be equal to a predetermined distance like if 100 this would be 20 feet. I
If (RevCount = 100) then
Stop

LOOP


However, even with no light the counter continues erratically or it counts when light is applied, but the RevCount always fails to work. I'm new to programing, so I need a bit of help. I am willing to learn. I find it difficult to do, but robotics is fun and rewarding.

I have read a few examples on counters, but want I really want to do is count the amount of times the spinning wheel (with holes in a CD disk) breaks the light path. If it breaks the light path x number of times, then I want to compare those values to a fixed distance. If the fixed distance is equal to my user desiredDX, then my robot will not move any further (in a straightline). If possible, does anyone know how to reuse an old computer mouse for an "encoder system" and how to write an example program for a bs2 micro-controller? Plead advise. Thank you.

Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:12:42 AM GMT

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,563
    edited 2008-12-31 04:59
    simpsonmichael1,

    In the future please try to use a descriptive subject for your posts. "(No Subject)" doesn’t convey what you need help with. This will often limit potential useful responses as those who can help may never see your message.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwinnkwinn Posts: 8,697
    edited 2008-12-31 18:58
    The first thing to check is the "CD encoder" to be sure you are getting a clean signal in. Most CD's I have seen are semi transparent and that may cause spurious counts. Second, here does not appear to be code to wait for the signal to go back low before checking for a high again. This makes it likely that you will count the same high signal more than once. Try a bit of code to read and display the status of the pin as a starting point. Once you can see it change from low to high at the appropriate position of the encoder you can proceed to the next step.

    PS - Great way to recycle a CD coaster.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-02 19:12
    You can add a subject to your message by clicking the Pencil icon at the top right of the message. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.