   if(mask_count >= mask_delay_ms)  // at 'phase' pulses start the Mask (Duty cycle) timer
   {
     PORTD |= (B10000000);      // Turn on the mask (Duty cycle) clock. From now on no more measurements until next cycle
-    TCCR2B &= !(B00000011);  // Turn off the clock until the new phase clock pulse arrives
+    TCCR2B &= ~(B00000100);  // Turn off the clock until the new phase clock pulse arrives. Deze maakt de code kapot bij een ~, wat eigenlijk zou moeten
     mask_count = 0;
     mask_timer_done = 1;
   }


//#define PSYNC PD2
//#define MARKER_OUT PD7
#define PULSE_CYCLE 24
#define BUF_LENGTH 64
#define MAX_PHASE 1000

  {
    if(mask_timer_done)
    {
      PORTD &= ~(B10000000);      // Turn the mask on
      TCCR2B |= B00000100;     // Turn on the mask (Duty cycle) clock to a 64 prescaler
      TCCR0B &= ~(B00000011);  // Turn off the phase clock until the new pulsetube clock pulse comes in
    }
    else // not finished, the duty cycle time is longer than the pulse tube period.
    {
      TCCR2B &= ~(B00000100);  // Turn off the mask clock
      TCNT2 = 0;               // reset the count
      mask_count = 0;          // reset the mask count
      TCCR2B |= B00000100; // Start the mask timer
