Answered: mlab / mcc variable usage problems.

Ricky,

If you look down at the comment with your name on it you will get a description of the problem. Basically if I attempt to update the s_elapsed
or s_loop variables the initial value do not seem to be zero when loop starts

Thanks,
-Tom-


void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
pwm01 = pwm02 = pwm03 = pwm04 = 127;
pwm05 = pwm06 = pwm07 = pwm08 = 127;
pwm09 = pwm10 = pwm11 = pwm12 = 127;

s_elapsed = 0UL;
s_loop = 0UL;
s_elapsed_start = 0UL;

#ifdef ZI_MAIN_LOOP_LOGGING
printf(“entering autonomous mode loop(%04X): %d elapsed(%04X): %d\r”, (char*)&s_loop, s_loop, (char*)&s_elapsed, s_elapsed);
#endif

while (autonomous_mode)   /* DO NOT CHANGE! */
{
    if (statusflag.NEW_SPI_DATA)      /* 18.5ms loop area */
    {
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */

#ifdef ZI_MAIN_LOOP_LOGGING
printf(“completed getdata loop(%06X): %d elapsed(%06X): %d\r”, (char*)&s_loop, s_loop, (char*)&s_elapsed, s_elapsed);
#endif

#ifndef ZI_HANDLE_ENCODER_TICKS
HandleEncoderTicks();
#endif

#ifdef ZI_MAIN_LOOP_LOGGING
printf(“prior to putdata loop(%06X): %d elapsed(%06X): %d\r”, (char*)&s_loop, s_loop, (char*)&s_elapsed, s_elapsed);
#endif

        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */

#ifdef ZI_MAIN_LOOP_LOGGING
printf(“completed putdata loop(%06X): %d elapsed(%06X): %d\r”,(char*)&s_loop, s_loop, (char*)&s_elapsed, s_elapsed);
#endif

        PrintWord(s_loop);
        PrintWord(s_elapsed);
        
        // Ricky: If I include these line in the code the initial values of
        // of s_elapsed and s_loop do not seem to be zero from the 
        // logging. But if I comment these lines out compile and run the
        // values do seem to be zero from the logging output.   
        s_elapsed = s_elapsed + 18UL;
        s_loop++;
    }
}

}