Hallo

Code:
#include "RP6RobotBaseLib.h"    // The RP6 Robot Base Library.

int main(void)
{
   initRobotBase();
   writeString_P("Do some LED stuff!\n");
   startStopwatch1();

   uint8_t runningLight = 9;
   uint16_t stopVal = 0;

   while(true)
   {
      cli();
		stopVal = getStopwatch1();
		sei();
      if (stopVal > 600)
      {
         writeInteger(getStopwatch1(), DEC);
         writeChar('\n');
         writeInteger(stopVal, DEC);
         writeChar('\n');
         writeChar('\n');

         setLEDs(runningLight);
         runningLight <<= 1;
         if(runningLight > 36)
            runningLight = 9;
         setStopwatch1(0);
      }

   }

   return 0;
}
Genau bei stopVal = getStopwatch1(); tritt ein ISR-Aufruf auf. Das Highbyte der StopWatch ist schon erhöht, das Lowbyte noch nicht:

511 ist binär 01 11111111
512 ist binär 10 00000000
767 ist binär 10 11111111

Deshalb ist stopVal größer als 600 und die Stoppuhr aber immer noch kleiner als 600 ;)

Das Stichwort heißt "atomar".

Eigentlich logisch, aber das hat bisher noch keiner bemerkt. Glückwunsch!

Gruß

mic

[Edit]
Code:
#include "RP6RobotBaseLib.h"    // The RP6 Robot Base Library.

int main(void)
{
   initRobotBase();
   startStopwatch1();

   while(true)
   {
      if (getStopwatch1() > 600)
      {
         writeInteger(getStopwatch1(), DEC);
         if(getStopwatch1() < 601) writeChar('*');
         writeChar('\n');
         setStopwatch1(0);
      }
   }
   return 0;
}
Code:
#include "RP6RobotBaseLib.h"    // The RP6 Robot Base Library.

int main(void)
{
   initRobotBase();
   startStopwatch1();

   while(true)
   {
      cli();
		if (getStopwatch1() > 600)
      {
         sei();
			writeInteger(getStopwatch1(), DEC);
         if(getStopwatch1() < 601) writeChar('*');
         writeChar('\n');
         setStopwatch1(0);
      }
      else sei();
   }
   return 0;
}
Schlanker und schneller wäre wohl ein schlichtes

}
sei();

anstelle von

}
else sei();