LINE FOLLOWER coding almost done ,, need checking help

Thread Starter

x.macubex

Joined Feb 17, 2010
1
/*

ic used atmega16
l293d

notes -

* I have used codevision of coding so check heades
if using avrstudio ,, and also direct refrence like PINA.1
is not avialable in avrstudio ,,

* adc fxn not used

* ports used

- pin 33 to 40 for sensor arrays (PORT A),,

- for PWM signal ie the one going to enable pin of h bridge
OC1B pin 18
oc1A pin 19 (PORT D)

- pin 22,23,24,25 is given to the i/p of the L293d ie i/p 1,2,3,4 in order (PORT c)


*/



#include <mega16.h>
#include <delay.h>
#include <stdio.h>

#define FWD 0xAA
#define REV 0x55
#define R 0x22
#define L 0x88
#define CW 0x99
#define CCW 0x66
#define STOP 0x00
#define B 0xFF
#define RSPEED OCR1AL
#define LSPEED OCR1BL
#define SPEED0 255
#define SPEED1 0
#define SPEED2 0
#define SPEED3 0
#define MAX 3
#define HMAX 1


void move (unsigned char dir);

unsigned char i,rdev,ldev,ip,dir,dirl,history[MAX],hcount=0,rotpow;



unsigned char rep=0,prev=0;


void main(void)
{
// Input/Output Ports initialization
// Port A initialization

PORTA=0x00;
DDRA=0x00;

// Port B initialization

PORTB=0x00;
DDRB=0x00;

// Port C initialization

PORTC=0x00;
DDRC=0xFF;

// Port D initialization

PORTD=0x00;
DDRD=0x30;

// Timer/Counter 0 initialization
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization

// Clock value: 921.600 kHz
// OC non inverting
// I/p Capture on Falling Edge

TCCR1A=0xA1;
TCCR1B=0x0A;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0xFF;
OCR1BH=0x00;
OCR1BL=0xFF;

// Timer/Counter 2 initialization
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00; // disconnect occ2

// External Interrupt(s) init

MCUCR=0x00;
MCUCSR=0x00;



// USART initialization

UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x07;



// Timer, counter, Interuptor init

TIMSK=0x00;

// Analog Comparator initialization

ACSR=0x80;
SFIOR=0x00;


while (1)
{

if(rep<255)
rep++;

if(prev!=PINA)
{
prev=PINA;
printf("%u\r",rep);

for(i=0;i<8;i++)
printf("%u\t",(prev>>i)&0x01);

rep=0;
}



if(PINA!=255)
{
rotpow=255;
ldev=rdev=0;

if(PINA.3==0)
rdev=1;
if(PINA.2==0)
rdev=2;
if(PINA.1==0)
rdev=3;
if(PINA.0==0)
rdev=4;


if(PINA.4==0)
ldev=1;
if(PINA.5==0)
ldev=2;
if(PINA.6==0)
ldev=3;
if(PINA7==0)
ldev=4;

if(rdev>ldev)
move(R);

if(rdev<ldev)
move(L);

if(rdev==ldev)
move(FWD);
}
else
{
for(i=0,dirl=0;i<MAX;i++)
{
if(history==L)
{dirl++;}
}

if(rotpow<160)
{rotpow=160;}
if(rotpow<255)
{rotpow++;}
if(dirl>HMAX)
{move(CW);}
else
{move(CCW);}
}
};
}

void move (unsigned char dir)
{
PORTC=dir;

if(dir==L || dir==R)
{
hcount=(hcount+1)%MAX;
history[hcount]=dir;
}

LSPEED=RSPEED=255;

}




/*
i have done the above code ,, the code seems to be flaw less ,, i cant get what the problum is ,, there r two moters ,, icant get the motor 2 to work ,, i checked weather its in working condition ,, plz check the above code ,, so that ya can find any errors ,,


*/
 
Top