Ok so I am an absolute beginner at robot building.. Though I have been studying like a complete maniac for the past few weeks, and have a degree in electronics but that degree was 4 years back and I dont think I remember much now!.Imagine a protoboard held horizontally..Basically the circuit on my protoboard is is an H-bridge driver using bipolar transistors on the right.. there is a pic 16f57 at the left... in the center there is a voltage regulator.. I put this along with a pot to vary the voltage to the HBridge circuit... Please suggest me a better way if there is any... Earlier I had put an opamp as well but I removed it now..

I think I will use a 10.8V battery for the motor and a 7.2V for the microcontroller.. Is that fine ?

The main problem which I am facing is that I want to control the voltage in order to control the speed of the motors using my PIC...

What I thought was to attach voltage regulators, positive and negative.. and then use an op-amp to amplify voltage given by a microcontroller and feed the output to the regulators.. the analog input was 0.0517v to the opamp.... That output could be fed to the voltage regulator..

But for now I have removed the op-amp, and im thinking of directly feeding the battery voltage to the LM317, and LM337 (which unfortunately I don't have right now).. Ultimately, I would want to use a microcontroller code and give input to the adjust terminal of the regulator to vary the speed...

I don't want to sound down on you or anything, but my experience is this: If you forget an education in 4 years, you will probably fail at robotics, and probably also fail at life!

The voltage regulator should only be between the input voltage, and the VCC of the microcontroller. Set it to output whatever the microcontroller wants for input (typically 5V or 3.3V, but the data sheet will tell you for sure) and add a bypass capacitor and perhaps two capacitors around the voltage regulator.

To regulate the speed of a motor, you use PWM output from the microcontroller. To go faster, make the PWM duty cycle longer. The H-bridge needs to be able to keep up with the frequency of the PWM. If the frequency is 200 Hz, almost anything except relays will keep up, but response will be somewhat slow, and it will be noisy. Modern MOSFET based H-bridges with fast-switching gate drives can keep up at 20 kHz and above, at which point the PWM will be inaudible.

The PWM functions of a microcontroller typically are tied to whatever timer peripherals they have. The details vary be family (ARM, AVR, PIC, MSP, etc) and are described in the data sheet of the microcontroller.

I researched here and at other places and made this code.. It compiled successfully.. Would it work properly on my robot.? This code is for the IR sensor which I have..Another modified code for when my photoresistors arrive is there at the end... What about that one ?

When there are more functions, I am thinking of making a header file containing all the functions... The code is as below..

that degree was 4 years back and I dont think I remember much now![/quote[

I don't want to sound down on you or anything, but my experience is this: If you forget an education in 4 years, you will probably fail at robotics, and probably also fail at life!

The voltage regulator should only be between the input voltage, and the VCC of the microcontroller. Set it to output whatever the microcontroller wants for input (typically 5V or 3.3V, but the data sheet will tell you for sure) and add a bypass capacitor and perhaps two capacitors around the voltage regulator.

To regulate the speed of a motor, you use PWM output from the microcontroller. To go faster, make the PWM duty cycle longer. The H-bridge needs to be able to keep up with the frequency of the PWM. If the frequency is 200 Hz, almost anything except relays will keep up, but response will be somewhat slow, and it will be noisy. Modern MOSFET based H-bridges with fast-switching gate drives can keep up at 20 kHz and above, at which point the PWM will be inaudible.

The PWM functions of a microcontroller typically are tied to whatever timer peripherals they have. The details vary be family (ARM, AVR, PIC, MSP, etc) and are described in the data sheet of the microcontroller.

Thank you I will try these methods.. About the past 4 years, Ive been busy doing and learning lots of stuff man.. Its been great.. And I m coming back to tech stuff as well !

I don't want to sound down on you or anything, but my experience is this: If you forget an education in 4 years, you will probably fail at robotics, and probably also fail at life!

That's a harsh thing to say as well as totally inappropriate in engineering forum (and probably any other type of communication in the matter of fact), as that particular comment did not add any value nor answered any of abbyboy86's questions, however, based on perception of Yours alone, it implied that abbyboy86 is/will be a failure in life.

To back up my rambling - I don't remember majority of things that I learnt in uni (graduated 2 years ago) simply because I don't use them every day and my memory is terrible (or worse than I would like it to be); every time I have to write Windows app, or some software for microcontroller, or design a circuit, or use/come up with some clever algorithm I cannot take a step without referring to manual/reference/guide of some sort. Au contraire to what You said - I, for one, am not a failure in life: I have good wife, home, car, well paid job (which has little to do with what I did in uni), can afford to visit another country at least twice a year and have spare time and budget to explore other things I enjoy. So, if Your definition of failure is a person who forgets things over time, then world is full of failures and You can consider Yourself an elephant

Logged

"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

This code will read the values of Rea1, Rea2, and Rea3, and throw ignore those values, and will set the value of Rea4 to 0. That's probably not what you want.

Quote

while(!0) Rea1,Rea2=5; Rea3,Rea4=0;

This code will read the value of Rea1 and ignore it, and set Rea2 to 5, forever. It will never reach the code that reads the value of Rea3 and ignores it, and sets Rea4 to 0.

Quote

while (!0) l_rev(); r_forw();

This code will call the function l_rev() forever, and will never get to the code that calls the function r_forw().

There are multiple similar problems in the code. I suggest starting smaller -- try just a single action, and make it actually run on the robot. Then add a single second action, and verify that it all works as expected. Slowly grow the set of features, verifying between each step. That is going to make debugging much easier.

I also highly recommend ALWAYS wrapping braces {} around all while() and if() statements, even when you only have one statement. The reason is that you will then never be confused when you try to add a second statement, and it doesn't work the way you want.

Also, in robotics, you pretty much never want to do something "forever" -- you always want some kind of time-out after which you stop, no matter what.