Skip to content

Commit dacdfc9

Browse files
MCUdudefacchinm
authored andcommitted
Add missing 20 MHz clock option (#19)
* Add missing 20 MHz clock option ATmega4809 have an internal 20 MHz clock that can be selected by changing the OSCCFG fuse byte.
1 parent df16dab commit dacdfc9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

cores/arduino/wiring.c

+17-9
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ void init()
274274

275275
int64_t cpu_freq;
276276

277-
#if (F_CPU == 16000000)
277+
#if (F_CPU == 20000000)
278+
cpu_freq = 20000000;
279+
280+
/* No division on clock */
281+
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 0x00);
282+
283+
#elif (F_CPU == 16000000)
278284
cpu_freq = 16000000;
279285

280286
/* No division on clock */
@@ -321,19 +327,21 @@ void init()
321327

322328
#if defined(ADC0)
323329

324-
/* ADC clock between 50-200KHz */
330+
/* ADC clock between 50-200 kHz */
325331

326-
#if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
332+
#if F_CPU >= 20000000 // 20 MHz / 128 = 156.250 kHz
333+
ADC0.CTRLC |= ADC_PRESC_DIV128_gc;
334+
#elif F_CPU >= 16000000 // 16 MHz / 128 = 125 kHz
327335
ADC0.CTRLC |= ADC_PRESC_DIV128_gc;
328-
#elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
336+
#elif F_CPU >= 8000000 // 8 MHz / 64 = 125 kHz
329337
ADC0.CTRLC |= ADC_PRESC_DIV64_gc;
330-
#elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
338+
#elif F_CPU >= 4000000 // 4 MHz / 32 = 125 kHz
331339
ADC0.CTRLC |= ADC_PRESC_DIV32_gc;
332-
#elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
340+
#elif F_CPU >= 2000000 // 2 MHz / 16 = 125 kHz
333341
ADC0.CTRLC |= ADC_PRESC_DIV16_gc;
334-
#elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
342+
#elif F_CPU >= 1000000 // 1 MHz / 8 = 125 kHz
335343
ADC0.CTRLC |= ADC_PRESC_DIV8_gc;
336-
#else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
344+
#else // 128 kHz / 2 = 64 kHz -> This is the closest you can get, the prescaler is 2
337345
ADC0.CTRLC |= ADC_PRESC_DIV2_gc;
338346
#endif
339347

@@ -374,4 +382,4 @@ void init()
374382
sei();
375383
}
376384

377-
void setup_timers(void) __attribute__((weak));
385+
void setup_timers(void) __attribute__((weak));

0 commit comments

Comments
 (0)