Let's Make Robots!

Controlling DC motors


I drive  2 dc motors by using command letters (8-forward, 2-backward, 4-left, 6-right) with Hyper Terminal and i have one problem with this.When i holding for example button "8" for a long time after i release the button  motors still drive for a while and then stop. I am using UART module at LPC2138 if someone has experience with this and want to help pls give me advice to reduce the delay.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Instead of continuosly sending keystrokes to the robot from a terminal window, write a small program that sends motorStart motorStop commands. Motor start would be sent when the forward key is pressed and motor stop could pe sent when the key is released. This could easily be written in something like Processing, which should be easy to understand if you have already programmed an Arduino.

Hi I am working with LPC2138 and i have a small program code who receive ascii from hyper terminal like"8" for forward and i work with interrupt. When one char is in Receiver Buffer Register (U0RBR) i activate the motor depend of the pressed button and when the button is released motor stop and the program is waiting for another press of button. This works only when i press buttons for short moments but when i hold them for a while and release it keeps driving for 3, 5 or 10 sec depends of how long i hold the button.    

Birdmun's solution is probably the best simple solution you will find.  One other thing that might help some is to raise the bit per second rate on the serial port.  I suspect you are using something like 9600.  Raise that as high as you can go that works, like 115200, then the characters won't get delayed as long.  Won't fix the problem entirely, but maybe make it less of a problem.

maybe you could add a 5th key, like the 5 key for Stop. Then all you need to do is tap the button for a direction and then 5 to stop that move.

Yes I could but that is not how supposed to be. I want to make my keyboard exactly like the remote control for toy cars.

Your keyboard has key buffer built in.  When you hold a key down, it repeats at about 10 characters per second.  When sending those characters over the serial port, they may not go out as fast as they are generated and get buffered either in the keyboard, the OS, or the application program.  Then, when you let go of the key, there are still buffered characters that keep geting sent.

Yes something like that is the problem but can you tell me some hint how to reduce this with  software code

The "best" solution is set the PC to not repeat keys.  I believe windows has a setting to turn off key repeat.Hyperterm may also have a similar setting, I don't know.  But Hyperterm is the worst terminal program ever devised by man.  I recommend using something else.  TeraTerm is pretty good, but other people can probably give better recommendations.  

Trying to handle it on the other end will be a problem.  The controller board has no way of knowing anything about your key presses.  It only knows it is receiving characters.  When a stream on "8"s come in, it doesn't have any way of knowing whether you are still holding the key and intending movement or if the buffer is sending old characters and you have released the key.  One thing you could do is not respond to repeated keys.  If a character is the same as the previous one, ignore it.  You would then have to press a different key, maybe space, between movement keys.  That would be unpleasant.  A better solution, in my opinion, would be two keystrokes for distance and direction.  Say "5" "F" for 5 steps Forward.  Then you would not need to hold the key down for repeated movements.