go away spammer

Author Topic: programming problem  (Read 2365 times)

0 Members and 1 Guest are viewing this topic.

Offline superchikuTopic starter

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
programming problem
« on: March 08, 2008, 12:42:02 PM »
well i made this program for the line following bot i set the adc's prescaler at 8 and timers prescaler at 8 and also adc's voltage reference to AVCC (iam not using crystal and my mcu is atmega16 running at 1mhz) now when i loaded program i tested my pwm channels and i was getting around 3.78 v its cool i needed that much but the problem is i did not connect and sensors so the adc's must be getting 0 v reading but according to my program if i get a value more than 98(nearly 1.5v) i should get pwm of 3.78v but without the adc i shouldnt get any pwm but here iam getting ...can u tell me what is the problem?????

PS:i havent connected aref and gnd with a capacitor do u think that is  a problem?? also my adc is in auto trigger mode and when i say motor left2 i mean iam turning more to the left than iam turning in motorleft1.....

for better reference i have pasted my code
/* normal header files included*/
# include<stdio.h>
# include<avr/io.h>
# include<util/delay.h>

//defining pwm values for different level of input adc values left1,left2,right1,right2 specify how much the bot should turnleft2>left1*/
# define motorleft1 127
# define motorleft2 130
# define motorright1 127
# define motorright2 130
# define motorstraight 215
# define threshold 98

void motorleft1turn();
void motorleft2turn();
void motorright1turn();
void motorright2turn();
void motorallstraight();
void timerallinit();
void adcinitialize();
void adcgetvalue();
void directioninputinitialize();

unsigned int analog1,analog2,analog3;

int main(void)
 {
  timerallinit();
  adcinitialize();
  directioninputinitialize();
  while(1)
   {
    adcgetvalue();
    if(analog1>98 && analog2>98 && analog3>98)
     {
      if(analog1<threshold && analog2>threshold && analog3>threshold)
       {
       motorright1turn();
       }
      if(analog1<threshold && analog2<threshold && analog3>threshold)
       {
        motorright2turn();
       }
      if(analog1>threshold && analog2>threshold && analog3<threshold)
       {
        motorleft1turn();
       }
      if(analog1>threshold && analog2<threshold && analog3<threshold)
       {
        motorleft2turn();
       }
      if(analog1>threshold && analog2>threshold && analog3>threshold)
       {
        motorallstraight();
       }
   
       }
    }
 return(1);
}

void timerallinit()
 {
  TCCR0|=_BV(6)|_BV(3)|_BV(5)|_BV(1);
  TCCR2|=_BV(6)|_BV(3)|_BV(5)|_BV(1);
  DDRD=0x80;
  DDRB=0x08;
 
 }
void adcinitialize()
 {
  ADCSRA|=_BV(7)|_BV(6)|_BV(5)|_BV(1)|_BV(0);
  SFIOR=0x00;
  ADMUX=0x60;
  analog1=ADCH;
 }
void adcgetvalue()
 {
  ADMUX=0x60;
  analog1=ADCH;
  _delay_ms(5);
  ADMUX=0x61;
  analog2=ADCH;
  _delay_ms(5);
  ADMUX=0x63;
  analog3=ADCH;
  _delay_ms(5);
 }
 
void motorleft1turn()
 {
  OCR0=motorleft1;
  OCR2=motorstraight;
 }
 
void motorleft2turn()
 {
  OCR0=motorleft2;
  _delay_ms(0.5);
  OCR2=motorstraight;
 }
 
void motorright1turn()
 {
  OCR0=motorstraight;
  OCR2=motorright1;
 }
void motorright2turn()
 {
  OCR0=motorstraight;
  OCR2=motorright2;
  _delay_ms(0.5);
 }
void motorallstraight()
 {
  OCR0=motorstraight;
  OCR2=motorstraight;
 }
void directioninputinitialize()
 {
 
  DDRD|=_BV(6)|_BV(5)|_BV(3)|_BV(2);
  PORTD|=(1<<5)|(1<<2);
  }
 
 
 
 
   
« Last Edit: March 08, 2008, 01:47:04 PM by superchiku »
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: programming problem
« Reply #1 on: March 09, 2008, 01:52:47 PM »
Um . . . I completely didn't understand that painfully disorganized really long run on sentence you got there . . .

I have no idea what is or isn't working or even what you are trying to do based on that sentence :P

Try and break it up a bit into understandable chunks, explaining what you want it to do, what you did to get that to happen, exactly what isn't working, and what you did to debug the problem.

Offline superchikuTopic starter

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: programming problem
« Reply #2 on: March 23, 2008, 12:12:59 AM »
sorry for not writing clearly, no problem now as i have completed my bot and the code works perfectly

but iam still not able to know how the pwm values for 2 different timers  differ so much even though they are initialized the same way
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

 


Get Your Ad Here