Disable CKDIV8
and adapt to clock div. factor
Configure fuses for the `fuses` target in Makefile to disable `CKDIV8`. Adapt PWM generation in `lcd_update_backlight()` to new clock division factor, as well as interrupt handling, debouncing and dechattering. This also enables partially lower PWM frequencies (between off and former lowest PWM setting) for a dimmer lcd backlight.
This commit is contained in:
parent
c48e4a31ab
commit
bd217ce6e7
2 changed files with 26 additions and 17 deletions
|
@ -9,6 +9,7 @@ EEP := main.eep
|
||||||
BIN := main.elf
|
BIN := main.elf
|
||||||
OBJ := main.o
|
OBJ := main.o
|
||||||
|
|
||||||
|
LOW_FUSE := 0xE2
|
||||||
HIGH_FUSE := 0xD6
|
HIGH_FUSE := 0xD6
|
||||||
|
|
||||||
SHELL := sh
|
SHELL := sh
|
||||||
|
@ -42,7 +43,7 @@ eeprom: $(EEP) size
|
||||||
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U eeprom:w:$<:a
|
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U eeprom:w:$<:a
|
||||||
|
|
||||||
fuses:
|
fuses:
|
||||||
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U hfuse:w:$(HIGH_FUSE):m
|
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U lfuse:w:$(LOW_FUSE):m -U hfuse:w:$(HIGH_FUSE):m
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET) $(EEP) $(BIN) $(OBJ)
|
$(RM) $(TARGET) $(EEP) $(BIN) $(OBJ)
|
||||||
|
|
|
@ -194,10 +194,20 @@ static void lcd_update_backlight(void) {
|
||||||
case 0:
|
case 0:
|
||||||
DDRD &= (0 << PD5);
|
DDRD &= (0 << PD5);
|
||||||
break;
|
break;
|
||||||
default:
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
TCCR0B = 0x0C; // prescaler = 256;
|
||||||
DDRD |= (1 << PD5);
|
DDRD |= (1 << PD5);
|
||||||
OCR0B = value_backlight - 1;
|
OCR0B = value_backlight - 1;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
TCCR0B = 0x0B; // prescaler = 64;
|
||||||
|
DDRD |= (1 << PD5);
|
||||||
|
OCR0B = value_backlight - 4;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +608,7 @@ ISR(PCINT0_vect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: proper dechattering
|
// TODO: proper dechattering
|
||||||
_delay_us(100);
|
_delay_ms(3);
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
@ -607,19 +617,19 @@ ISR(PCINT0_vect) {
|
||||||
ISR(PCINT1_vect) {
|
ISR(PCINT1_vect) {
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
if (PINC & (1 << PC0)) { // release
|
if (PINC & (1 << PC0)) { // Release
|
||||||
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
|
if (TCCR1B & (1 << CS10)) // If release before hold
|
||||||
if (TCNT1 != 0) {
|
|
||||||
update_state(click); // Switch to selected state
|
update_state(click); // Switch to selected state
|
||||||
TCNT1 = 0;
|
|
||||||
}
|
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
|
||||||
} else { // press
|
} else { // Press
|
||||||
|
TCNT1 = 0;
|
||||||
if (!(TCCR1B & (1 << CS10)))
|
if (!(TCCR1B & (1 << CS10)))
|
||||||
TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1
|
TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: proper debouncing
|
// TODO: Proper debouncing
|
||||||
_delay_us(70);
|
_delay_ms(3);
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
@ -629,7 +639,6 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
|
TCCR1B &= (0 << CS11) & (0 << CS10); // Disable Timer/Counter1
|
||||||
TCNT1 = 0;
|
|
||||||
update_state(hold);
|
update_state(hold);
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
@ -643,8 +652,7 @@ int main(void) {
|
||||||
// Init backlight: FastPWM: 1.25kHz
|
// Init backlight: FastPWM: 1.25kHz
|
||||||
// TODO: Try to get the backlit even more dim
|
// TODO: Try to get the backlit even more dim
|
||||||
TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
||||||
TCCR0B |= (1 << CS01) | (1 << WGM02); // prescaler = 8;
|
OCR0A = 255;
|
||||||
OCR0A = 100;
|
|
||||||
lcd_update_backlight();
|
lcd_update_backlight();
|
||||||
|
|
||||||
// SPI setup
|
// SPI setup
|
||||||
|
@ -661,13 +669,13 @@ int main(void) {
|
||||||
PCICR |= (1 << PCIE1);
|
PCICR |= (1 << PCIE1);
|
||||||
PCMSK1 |= (1 << PCINT8);
|
PCMSK1 |= (1 << PCINT8);
|
||||||
|
|
||||||
// Timer1 setup to recognize held button
|
// Timer/Counter1 setup to recognize held button
|
||||||
OCR1A = 8192;
|
OCR1A = 65535;
|
||||||
TIMSK1 |= (1 << OCIE1A); // Enable match compare A
|
TIMSK1 |= (1 << OCIE1A); // Enable match compare A
|
||||||
|
|
||||||
// Show splash screen and load the menu
|
// Show splash screen and load the menu
|
||||||
lcd_splash();
|
lcd_splash();
|
||||||
_delay_ms(250);
|
_delay_ms(2000);
|
||||||
change_state(current_state);
|
change_state(current_state);
|
||||||
|
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
|
|
Loading…
Reference in a new issue