Why does millis() not work on ATTINY85

Can anyone help with this code. Looks like the millis() function is not working for ATTINY85. It never leaves the while loop in the sketch below with the millis() function to wait for a period of time.

uint8_t Level[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
uint8_t Order[8] = {0, 1, 2, 5, 4, 3, 7, 6 };

unsigned long beginTime = 0;
unsigned long endTime = 0;
unsigned long roundTime = 8000;
const int numled = 8;
unsigned long cycleTime = roundTime / numled / 64 ;


// Timer/Counter1 overflow interrupt
ISR(TIM1_COMPA_vect) {
  static uint8_t first, ramp, column, bits, colbit;
  ramp = (ramp+1) & 0x3F;             // Count from 0 to 63
  if (ramp == 0) {
    bits = 0x07;                      // All on
    column = (column + 1) & 0x03;
    first = column * 3;               // First LED in this column
    colbit = 1<<column;
  }

  if (Level[first] == ramp) bits = bits & 0x06;
  if (Level[first+1] == ramp) bits = bits & 0x05;
  if (Level[first+2] == ramp) bits = bits & 0x03;
  uint8_t mask = colbit - 1;
  uint8_t outputs = (bits & mask) | (bits & ~mask)<<1;
  DDRB = outputs | colbit;
  PORTB = outputs;
}

void setup() {

  // Set up Timer/Counter1 to multiplex the LEDs
  TCCR1 = 1<<CTC1 | 2<<CS10;          // Divide by 2
  GTCCR = 0;                          // No PWM
  OCR1A = 0;
  OCR1C = 250-1;                      // 16kHz
  TIMSK = TIMSK | 1<<OCIE1A;          // Compare Match A interrupt
}

void loop () {
  uint8_t temp = Level[Order[numled-1]];
  for (int i=numled-1; i>=0; i--){   
       for (int p=0; p<=63; p++) {
            beginTime = millis();
            Level[Order[i]] = p;
            if (i==numled-1) { 
                Level[0]=63-p;
              } else { 
                Level[Order[i+1]] = 63-p;
              }
            endTime = millis();
            while(endTime <= beginTime+cycleTime) {
              // Stay's in this loop for ever.....
              endTime = millis();
              }
       }
  }
  Level[Order[0]] = temp;      
}

Could you please, please, please edit your code and apply code tags around the code in your post? Pleaae?

Might was well use delay().

I do have 8 led. I want to make rounds of exact 8 sec or 7 sec or 6 sec. I have to calculate the delay for each step so I wondered it's more easy to use the milles() function.
I am running on 8MHz.

See post #2.

Figured the formatting out. Sorry, new here.

What do you want that code to do?

I got 8 led in a charlieplexing config using 4 outputs of the ATTiny85. I let 1 led glow up and the previous one glow down and make a round for a small lighthouse. I want this to happen in 8 seconds for all leds. So one cycle takes up 8000 millisec / 8 led / 64 steps.

The interrupt is handeling the values and order set in the loop.

I don't get the timing right. The board is running at 8Mhz.

So one cycle should be 8000/8/64 = 15 millisec. But when i put in a delay of 15 it runs to fast. It needs to be 1800. Don't understand why.

Thanks for looking into it.

So you got 64 LEDs connected to 4 GPIO pins and you want the LEDs to simulate the spinning light of a light house and you want the whole thing to take 8 seconds, right?

It got 8 LED's. Level[7] in the code attached on p0 - p4 on charlieplexing. Interrupt makes 64 devisions for PWM based on interrupt on timer(1).

So 8 lights in a circle going round in 8 sec. Pulsing from 0 - full and fading from full to 0 on each led. So there is always light.

And you want loop to run once every 8 seconds. Or you want this loop to only run once every 8 seconds?

Using millis() cause you need interrupts to be active at all times.

I want a full round loop run of 8 lights in 8 seconds. In the future i want to ajust it by increments of 1 sec by pulling p4 high.

8 lights in 8 seconds so one light per second, correct?

So you want that code to run one time a second?

yes. Strangly I need to put in delay(1800) to let this happen. I don't get it.

Something like that, not tested.

int LEDinProgress =0;
unsigned long Duration = 8000;
unsigned long TimePast = Duration;
void loop () 
{
  uint8_t temp = Level[Order[numled-1]];
  
  
  if ( millis() - TimePast >= Duration )
  {
       for (int p=0; p<=63; p++) {
            Level[Order[LEDinProgress]] = p;
            if LEDinProgress==numled-1) { 
                Level[0]=63-p;
              } else { 
                Level[Order[LEDinProgress+1]] = 63-p;
              }
       }
	   TimePast = millis();
	   LEDinProgress++;
	   if ( LEDinProgress >= 8 )
	   {
	   LEDinProgress = 0;
	   }
  }

  
  Level[Order[0]] = temp;      
}

Nu is maar een Led aan. Lijkt er op dat Millis() niet werkt.

Probleem met deze code is dat hij heel snel tot 8x gaat en dan wacht. De 8 seconden is niet over alle led's verdeeld.

Did you click "Burn bootloader" at 8MHz? ATtiny85 come from the factory set to 1MHz. If you upload a sketch to run at 8MHz without first clicking "Burn bootloader", the operation of delay() and millis() will not be correct.

Good question. I used this link: inhoud - Bootloader installeren op de ATTiny85 - Opencircuit. I don't see any settings there. The example below is resulting in a zero so millis() is not working. I don't burn before uploading. It's not possible also because my programmer USB is only avail after compile for short time.

             beginTime = millis();
             delay(1800);
             endTime = millis();

             if ( endTime - beginTime == 0) { Level[Order[0]] = 63;}
             if ( endTime - beginTime > 0) { Level[Order[1]] = 63; }
             if ( endTime - beginTime > 100) { Level[Order[2]] = 63; }
             if ( endTime - beginTime > 1000) { Level[Order[3]] = 63; }
             if ( endTime - beginTime > 1500) { Level[Order[4]] = 63; }
             if ( endTime - beginTime > 2000) { Level[Order[5]] = 63; }

How do you expect millis() to work when the CPU is doing NOOPS?

And that's not how to use millis().