PDA

View Full Version : Serial Interfacing with DC Motor



shyam4uall
01-08-2009, 09:43 PM
I want to drive 2 DC motors through PC serial port via microcontroller(Atmega8).

I am struck with the programming part(WinAVR).Please help me.

What i want is that when I send "1" the two motors should rotate clockwise(forward) and when "2" one should rotate clockwise another anti clockwise (left/right) and same for backward movement.

I have seen some examples where a character is send from PC like "C" and "[C]" is send back to PC.I have to modify those codes.

I am confused that after sending a command for forward movement let it be "1" and storing it in a variable,now after this how do i send the data to the output pins.

can it be like this :

if(temp=="1")
PORTD=XXXXXXXX;

also how to handle those buffers ?

(I have started few more threads all related to same stuffs sorry for that)

shashak
01-08-2009, 11:06 PM
can it be like this :

if(temp=="1")
PORTD=XXXXXXXX;



you are on right track, its all logical problem i.e. how u have to code,
look up table is your answer, just resolve how many combination there could be and map them like match the column analogy using if else or any equal statement, and also use <AND NOT> and <OR> logic with pin assertion, just for sanity....

avinash_g
01-10-2009, 06:41 PM
Hey you are writing "1" which is a string and strings CANNOT BE compared that way !!!

Write '1' instead of "1"

Coz '1' is single byte char while "1" = 2 byte STRING of char (the last byte for '\0' for string.


See my RS232/ USART turorials here

http://extremeelectronics.co.in/avr-tutorials/using-the-usart-of-avr-microcontrollers-reading-and-writing-data/