Skip to content

Commit db32b3f

Browse files
committed
samd51: DAC: Make clock usage more like Arduino core
This improves the behavior around adafruit#1992. The samples stay in sync now, though full scale changes still behave erratically. Testing performed: On a Metro M4, with both analog channels going to a scope, I looked for synchronization and waveform shape. Original reproducer: Stays synchronized. adafruit#1992 (comment) reproducer: Stays synchronized and plays at the nominal 100kHz sample rate. However, waveform peaks are "regularly irregular", with every other high peak being truncated, usually. A difference I'm aware of between this and Arduino's M4 core is that Arduino uses CCTRL_CC100K; however, doing this makes CP worse, so I went with the more "correct" CC12M setting.
1 parent 30a9346 commit db32b3f

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

ports/atmel-samd/asf4_conf/samd51/hpl_dac_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// <i> This defines the current in output buffer according to conversion rate
5252
// <id> dac0_arch_cctrl
5353
#ifndef CONF_DAC0_CCTRL
54-
#define CONF_DAC0_CCTRL 1
54+
#define CONF_DAC0_CCTRL 2
5555
#endif
5656

5757
// <q> Run in standby
@@ -90,7 +90,7 @@
9090
// <i> This defines the current in output buffer according to conversion rate
9191
// <id> dac1_arch_cctrl
9292
#ifndef CONF_DAC1_CCTRL
93-
#define CONF_DAC1_CCTRL 1
93+
#define CONF_DAC1_CCTRL 2
9494
#endif
9595

9696
// <q> Run in standby

ports/atmel-samd/asf4_conf/samd51/hpl_gclk_config.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Circuit Python SAMD51 clock tree:
2-
// DFLL48M (with USBCRM on to sync with external USB ref) -> GCLK1, GCLK5
2+
// DFLL48M (with USBCRM on to sync with external USB ref) -> GCLK1, GCLK4, GCLK5
33
// GCLK1 (48MHz) -> 48 MHz peripherals
4-
// GCLK5 (48 MHz divided down to 2 MHz) -> DPLL0, DAC peripherals
4+
// GCLK4 (48MHz divded down to 12MHz) -> DAC
5+
// GCLK5 (48 MHz divided down to 2 MHz) -> DPLL0 peripheral
56
// DPLL0 (multiplied up to 120 MHz) -> GCLK0, GCLK4 (output for monitoring)
67

78
// We'd like to use XOSC32K as a ref for DFLL48M on boards with a 32kHz crystal,
@@ -338,7 +339,7 @@
338339
// <i> This defines the clock source for generic clock generator 4
339340
// <id> gclk_gen_4_oscillator
340341
#ifndef CONF_GCLK_GEN_4_SOURCE
341-
#define CONF_GCLK_GEN_4_SOURCE GCLK_GENCTRL_SRC_DPLL0
342+
#define CONF_GCLK_GEN_4_SOURCE GCLK_GENCTRL_SRC_DFLL
342343
#endif
343344

344345
// <q> Run in Standby
@@ -388,7 +389,7 @@
388389
//<o> Generic clock generator 4 division <0x0000-0xFFFF>
389390
// <id> gclk_gen_4_div
390391
#ifndef CONF_GCLK_GEN_4_DIV
391-
#define CONF_GCLK_GEN_4_DIV 1
392+
#define CONF_GCLK_GEN_4_DIV 4
392393
#endif
393394
// </h>
394395
// </e>

ports/atmel-samd/asf4_conf/samd51/peripheral_clk_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@
7373
// <id> dac_gclk_selection
7474
// <i> Select the clock source for DAC.
7575
#ifndef CONF_GCLK_DAC_SRC
76-
#define CONF_GCLK_DAC_SRC GCLK_PCHCTRL_GEN_GCLK5_Val
76+
#define CONF_GCLK_DAC_SRC GCLK_PCHCTRL_GEN_GCLK4_Val
7777
#endif
7878

7979
/**
8080
* \def CONF_GCLK_DAC_FREQUENCY
8181
* \brief DAC's Clock frequency
8282
*/
8383
#ifndef CONF_GCLK_DAC_FREQUENCY
84-
#define CONF_GCLK_DAC_FREQUENCY 2000000
84+
#define CONF_GCLK_DAC_FREQUENCY 12000000
8585
#endif
8686

8787
// <y> EVSYS Channel 0 Clock Source

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
198198
#endif
199199
#ifdef SAMD51
200200
DAC->EVCTRL.reg |= DAC_EVCTRL_STARTEI0;
201-
DAC->DACCTRL[0].reg = DAC_DACCTRL_CCTRL_CC1M |
201+
DAC->DACCTRL[0].reg = DAC_DACCTRL_CCTRL_CC12M |
202202
DAC_DACCTRL_ENABLE |
203203
DAC_DACCTRL_LEFTADJ;
204204
DAC->CTRLB.reg = DAC_CTRLB_REFSEL_VREFPU;
@@ -207,7 +207,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
207207
#ifdef SAMD51
208208
if (channel1_enabled) {
209209
DAC->EVCTRL.reg |= DAC_EVCTRL_STARTEI1;
210-
DAC->DACCTRL[1].reg = DAC_DACCTRL_CCTRL_CC1M |
210+
DAC->DACCTRL[1].reg = DAC_DACCTRL_CCTRL_CC12M |
211211
DAC_DACCTRL_ENABLE |
212212
DAC_DACCTRL_LEFTADJ;
213213
DAC->CTRLB.reg = DAC_CTRLB_REFSEL_VREFPU;

0 commit comments

Comments
 (0)