Quote Originally Posted by shaiqbashir View Post
Thanks a lot for all ur help!

@skimask:

Thanks for that idea ! Well! surely i have written up my own code as well, that dint work so i have asked on this forum to provide me some help. I do admit my mistake that i dint provide my own code here: Well! This is what i have tried to do:

I have used PIC16F84A here. I havegot two motors. So two h-bridges surely.Now in each H-bridge, there are 4 inputs to be controlled logically:

1) Left P-channel MOS
2) Left N-channel MOS
3) Right P-channel MOS
4) Right N-channel MOS

now u see, if i take one H-bridge into my consideration. I can ON the pin containing Left P-channel MOS using HIGH command. then i can OFF the pins containing Right P-channel and Left N-CHannel MOSFETs using LOW command. When i apply PWM command on the port containg Right N-channel MOS, the H-bridge works and the motor rotates in one direction. So i say that my H-bridge is controlled by PWM command now.

Now comes the tricky part:

Now i have to drive the second H-bridge simultaenously as well. In PIC16F84A, there is only one PWM present. So what i decided to do is simply this that i connect run the second H-bridge totally by HIGH and LOW commands. I dint give any PWM command in the second H-bridge at all. Like I ON the Left P-channel and Right N-channel using HIGH command. I OFF the Right P-channel and LEft N-channel using LOW command. The motor runs in one direction as well.

What i had in my mind at that time, that i would first see that which of my motor is a faster one, Then i would use PWM command with the faster motor and will control the slower motor with HIGHs and LOWs only. So that i can reduce the speed of the faster motor through PWM command in order to make the speed of both motors equal so that my robot can go straight.

This is what my logic was, but dont know what it doesnt work. That is the reason whay i have asked u guys! Do u guys see any major flaw in this logic?

What are ur ideas to control this sort of mechanim?

Mr. Skimask! once again thanks for providing this code, but i do require some more explaination in order to understand this code. Like plz tell me how can i vary duty cycles in this?

I would be thankful to you if u plz provide some detailed explaination of this beautiful code.

Thanks in advance!


Read my post.......again.......slowly.......including the comments.......
Almost everything you need is right there in my post; left and right drive pwm values and a loop to make the pwm, a method for channel specific complementary drive (for drive 2 sets of 2 MOSFETs connected to 2 different channels). There's nothing tricky about what you're trying to do. It's been done, a lot, a whole lot, since the beginning of time, if not before...

And if you think you're going to find 2 perfectly matched motors that you can drive with an equal PWM signal/current, and get exactly the same RPM from both, under varying load conditions (floor surface, battery voltage, inclination, etc), well, I'm here to tell you, the world isn't that perfect.

You'd better design some sort of optical input or something to detect wheel speed and modify your PWM to compensate, and even then, an optical input is going to be a reactive system (i.e. the wheels start turning at different speeds, you speed one or the other up to compensate, too late, the 'bot has already turned somewhat).

What are YOUR ideas?