View Single Post
  #4   Spotlight this post!  
Unread 07-02-2004, 02:00
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Re: IR reflective (tape) sensor code problems

Quote:
Originally Posted by deltacoder1020
where are you declaring "counter" and "endprogram"? if they are outside a function, you probably need to initialize them somewhere else (i.e. don't put the =0 part in, instead assign them the value of 0 in User_Initialization or somewhere there).

if they are in the function, add "static" in front of "int", so that it reads "static int counter" and "static short endprogram" - you don't want the values reset every time the function is called.

it does seem that the counter is working at least somewhat decently, though, as it is waiting for 15 seconds... could you post the code that comes after the IR part?
Their code is correct..

You can initialize global variables and set values like so
int ROAAAR = 0;

I usually do
Code:
void blah(void)
{
  static int x = 0; 
}
though.

Personally, I recommend keeping the programming port connected and having a debug statement every 10 loops showing the values of PWMs, etc...

sample
Code:
// Paste top
//in the code, comment out to turn off debug
#define DEBUG_ALL

#ifdef DEBUG_ALL
unsigned int _debug_counter = 0;  // 0-65535 then rollover
#define debug_all(pulses, type)                                                            \
      {                                                                                    \
         if (_debug_counter % pulses == 0)                                                 \
         {                                                                                 \
            switch(type)                                                                   \
            {                                                                              \
            case 1:                                                                        \
               printf("PWM01 = %d, PWM02 = %d...\n", pwm01, pwm02);                        \
               break;                                                                      \
            case 2:                                                                        \
               printf("PWM03 = %d, PWM04 = %d...\n", pwm01, pwm02);                        \
               break;                                                                      \
            case 3:                                                                        \
               printf("rc_dig_out01 %d, rc_dig_out02.\n",                                  \
	       (int)rc_dig_out01, (int)rc_dig_out02);                                      \
               break;                                                                      \
	    default:                                                                       \
	       printf("Invalid type.\n");                                                  \
            }                                                                              \
         }                                                                                 \
      }
#else
#define debug_all(pulses, type) \
   { \
   }
#endif
// End paste top


// every loop call
void Process_Data_From_Master_uP(void)
{
  Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
+ #ifdef DEBUG_ALL
+    _debug_counter++;
+ #endif
  //blah...

//code to call debug_all(numloops, type)
+   debug_all(10, 1);
+   debug_all(100, 2);
+   debug_all(50, 3);
}
That works for me. I like this approach because it doesn't waste memory when DEBUG_ALL is not defined, the code is not compiled in when DEBUG_ALL is set. I'll probably tie into the standard debugging and make the default code's debugging more efficient later. When your running the code even while not debugging, the default code has debugging built in and compiled wasting memory. I decided to post this because it shows a lot of the macro capabilities allowing you to emulate reference variables to a degree.

Thanks,
Ryan Waliany
__________________
R

Last edited by rwaliany : 07-02-2004 at 02:05.