GE 330 - Final Project

Group 10 - Nick Gans

Atmel Microcontroller Applications

 

 

I had two, related projects implemented with the Atmel Mega16 Microcontroller.  The first was to interface the IR distance censors used in the labs with the I2C bus.  The second project was to implement a right wall following program on a simple, two-wheeled robot.

 

The Sharp G2D02 Infrared Sensor used in the Mechatronics Lab provides an 8-bit range sensor with a serial interface.  The other sensors used in the lab communicate with the DSP using a two-wire serial interface developed by Phillips, known as I2C.  It is desirable to have all the sensors on the same bus.  The basic strategy employed is to have the Atmel chip constantly requesting readings from the three IR sensors and storing the data.  Whenever the DSP requests data from the Atmel chip, the Atmel sends the most recently acquired data.

Going into further detail, the Sharp IR has a single input and a single output.  Pulling the input high for a significant period of time (around 50-70ms) will cause it to latch the current reading.  It will send it's output low to inform the Atmel it is ready.  The Atmel then "clocks" the Sharp input line eight times.  At each rising edge the Sharp will output one bit which the Atmel reads and shifts.  The Atmel has an onboard timer, which will generate an interrupt when it counts a specified number of clock edges.  This was used to generate the correct timing for the input high and the clock pulses.  At the end of the ISR the data is saved.

The Atmel chip is configured as a "slave" on the I2C bus.  All the other sensors on the bus are slaves as well, and each has a specific address.  The DSP is the bus master; it broadcasts the address of the slave device it wants to communicate with along with a word of data.  The master then can either send to or receive data from the slave.  The Atmel has an integrated I2C bus, and can be configured as a slave with a unique address.  When the Atmel's slave address is broadcast, an interrupt is generated.  The Atmel checks the data word to see which IR reading was requested and then sends the data on the I2C bus.  Documentation on using the Atmel I2C was pretty sketchy.  I used this site for some code to handle communications.  The assembled program was 312 bytes.

atm_i2c.c -- functions to handle I2C communications on Atmel

i2c_com_1.c -- main Atmel program, includes IR reading functions

user_I2C_IR_Robot.c -- Code on Robot to request IR readings from Atmel  

 

I also used the Atmel controller to perform wall following with a simple two-wheeled robot.  The code to read the IR sensors was kept from the previous project.  The second hurdle was to correctly drive the wheels.  The wheels are driven by modified Hobbico CS-72 servo motors.  A Pulse Width Modulated (PWM) signal determines the speed and direction the servo moves to.  The period is about 20ms, and the duty cycle is between .1ms and 2ms, corresponding to an output from full reverse to full forward. 

The Timer and ISR were modified to handle the PWM generation, which needs to update approximately every .1 ms (10KHz).  Thus interrupts were generated at 10Khz for the PWM, and counted until the appropriate amount of time had passed to handle ISR tasks.  Occasionally the timing of two sets of tasks interfere which can be seen in shuddering of the robot.  Since the majority of both tasks is waiting, this overlap is fairly rare.

Control of the wheel speed is rather simple, due to the servo characteristics and limits on the PWM resolution.  Each wheel has 5 forward speeds and 4 backwards speeds, plus stop.  There is no way to measure speed, so the speed is necessarily open loop.  The IR sensors provide feedback to a steer input which weights the wheels appropriately to turn.  The assembled program was only 325 bytes.

lil_robot.c - all code to perform wall following with the little robot    

Shots of the robot in Action

wall_foll1.JPG - wall following

wall_foll2.JPG - more wall following

corner.MPG - video of the robot turning around a corner

wall1.MPG - video of the robot wall following