Allow wider range of clocks
This commit is contained in:
parent
fa12096630
commit
7c5fd66f92
7
Makefile
7
Makefile
|
@ -12,9 +12,9 @@ LDFLAGS += -mmcu=$(MCU)
|
||||||
AVDFLAGS += -p $(MCU)
|
AVDFLAGS += -p $(MCU)
|
||||||
AVDFLAGS += -c usbtiny
|
AVDFLAGS += -c usbtiny
|
||||||
|
|
||||||
CLOCK_HZ = 16000000
|
CLOCK_HZ = 2000000
|
||||||
FUSES += -U lfuse:w:0xff:m
|
FUSES += -U lfuse:w:0x7f:m
|
||||||
FUSES += -U hfuse:w:0xd9:m
|
FUSES += -U hfuse:w:0xdd:m
|
||||||
FUSES += -U efuse:w:0xff:m
|
FUSES += -U efuse:w:0xff:m
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ fuses:
|
||||||
avrdude $(AVDFLAGS) $(FUSES)
|
avrdude $(AVDFLAGS) $(FUSES)
|
||||||
|
|
||||||
main: main.o avr.o
|
main: main.o avr.o
|
||||||
|
avr.o: CFLAGS += -DCLOCK_HZ=$(CLOCK_HZ)
|
||||||
|
|
||||||
$(PROG).hex: $(PROG)
|
$(PROG).hex: $(PROG)
|
||||||
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||||
|
|
11
avr.c
11
avr.c
|
@ -4,9 +4,8 @@
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include "avr.h"
|
#include "avr.h"
|
||||||
|
|
||||||
/* This only works out for a 16MHz or 8MHz clock */
|
/* Clock must be a multiple of 2MHz or there will be clock drift */
|
||||||
#define CLOCK_HZ 16000000
|
#define TICKS_PER_SECOND (CLOCK_HZ / 64)
|
||||||
#define TICKS_PER_SECOND (CLOCK_HZ / 256)
|
|
||||||
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10)
|
#define TICKS_PER_JIFFY (TICKS_PER_SECOND / 10)
|
||||||
|
|
||||||
#define cbi(byt, bit) (byt &= ~_BV(bit))
|
#define cbi(byt, bit) (byt &= ~_BV(bit))
|
||||||
|
@ -34,9 +33,9 @@ init(void)
|
||||||
TCCR1B = 0;
|
TCCR1B = 0;
|
||||||
TCNT1 = 0;
|
TCNT1 = 0;
|
||||||
OCR1A = TICKS_PER_JIFFY - 1;
|
OCR1A = TICKS_PER_JIFFY - 1;
|
||||||
TCCR1B |= (1 << WGM12);
|
TCCR1B |= _BV(WGM12);
|
||||||
TCCR1B |= (1 << CS12);
|
TCCR1B |= _BV(CS11) | _BV(CS10);
|
||||||
TIMSK1 |= (1 << OCIE1A);
|
TIMSK1 |= _BV(OCIE1A);
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
4
avr.h
4
avr.h
|
@ -5,10 +5,6 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
// Make sure JIFFY_uS is going to be an integer and not a float!
|
|
||||||
#define JIFFIES_PER_SECOND 100
|
|
||||||
#define JIFFY_uS (1000000 / JIFFIES_PER_SECOND)
|
|
||||||
|
|
||||||
#define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit))
|
#define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit))
|
||||||
|
|
||||||
#define mode(on) bit(PORTA, _BV(0), on)
|
#define mode(on) bit(PORTA, _BV(0), on)
|
||||||
|
|
34
main.c
34
main.c
|
@ -133,7 +133,7 @@ draw()
|
||||||
if ((state == TIMEOUT) && (jam_clock % 8 == 0)) {
|
if ((state == TIMEOUT) && (jam_clock % 8 == 0)) {
|
||||||
// Blank it out
|
// Blank it out
|
||||||
for (clk = 0; clk < 4; clk += 1) {
|
for (clk = 0; clk < 4; clk += 1) {
|
||||||
write(0);
|
write(setup_digits[1]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clk = (abs(period_clock / 10) / 60) * 100;
|
clk = (abs(period_clock / 10) / 60) * 100;
|
||||||
|
@ -254,24 +254,22 @@ loop()
|
||||||
PORTB ^= 0xff;
|
PORTB ^= 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jiffies == 0) {
|
switch (state) {
|
||||||
switch (state) {
|
case SETUP:
|
||||||
case SETUP:
|
break;
|
||||||
break;
|
case JAM:
|
||||||
case JAM:
|
case LINEUP:
|
||||||
case LINEUP:
|
if (period_clock) {
|
||||||
if (period_clock) {
|
period_clock += 1;
|
||||||
period_clock += 1;
|
}
|
||||||
}
|
// fall through
|
||||||
// fall through
|
case TIMEOUT:
|
||||||
case TIMEOUT:
|
if (jam_clock) {
|
||||||
if (jam_clock) {
|
jam_clock += 1;
|
||||||
jam_clock += 1;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue