ببینین من یه ربات مسیر یاب با متور گیر بوکس 500 دور و 10 سنسور tcr5000و درایور موتور l298 و ای سی atmega32و ایسی uln2003برای برد سنسورام درست کردم الان برنامشو هم ریختم اما وقتی موتورامو به 12 ولت وصل میکنم از خط میره بیرون ولی وقتی به 7 یا 6 ولت وصلش میکنم درست راهشو میره و بدون خطا !!!!!!!!!!!!!!!!!!!!!!!!
حالا شما بگین باید چی کار کنم
راستی porta ورودی ایسی هم است و portd خروجی ایسی هست(prtd.0 تا portd.5) برنامشم با کدویژن نوشتم
حالا شما میتونین کمکم کنن تا برنامشو درست کنم
اینم متن برناممه
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
Project :
Version :
Date : 2/7/2012
Author : NeVaDa
Company :
Comments:
Chip type : ATmega32A
Program type : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
#include <delay.h>
#define FWD 0b00011110
#define R 0b00011000
#define L 0b00000110
#define CW 0b00011011
#define CCW 0b00110110
#define STOP 0b00000000
#define Rspeed 0b00011011
#define Lspeed 0b00110110
#define MAX 3
#define HMAX 1
// Declare your global variables here
int sensor1[10];
int sensor2[10];
int sensorflag=1,j;
void sensordetect(void);
void move(unsigned char dir,unsigned char delay,unsigned char power);
unsigned char i,rdev,ldev,ip,delay,dir,power,dirl,history[MAX],hcount=0,rotpow;
int fwdcounter=0,ocounter=0;
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTD=0x00;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
while (1)
{
sensor1[0]=PINA.0;
sensor1[1]=PINA.1;
sensor1[2]=PINA.2;
sensor1[3]=PINA.3;
sensor1[4]=PINA.4;
sensor1[5]=PINA.5;
sensor1[6]=PINA.6;
sensor1[7]=PINA.7;
sensor1[8]=PINC.6;
sensor1[9]=PINC.7;
for(j=0;j<=9;j++)
if(sensor1[i]==sensor2[i])
sensorflag=0;
if(sensorflag)
sensordetect();
sensorflag=1;
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
// Place your code here
if(PINA.0==1 || PINA.1==1 ||PINA.2==1 ||PINA.3==1 ||PINA.5==1 ||PINA.6==1 ||PINA.7==1 ||PINC.6==1 ||PINC.7==1)
{
rotpow=255;
ldev=rdev=0;
if(PINA.3==1)
rdev=1;
if(PINA.2==1)
rdev=2;
if(PINA.1==1)
rdev=3;
if(PINA.0==1)
rdev=4;
if(PINA.6==1)
ldev=1;
if(PINA.7==1)
ldev=2;
if(PINC.7==1)
ldev=3;
if(PINC.6==1)
ldev=4;
if(rdev>ldev)
move(R,0,195+12*rdev);
if(rdev<ldev)
move(L,0,195+12*ldev);
if(rdev==ldev)
move(FWD,0,200);
if(PINA.4==1 || PINA.5==1)
move(FWD,0,200);
}
else
{
if(fwdcounter>1)
move(FWD,0,200);
else
{
for(i=0,dirl=0;i<MAX;i++)
{
if(history[i]==L)
dirl++;
}
if(rotpow<160)
rotpow=160;
if(rotpow<255)
rotpow++;
if(dirl>HMAX)
move(CCW,0,rotpow);
else
move(CW,0,rotpow);
}
}
}
}
void move(unsigned char dir,unsigned char delay,unsigned char power)
{
PORTD=dir;
if(dir==L || dir==R )
{
hcount=(hcount+1)%MAX;
history[hcount]=dir;
ocounter++;
if(ocounter>100)
ocounter=100;
if(ocounter>=2)
fwdcounter=0;
}
if(dir==FWD)
{
fwdcounter++;
if(fwdcounter>100)
fwdcounter=100;
if(fwdcounter>=2)
ocounter=0;
}
// Lspeed=Rspeed=255;//power;
//delay_ms(delay);
}
void sensordetect()
{
sensorflag=1;
while(1)
{
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
for(j=0;j<=9;j++)
if(sensor1[i]==sensor2[i])
sensorflag=0;
if(sensorflag)
{
return;
}
sensorflag=1;
sensor1[0]=PINA.0;
sensor1[1]=PINA.1;
sensor1[2]=PINA.2;
sensor1[3]=PINA.3;
sensor1[4]=PINA.4;
sensor1[5]=PINA.5;
sensor1[6]=PINA.6;
sensor1[7]=PINA.7;
sensor1[8]=PINC.6;
sensor1[9]=PINC.7;
if(PINA.0==0|| PINA.1==0 ||PINA.2==0 ||PINA.3==0 ||PINA.5==0 ||PINA.6==0 ||PINA.7==0 ||PINC.6==0 ||PINC.7==0)
{
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.6==0)
ldev=1;
if(PINA.7==0)
ldev=2;
if(PINC.7==0)
ldev=3;
if(PINC.6==0)
ldev=4;
if(rdev>ldev)
move(R,0,195+12*rdev);
if(rdev<ldev)
move(L,0,195+12*ldev);
if(rdev==ldev)
move(FWD,0,200);
if(PINA.4==0 || PINA.5==0)
move(FWD,0,200);
}
else
{
if(fwdcounter>1)
move(FWD,0,200);
else
{
for(i=0,dirl=0;i<MAX;i++)
{
if(history[i]==L)
dirl++;
}
if(rotpow<160)
rotpow=160;
if(rotpow<255)
rotpow++;
if(dirl>HMAX)
move(CCW,0,rotpow);
else
move(CW,0,rotpow);
}
}
}
}
راستی سنسورامم مثل یه هفت باز هست
(اگه خواستین بگین عکس رباتمم بذارم با روش قرار گرفتن سنسوراش)
راستی توروخدا کمکم کنین من تا اذر بیشتر وقت ندارم !!!!!!!!!!!!!!!!!!
حالا شما بگین باید چی کار کنم
راستی porta ورودی ایسی هم است و portd خروجی ایسی هست(prtd.0 تا portd.5) برنامشم با کدویژن نوشتم
حالا شما میتونین کمکم کنن تا برنامشو درست کنم
اینم متن برناممه
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
Project :
Version :
Date : 2/7/2012
Author : NeVaDa
Company :
Comments:
Chip type : ATmega32A
Program type : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
#include <delay.h>
#define FWD 0b00011110
#define R 0b00011000
#define L 0b00000110
#define CW 0b00011011
#define CCW 0b00110110
#define STOP 0b00000000
#define Rspeed 0b00011011
#define Lspeed 0b00110110
#define MAX 3
#define HMAX 1
// Declare your global variables here
int sensor1[10];
int sensor2[10];
int sensorflag=1,j;
void sensordetect(void);
void move(unsigned char dir,unsigned char delay,unsigned char power);
unsigned char i,rdev,ldev,ip,delay,dir,power,dirl,history[MAX],hcount=0,rotpow;
int fwdcounter=0,ocounter=0;
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTD=0x00;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
while (1)
{
sensor1[0]=PINA.0;
sensor1[1]=PINA.1;
sensor1[2]=PINA.2;
sensor1[3]=PINA.3;
sensor1[4]=PINA.4;
sensor1[5]=PINA.5;
sensor1[6]=PINA.6;
sensor1[7]=PINA.7;
sensor1[8]=PINC.6;
sensor1[9]=PINC.7;
for(j=0;j<=9;j++)
if(sensor1[i]==sensor2[i])
sensorflag=0;
if(sensorflag)
sensordetect();
sensorflag=1;
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
// Place your code here
if(PINA.0==1 || PINA.1==1 ||PINA.2==1 ||PINA.3==1 ||PINA.5==1 ||PINA.6==1 ||PINA.7==1 ||PINC.6==1 ||PINC.7==1)
{
rotpow=255;
ldev=rdev=0;
if(PINA.3==1)
rdev=1;
if(PINA.2==1)
rdev=2;
if(PINA.1==1)
rdev=3;
if(PINA.0==1)
rdev=4;
if(PINA.6==1)
ldev=1;
if(PINA.7==1)
ldev=2;
if(PINC.7==1)
ldev=3;
if(PINC.6==1)
ldev=4;
if(rdev>ldev)
move(R,0,195+12*rdev);
if(rdev<ldev)
move(L,0,195+12*ldev);
if(rdev==ldev)
move(FWD,0,200);
if(PINA.4==1 || PINA.5==1)
move(FWD,0,200);
}
else
{
if(fwdcounter>1)
move(FWD,0,200);
else
{
for(i=0,dirl=0;i<MAX;i++)
{
if(history[i]==L)
dirl++;
}
if(rotpow<160)
rotpow=160;
if(rotpow<255)
rotpow++;
if(dirl>HMAX)
move(CCW,0,rotpow);
else
move(CW,0,rotpow);
}
}
}
}
void move(unsigned char dir,unsigned char delay,unsigned char power)
{
PORTD=dir;
if(dir==L || dir==R )
{
hcount=(hcount+1)%MAX;
history[hcount]=dir;
ocounter++;
if(ocounter>100)
ocounter=100;
if(ocounter>=2)
fwdcounter=0;
}
if(dir==FWD)
{
fwdcounter++;
if(fwdcounter>100)
fwdcounter=100;
if(fwdcounter>=2)
ocounter=0;
}
// Lspeed=Rspeed=255;//power;
//delay_ms(delay);
}
void sensordetect()
{
sensorflag=1;
while(1)
{
sensor2[0]=PINA.0;
sensor2[1]=PINA.1;
sensor2[2]=PINA.2;
sensor2[3]=PINA.3;
sensor2[4]=PINA.4;
sensor2[5]=PINA.5;
sensor2[6]=PINA.6;
sensor2[7]=PINA.7;
sensor2[8]=PINC.6;
sensor2[9]=PINC.7;
for(j=0;j<=9;j++)
if(sensor1[i]==sensor2[i])
sensorflag=0;
if(sensorflag)
{
return;
}
sensorflag=1;
sensor1[0]=PINA.0;
sensor1[1]=PINA.1;
sensor1[2]=PINA.2;
sensor1[3]=PINA.3;
sensor1[4]=PINA.4;
sensor1[5]=PINA.5;
sensor1[6]=PINA.6;
sensor1[7]=PINA.7;
sensor1[8]=PINC.6;
sensor1[9]=PINC.7;
if(PINA.0==0|| PINA.1==0 ||PINA.2==0 ||PINA.3==0 ||PINA.5==0 ||PINA.6==0 ||PINA.7==0 ||PINC.6==0 ||PINC.7==0)
{
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.6==0)
ldev=1;
if(PINA.7==0)
ldev=2;
if(PINC.7==0)
ldev=3;
if(PINC.6==0)
ldev=4;
if(rdev>ldev)
move(R,0,195+12*rdev);
if(rdev<ldev)
move(L,0,195+12*ldev);
if(rdev==ldev)
move(FWD,0,200);
if(PINA.4==0 || PINA.5==0)
move(FWD,0,200);
}
else
{
if(fwdcounter>1)
move(FWD,0,200);
else
{
for(i=0,dirl=0;i<MAX;i++)
{
if(history[i]==L)
dirl++;
}
if(rotpow<160)
rotpow=160;
if(rotpow<255)
rotpow++;
if(dirl>HMAX)
move(CCW,0,rotpow);
else
move(CW,0,rotpow);
}
}
}
}
راستی سنسورامم مثل یه هفت باز هست
(اگه خواستین بگین عکس رباتمم بذارم با روش قرار گرفتن سنسوراش)
راستی توروخدا کمکم کنین من تا اذر بیشتر وقت ندارم !!!!!!!!!!!!!!!!!!
دیدگاه