The Tracked Robot Project 2010

Page 5

Assignment of the Processor Pins and Ports

We are using an Atmel Mega 88P as the processor for this version of the tracked robot. The Atmel AVR series of chips are easy to program and are not very expensive. Most of the pins can not only be used as simple input or output, but can also be assigned special tasks by turning on functions built into the chip. Some pins or ports can be used for more than one function while some are dedicated when you select to use them for a specific function.
 
ChipProgram FLASH MemoryEEPROM Data Storage
AT Mega 44P4K256 Bytes
AT Mega 88P8K512 Bytes
AT Mega 168P16K512 Bytes
AT Mega 328P32K1024 Bytes

We are using an SPI port to program the chip, this means that certain signals are triggered to allow new code to be sent to the chip. To do this we need to dedicate the RESET pin so that when it is held LOW the chip will go into reset mode and either start the program over, or if the proper signals are placed on the programming pins, the chip can be reprogrammed. For this reason, Pin-1 cannot be used for anything other than programming and resetting the chip. We must now evaluate the remaining pins and decide which will need to be used for specific tasks and which can be changes with ease depending on our needs.

mega chip pins
Mega 48P, 88P, 168P, 328P pin connections

The remaining programming pins, 17, 18, and 19 could also be used for other purposes when the chip is not being programmed... but we need to be careful. If a motor controller were connected here, it could start up with unpredictable results every time the chip is programmed. But, if we connect an LCD to these pins, the worst that would happen is that the display would have garbage on it during programming... but nothing would be harmed by that. Since it won't hurt anything, we will dedicate these pins to three of the four data lines of the LCD.

Two if the pins have a special alternate function, OC1A and OC1B are functions that can generate Pulse Width Modulation (PWM). The PWM function can be used to make a DC motor run at variable speeds which could be very useful for a roving robot. For this reason we will dedicate these two pins to the PWM inputs of the motor driver chip. (We are using an L293B because I have a few in my parts bin.)

Next we go through the remaining pins and assign them prior to doing the wiring for the circuit. This way, we can avoid most problems later on and not need to rewire the board. It will also serve us if we wish to troubleshoot or modify this circuit in the future. I use a spreadsheet as a workbook to help me lay out the assignments as follows.

Connect To PIN PORT  FUNCTION   DEVICE   FUNCTION  PORT PIN Connect To
Programming / Reset Switch 1 PC.6 RESET Atmel
AVR


MEGA
88P
ADC5 PC.5 28 Speaker 
 Reserved for communication 2 PD.0 RXD ADC4 PC.4 27 Motor 2 Direction A
Reserved for communication 3 PD.1 TXD ADC3 PC.3 26 Motor 2 Direction B
Wheel Sensor #1 4 PD.2 INT0 ADC2 PC.2 25 Switch A (PINC.2)
Wheel Sensor #2 5 PD.3 INT1 ADC1 PC.1 24 Switch B (PINC.1)
Wheel Sensor LED 6 PD.4 T0 ADC0 PC.0 23 USER I/O
5 VOLTS DC ( VCC ) 7 VCC POWER GROUND GND 22 GROUND
GROUND ( VSS ) 8 GND GROUND AREF AREF 21 VCC
LCD PIN 14 9 PB.6 XTAL1 AVCC AVCC 20 VCC
LCD PIN 06 10 PB.7 XTAL2 SCK PB.5 19 Programming / LCD - PIN 13
Indicator LED #1 11 PD.5 T1 MISO PB.4 18 Programming / LCD - PIN 12
Motor 1 Direction A 12 PD.6 AIN0 MOSI PB.3 17 Programming / LCD - PIN 11
Motor 1 Direction B 13 PD.7 AIN1 OC1B PB.2 16 Motor #2 PWM
LCD - PIN 04 14 PB.0  I/O OC1A PB.1 15 Motor #1 PWM

I prefer to program in BASIC since I have used the language since 1978 or so... and the version that I am using called BASCOM is very powerful, supports a large number of chips, and the demo version is FREE and will program up to 4K of memory. For this robot... I doubt that we will exceed that memory restriction. We are using the AT Mega 88P, but we could have used the Mega 44P which has 4K of memory and have programmed 100% of the memory with the free version. You can download the software here:  http://www.mcselec.com/

If you get the registered version, you can program beyond the 4K barrier... and if you use the Mega 328P chip... you would have FOUR TIMES the memory of the Mega 88P chip we are using in this version. (All the above chips are pin-for-pin compatable.)