The Tracked Robot Project 2010Page 6Bringing it all togetherWe
have the breadboard mounted and the pin layout mapped out. Not it's
time to wire up the robot and begin bringing it to life. Here is a
photograph of the robot as I completed it at the time of this writing.
The motors are connected for testing WITHOUT the tracks installed. This
way I can run up the motors and test for overheating and other problems
without the robot rolling off the table. Once inital testing is
completed, the wires will be run more neatly and the tracks installed
for "road testing" to see how it handles on floors, carpet, grass, and
concrete.
Testing Configuration As
you can see above, the bulk of the electronics is in place. The wheel
count sensors and the LCD need to be connected again but the robot is
capable of running under power and has run both motors forward and
reverse by setting the PWM pin to ON. This runs the motors at full
speed... which under 3 volts is rather slow... so we will upgrade to
4.5 volts to give it a bit more pep. By using PWM instead of just
turning the port to ON, we can control not only the direction but the
speed as well.
The motor driver uses three pins for each motor... or a total of six (6) pins for both motors. For each motor two of the pins set the direction to one of four states... IDLE, STOP, FORWARD, or REVERSE. The difference between IDLE and STOP is that in the IDLE mode the motors can free spin but in STOP the current generated by a spinning motor us used as a brake. Since this motor set is geared 203 to 1... there isn't much free spinning going on! The remaining pin will disable the motor when set LOW, and enable the motor when set HIGH. If you use PWM, the motor is actually switched on and off several hundred times per second... and if it is on more than it is off it goes faster. If it is off more than on... it goes slower. Lets look at a few of the connections we have to the microprocessor and how they were developed for this project. Let's start with the LCD display that we are adding and that you will see in the images to follow. The LCD that we use is a character only type so it does not support commands like LINE, CIRCLE, etc. It is a very simple device to use in BASCOM... we simply define which pins are being connected to the processor, then we have a few simple commands that are available to us. LCD Commands
Connecting and Configuring the LCDConnecting the LCD to the processor is pretty simple, the unit has 14 pins, connect pins 1, 3, and 5 to ground. Connect Pin 2 to your 5v supply. Once that's done there are two control lines called RS (pin-4) and E (pin-6) that get connected to an unused pin on the processor. There are 8 data pins starting at pin-7 to pin-14 but we are going to use only four of them. It is slightly slower... but we are not going to do more than 10 or 20 updates per second at most... so it's not a big deal. Here are the connections that were used in this project.
Once you have made the electrical connections, you need to tell the microprocessor how the chip is connected. We start off the BASCOM program by identifying the chip, some of it's parameters, and by telling it what is connected to it. The first lines 001 to 009 set up what type of processor we are writing for. If we didn't have these specified, we would need to use a drop-down menu each time to specify them. We have included this information with the special commands starting with the ( $ ) symbol. The software will now do this for us automatically each time we open the file and compile it. The lines in green that start with the ( ' ) character are remarks. A remark is just a note for you and I that the processor will ignore... it will not be loaded into the chip and it will not use any memory. So... ALWAYS put remarks in your code so that when you come back in six months... you will be able to figure out how it works again.
Starting at line 010 we tell the AVR that an LCD is attached and how to use it. First we let the processor know there are 16 characters and 2 lines of text available to us on line 011. We look at our connections and let the AVR know which pins are connected to what functions of the LCD in line 012. When that is finished, we can clear the display by using the command CLS, then place text onto the display with the LCD command. Switches A and B TheoryThere are two switches installed on the robot to allow us to interact with the software. We can have the robot do something simple like displaying a message "Robot OK" on the LCD and flash an LED to let us know it is wating. This let's us know that the processor is working and that everyting should be okay to continue. Sometimes you don't want motors to start spinning right away... so we included two switches. One could have the robot do a simple test of the motors such as starting each one for a second or two just so that we know the batteries and motor drivers are all connected properly. The software could then jump to our main routines when we hit the second button. It allows us more control over how the robot behaves.The ports on the Atmel AVR series have three internal registers that we need to know about. There is a PORT which supplies signals to the outside world, a PIN which is an input from the outside world, and a DDR which selects between INPUT and OUTPUT modes. Since we want to connect our two switches to the Atmel physical pins 24 and 25, we need to remember how the chip is designed. Since the switch will be an INPUT, we need to assign them as PINC.1 and PINC.2 instead of PORTC.1 and PORTC.2 or we won't be able to read them. Once they are defined, we need to set the proper DDR to be an INPUT. There are several ways of doing this... but since you are just getting started with programming we will use the most simple method. In our code we will include... CONFIG PORTC.1 = INPUT CONFIG PORTC.2 = INPUT We could have also set all 8 of the bits at the same time... using a 0 for input and 1 for output... this is done by using a binary number. The binary numbers start with ( &B ) followed by the actual bits... larges to smallest. Since we are looking at setting pins 1 and 2... keep in mind the bits go from 7 through 0 reading left to right. Placing a 1 in all the other bits will leave them as an OUTPUT, the ones having a 0 will be the INPUTs. DDRC = &B11111001 Since you are already grasping enough new concepts... we will just stick with the first method for now. The second method will save some memory if you are defining a lot of pins however... so you may want to use it more as your code becomes more involved. Electrical Connection of Switches
|