Society of Robots - Robot Forum

Software => Software => Topic started by: junior000 on February 20, 2008, 12:45:58 PM

Title: using integers for previous value
Post by: junior000 on February 20, 2008, 12:45:58 PM
hi,

  i am using 18f4550 and c18 compiler.one sensor is connected to the port E0.motors are coneected to rc1 rd0 and rd3 rd4.

  problem statement:whenever the sensor detects a black line or switches off, integer i has to increment by 1(all other times the sensor is high).

  PATH:black tapes are arranged horizontally with gap of 20 cm on white surface
 
 
 
here goes my program.......
 
   define an PORTEbits.RE0
   void main()
   {
      int i=0;
      TRISE = 0b00000001;
      TRISC = 0;
       TRISD = 0;
 
       while(1)
      {
 
         while(an==1)
         {
         PORTC = 0b00000000;  //run motors forward
         PORTD = 0b00001001;
 
        }
 
         if(an==0)
         {
          i++;
          }
        while(i==3)
         {
 
        PORTC = 0b00000000; //turn left
        PORTD = 0b00000101;
        some delay;
         i=0;
         }
   }
}
 
         
problem:the bot is running properly.....but it is not responding to the integer i(the direction is not changing)
 
Title: Re: using integers for previous value
Post by: junior000 on February 22, 2008, 01:21:23 AM
should i use local or global variable???
should i specify "unsigned" int i???
Title: Re: using integers for previous value
Post by: Admin on February 23, 2008, 03:04:11 PM
Are you sure your variable 'an' ever changes to 0?

Also if an starts out as 1, then this is an infinite loop:
Code: [Select]
while(an==1)
         {
         PORTC = 0b00000000;  //run motors forward
         PORTD = 0b00001001;
        }
Title: Re: using integers for previous value
Post by: paulstreats on February 23, 2008, 07:19:57 PM
This is solved in a PM. The code simulates fine - its a problem with either sensor input or lack of power.

Hey Junior000, Im not getting on your back or anything but if you have a problem thats resolved you really should post a solution for other people that have the same problem
Title: Re: using integers for previous value
Post by: junior000 on February 26, 2008, 07:08:22 AM
yeah..i should have posted this earlier

the problem was with the power supply.the bot is working fine.