I wanted develop up a measurement system based on an Uno R4 Minima for some specific reasons (e. g. 24V supply, integrated DAC, footprint, resolution of micros() command etc.). While Susan Parker shows that the HOCO is very precise in the R4 Minima that she measured, the official spec says +/-1% within -20...+85C, which wouldn't be good enough for my purposes. I wanted to fit a crystal resonator to the board and use the MOSC as system clock input (at 48MHz). I found a R4 Minima clone with a 16MHz crystal already fitted (Arduino Uno R4 minima Clone - OTRONIC). Perfect for some trials, once again many thanks to Susan Parker for all the work and the insights you shared!!! Funfact: Reading out the clock registers of the R7FA4M1 on this clone (see Susan's post here: "Overclock" the R4 family - #3 by susan-parker) showed that it runs in HOCO mode and doesn't make any use of the crystal at all (they could leave it away ...). But having it on board, I tried the following:
Run with 16MHz input to MOSC, no PLL (i. e. ICK at 16MHz): works fine but of course at 1/3 of speed:
*SYSTEM_PRCR = 0xA501; // enable writing to clock registers
*SYSTEM_MOMCR = 0x0; // set oscillator mode to 10..20MHz and resonator
*SYSTEM_MOSCCR = 0x0; // set main oscillator running
while(*SYSTEM_MOSCCR != 0x0) {} // wait until updated
while(*SYSTEM_OSCSF & 0b00001000 == 0) {} // wait until MOSC stable
*SYSTEM_SCKSCR = 0x3; // select main clock
*SYSTEM_PRCR = 0xA500; // disable writing to clock registers
Run with 16MHz input to MOSC, PLLMUL = 12; PLLDIV = 4 (i. e. ICK at 48MHz): works fine but violates spec (PLL input > 12.5MHz):
*SYSTEM_PRCR = 0xA501; // enable writing to clock registers
*SYSTEM_MOMCR = 0x0; // set oscillator mode to 10..20MHz and resonator
*SYSTEM_MOSCCR = 0x0; // set main oscillator running
while(*SYSTEM_MOSCCR != 0x0) {} // wait until updated
while(*SYSTEM_PLLCR != 0x1) {} // confirm that PLL is stopped
while(*SYSTEM_OSCSF >> 1 != 0b0000100) {} // wait until MOSC stable and PLL stable off
*SYSTEM_PLLCCR2 = 0b10001011; // set PLL *12 / 4
delayMicroseconds(8);
*SYSTEM_PLLCR = 0x0; // start PLL
while(*SYSTEM_OSCSF >> 1 != 0b0010100) {} // wait until MOSC stable and PLL stable
*SYSTEM_SCKSCR = 0b101; // select main clock PLL
*SYSTEM_PRCR = 0xA500; // disable writing to clock registers
Run with 16MHz input to MOSC, PLLMUL = 6; PLLDIV = 2 (i. e. ICK at 48MHz): works fine but violates spec (PLL input > 12.5MHz and PLLMUL < 8):
*SYSTEM_PLLCCR2 = 0b01000101; // set PLL *6 / 2
To stay within all specs I then substituted the 16MHz by a 12MHz crystal (I felt quite brave as it was my first real SMD soldering ever
) and run with 12MHz input to MOSC, PLLMUL = 8; PLLDIV = 2 (i. e. ICK at 48MHz): works fine and doesn't violate any spec:
*SYSTEM_PLLCCR2 = 0b01000111; // set PLL *8 / 2
dela(), millis() and micros() work as expected, accuracy I will try to check next.
Maybe this helps those who try to fiddle around with the clocks and crystals ...