I am currently developing a pulse analyser using a MKR Zero. Starting with “Blink” and “ASCIITable” I can upload the and execute sketches repeatedly without any need to reset. The Pulse analyser needs to use the RTC, Analogue comparator, ADC and DMA. I am using GCLK4 from the 48 MHz clock generator divided by 6 to get 8 MHz for clocking the RTC and ADC prescalers to give the 8 MHz and 2 MHz clocks, respectively. The 48 MHz GCLK0 is used to clock AC-DIG and the GCLK1 (32 kHz) is used to clock AC_ANA.
I get a strange behavior in that after I have executed the sketch that sets-up the clocks the IDE environment does not recognize the board. I need to do a power reset followed by a quick double reset to be abel to upload any sketch from the IDE. Obviously, by redefining the GCLKs I have messed up something. I am wondering what? I know that the Arduino system uses some timers.
So my question is what GCLK can I redefine and which are going to mess up the system?
Digging a little deeper I did find buried in the Arduino environment startup.c file the following useful information.
- \brief SystemInit() configures the needed clocks and according Flash Read Wait States.
- At reset:
- OSC8M clock source is enabled with a divider by 8 (1MHz).
- Generic Clock Generator 0 (GCLKMAIN) is using OSC8M as source.
- We need to:
- Enable XOSC32K clock (External on-board 32.768Hz oscillator), will be used as DFLL48M reference.
- Put XOSC32K as source of Generic Clock Generator 1
- Put Generic Clock Generator 1 as source for Generic Clock Multiplexer 0 (DFLL48M reference)
- Enable DFLL48M clock
- Switch Generic Clock Generator 0 to DFLL48M. CPU will run at 48MHz.
- Modify PRESCaler value of OSCM to have 8MHz
- Put OSC8M as source for Generic Clock Generator 3
I don’t modify the source of Generic Clock Generator 0, 1, 2 or 3. I do redefine GCLK4. Is this used somewhere?
The source code is attached below:
Many thanks if somebody can tell me what stupid thing I am doing wrong.
DPP_v04.ino (17.7 KB)