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;
}
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.
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.
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?
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.