Вы находитесь на странице: 1из 9

ROBOTICS AND EMBEDDED

C
WINTER INTERNSHIP PROGRAM

PINAKI RANJAN SARKAR

INTRODUCTION TO THE
MICROCONTROLLERS
We have focused on Atmel AVR MCUs
AVR is a trademark of Atmel Corporation. Two features make it stand
out in the list of MCUs. Atmel has a flash memory product line and
their AVR MCUs all run off of a fast and easy to program flash
EEPROM. Atmel AVR chips are in circuit programmable , which
means we can hook cable to our project and reprogram the
microcontroller quickly and easily.

The Atmel AVR uses Harvard architecture with an instruction set


designed to work well with high level language compilers like we are
using AVR studio 6.2

PIN DIAGRAM OF ATMEGA 8 AND ATMEGA


16

There are three types of ports or resisters


1. DDRX // Data Direction Resister
2. PINX // Its the resister pins to take inputs
3. PORTX // Its the resister pin for outputs

The X defines the A,B,C pins in Atmega8 and A,B,C,D pins in the
Atmega16

Here the 8 and 16 defines the System Programmable Memory. We are


dealing with 8 bit microcontroller, It means that it can handle (access
and operate on) an 8-bit data at a time.It follows that the internal data
bus, the ALU (arithmetic logic unit), internal registers and memory are
all 8-bit wide

IR SENSOR AND SIMPLE LINE FOLLOWER


CODE
IR sensor works on the principle of emitting IR rays and
receiving the reflected ray by a receiver (Photo Diode).

IR source (LED) is used in forward bias.


IR Receiver (Photodiode) is used in reverse bias.

#include <avr/io.h> //includes the AVR libraries


#define F_CPU 12000000UL //defining the clock speed of the microcontroller, atmega 8
#include <util/delay.h> // Its for the delay function
int main(void)
{
DDRB = 0xFF; // as output port
DDRC = 0x00; // as input port
while(1) // The loop will be continue for infinite times
{
if((PINC& ~(1<<0)) && (PINC& ~(1<<3))) // set the particular bit here 0 for the ir sensor
PORTB = 0x12;

//for forward motion

else if(PINC& ~(1<<0))


PORTB = 0x08;

//for left

else if(PINC& ~(1<<3))


PORTB = 0x01;

//for right

else if !(PINC& ~(1<<0)) && (PINC& ~(1<<3)))


PORTB = 0x00;
}
}

//stop

SPEED CONTROLLING USING PWM


Their are two methods by which you can generate PWM from
AVR
Fast PWM
Phase Correct PWM
We will use the simplest timer, TIMER0 for PWM generation.
(Note TIMER0 of ATmega8 cannot be used for PWM generation,
these are valid for ATmega16 and ATmega32). We have a 8bit
counter counting from 0-255 and the goes to 0 and so on. This
can be shown on graph as

The period depends upon theprescalarsettings. Now for PWM


generation from this count sequence we have a new resister
named OCR0 (Output Compare Register Zero , zero because its
for TIMER0 and there are more of these for TIMER1 & TIMER2).
We can store any value between 0-255 in OCR0, say we store
63 and 191 in OCR0 then it would appear in the graph as
follows.

Вам также может понравиться