Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help in robot project

Status
Not open for further replies.

dx_2k5

New Member
Hi all
First I want to thank forum owners for this great forum, which can be very useful for students and engineers.:)
My project is wheeled robot powered with two dc-motors and gear boxes included with the motors, I used H-Bridge L298 to drive the two motors , under the control of PIC 16F84 , I did design the robot body and it is really looks great ;:D
Now I had one incremental encoder i mounted it in the left wheel and I want use it to gives order to motors to move in certain directions for example:
I want to program the robot to move forward while the encoder counting then when the encoder reach a value then stop the motors, then turn right 90 degrees then stop and move forward....etc.
now I wondering how to make the 16F84 count the pulses from the encoder ; do I need another chip like counter chip , and what is the Picbasic pro codes do I need ??????:confused:
I had a good experience with PIC basic pro complier .... Thanks for reading
 
You don't need a separate chip. THe PIC can count pulses very easily. This is an incremenetal encoder only? Just ticks for every X degrees of rotation, identically whether it's CW or CCW? Just to let you know, one encoder won't be enough to help your robot from not veering off course.

Since your PIC doesn't have a capture compare module, you COULD connect the encoder to an interrupt pin and just have it increment a value every time the interrupt is activated. OR you could make it easy and use Timer0 as a counter rather than a timer:

PAGE 21: https://www.electro-tech-online.com/custompdfs/2006/08/35007b.pdf
It tells you how to use Timer0 as a counter rather than a timer- the counter is incremented based on input pulses on the RA4 pin.
 
Last edited:
Thank u dknguyen for a quick reply:)
I think am going to try TMR0 one.
I don't know a lot about interrupt in 16F84 coz I didn't try it , but I'll give it a try.
By the way why is two encoders is necessary instead of one .,coz in my project i think only one encoder is enough?????
 
Two encoders will help drive the robot straight.
And help with turning accuracy.
I'm guessing that's where dknguyen was headed.
 
Yeah, one encoder on one wheel is kind of like God giving you two legs, but making one of them numb all the time. One encoder will give you purely distance readings. The problem with one "assymetric" encoder is that if the robot veers/turns, it will affect your readings (one wheel travels less or more during turns).

If you use one encoder, it's better to stick it on a single passive wheel centered somwhere on the midline between the two powered wheels. That way, if the robot veers or turns, your distance readings are still accurate. Bottom line- you want your encoder arrangement to be symmetric so they are not affected by turns. So one one encoder in the center, or two either side of the centerline is fine. But one on a single side is not.

Do what you want though, it may be the case that the encoder is designed just for that motor and must stay with it and you don't want to buy a second encoder for the other motor (plus there is only one Timer0 pin to work with so you can't use that method with two encoders). You could use the tricycle formation though. This would allow the use of one motor-mounted encoder, but would require a steering servo.

Don't use the interrupt. Use Timer0. It's should be more straightforward and take less code plus it won't bog down your processor with interrupts since (I assume) it's designed to run in the background. As opposed to interrupts which will continually interrupt your program flow. Also, if for some reason your PIC is clocked ultra slow and the wheels are spinning ultra fast (or the encoder outputs many many ticks per revolution), you might actually miss ticks...which build up onto the already attrocious odometric error from wheel slip.
 
Last edited:
Thank u guys for this information......I am going to test counter method,,,,,,and for encoder may be I'll try to get another one and replace the 16F84 with another PIC which contains two TMRs.
 
You need to have two timers that can behave as counters and I am not sure if PIC chips have this. So yeah, hehe.
 
actually, I think he should use interrupts from the encoders and one timer to determine a sample period for both encoders. the interrupts will be very short, just increment a counter and the usual house keeping. I'd stick schmitt triggers on the int lines, though. The advantage is that you can accurately tell differential rotations.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top