diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-10-19 09:01:36 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-10-19 09:01:36 +0200 |
commit | 255085d06a75c424cd6b95aaac10056e5de65876 (patch) | |
tree | 345a6bb1772089e4928e88f5035648f82b51531e /src/arch/arduino-nano/arch.cc | |
parent | 458c89d71c3aa22eb5e83d4e34930a8978c0ef7e (diff) |
arduino nano: support additional CPU frequencies
Diffstat (limited to 'src/arch/arduino-nano/arch.cc')
-rw-r--r-- | src/arch/arduino-nano/arch.cc | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/arch/arduino-nano/arch.cc b/src/arch/arduino-nano/arch.cc index b034348..2d957fc 100644 --- a/src/arch/arduino-nano/arch.cc +++ b/src/arch/arduino-nano/arch.cc @@ -5,6 +5,37 @@ void Arch::setup(void) { + +#if F_CPU == 16000000UL + /* default */ +#elif F_CPU == 8000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS0); +#elif F_CPU == 4000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS1); +#elif F_CPU == 2000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS1) | _BV(CLKPS0); +#elif F_CPU == 1000000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2); +#elif F_CPU == 500000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS0); +#elif F_CPU == 250000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS1); +#elif F_CPU == 125000UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS2) | _BV(CLKPS1) | _BV(CLKPS0); +#elif F_CPU == 62500UL + CLKPR = _BV(CLKPCE); + CLKPR = _BV(CLKPS3); +#else +#error Unsupported F_CPU +#endif + #ifdef TIMER_CYCLES TCCR0A = 0; TCCR0B = _BV(CS00); @@ -13,11 +44,14 @@ void Arch::setup(void) #if defined(WITH_LOOP) || defined(TIMER_S) TCCR1A = 0; TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10); // /1024 - OCR1A = 15625; + OCR1A = F_CPU / 1024; TIMSK1 = _BV(OCIE1A); #endif #ifdef TIMER_US +#if F_CPU != 16000000UL +#error TIMER_US is only supported with F_CPU = 16MHz +#endif // 16MHz/8 -> 2MHz timer TCCR2A = 0; TCCR2B = _BV(CS21); |