0

SAMD51 M4 DAC has problems getting it up
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SAMD51 M4 DAC has problems getting it up

by kevinjwalters on Wed Jul 03, 2019 5:23 pm

I just noticed some odd behaviour on PyGamer DACs and switched to a Feather M4 to make things simpler. Both of those SAMD51 (M4) based boards have DACs which exhibit a steppy quality when they rise but not fall. I've been using CircuitPython for all of these examples, I don't see any immediately obvious reason why that would cause this. The short duration top of the square wave suggests that it's the hardware doing this either as a "feature" or due to misconfiguration/misuse? With 8 steps it could be the upper 3 bits of the 12 are treated in a different way?

CP-FeatherM4-dac0-samd51-square-1.JPG
Feather M4 DAC0 alternating between 0 and 65535 in CircuitPython loop
CP-FeatherM4-dac0-samd51-square-1.JPG (177.29 KiB) Viewed 198 times


I compared it with a CPX with SAMD21 (M0) and that looks as one would hope. All images are 10us per graduation.

CP-cpx-dac-samd21-square-1.JPG
Circuit Playground Express (M0) DAC alternating between 0 and 65535 in CircuitPython loop
CP-cpx-dac-samd21-square-1.JPG (163.08 KiB) Viewed 198 times


I think the mulitple images are just caused by the triggering having problems with the jitter presumably from the CircuitPython interpreter.

Code is this running in REPL:

Code: Select all | TOGGLE FULL SIZE
>>> import board
>>> import analogio
>>> aout0 = analogio.AnalogOut(board.A0)

>>> while True:
...     aout0.value = 0
...     aout0.value = 65535


A 20 second browse of data sheet shows there is an "Interpolation Mode" (section 47.6.9.6). Perhaps that's the cause but I don't see why that would only affect rising?
Last edited by kevinjwalters on Thu Jul 04, 2019 8:38 am, edited 2 times in total.

kevinjwalters
 
Posts: 432
Joined: Sun Oct 01, 2017 3:15 pm

Re: SAMD51 M4 DAC has problems getting it up

by kevinjwalters on Thu Jul 04, 2019 8:34 am

I had a play in Arduino land with Feather M4. Without a pause I initially saw a triangle wave and thought that looked reasonable based on non-zero rise/fall time and DAC was ok. As I added some pauses to form a reasonable flat top and bottom of the square wave it all got a bit weird and seemed more like CircuitPython world but with extra twist of not always getting to 3.3V max.

First one is with 12us delay after setting the minimum and maximum value for DAC, second one with 100us instead:

AR-FeatherM4-dac1-samd51-square-24us-1.JPG
Feather M4 DAC1 alternating between 0 and 4095 (max) every ~12+12us in C/Arduino
AR-FeatherM4-dac1-samd51-square-24us-1.JPG (88.28 KiB) Viewed 169 times


AR-FeatherM4-dac1-samd51-square-200us-1.JPG
Feather M4 DAC1 alternating between 0 and 4095 (max) every ~100+100us in C/Arduino
AR-FeatherM4-dac1-samd51-square-200us-1.JPG (84.44 KiB) Viewed 169 times


The code using Arduino IDE 1.8.7 and Adafruit SAMD Boards by Adafruit 1.5.1:

Code: Select all | TOGGLE FULL SIZE
void loop() {
  // This does not seem to be needed on Feather M4
  // analogWriteResolution(12);
 
  // int usdelay = 12;
  int usdelay = 100; 
  while (1) {
    analogWrite(DAC1, 0);
    delayMicroseconds(usdelay);
    analogWrite(DAC1, 4095);
    delayMicroseconds(usdelay);
  }
}


Would be useful if someone else could corroborate this.

kevinjwalters
 
Posts: 432
Joined: Sun Oct 01, 2017 3:15 pm

Re: SAMD51 M4 DAC has problems getting it up

by kevinjwalters on Mon Jul 22, 2019 4:16 pm

Confirmed by another user with Feather M4:

DS1Z_QuickPrint4-feather-m4-dac-rise-i.png
DS1Z_QuickPrint4-feather-m4-dac-rise-i.png (40.67 KiB) Viewed 90 times


DS1Z_QuickPrint5-feather-m4-dac-rise-ii.png
DS1Z_QuickPrint5-feather-m4-dac-rise-ii.png (34.7 KiB) Viewed 90 times

kevinjwalters
 
Posts: 432
Joined: Sun Oct 01, 2017 3:15 pm

Re: SAMD51 M4 DAC has problems getting it up

by kevinjwalters on Mon Jul 22, 2019 6:17 pm

This gives a constant shape with one step at top which suggests the rise issue is not related to absolute values but when the delta change (increase) is greater than 1/8 (8192) of full range:

Code: Select all | TOGGLE FULL SIZE
>>> while True:
...     for i in range(0, 65536-8192-512, 16):
...         low = i
...         high = i + 8192 + 512
...         print(low, high)
...         for _ in range(50000):
...             aout0.value = low
...             aout0.value = high
...             aout0.value = low
...             aout0.value = high
...             aout0.value = low
...             aout0.value = high
...
...
...
0 8704
16 8720
32 8736
48 8752

kevinjwalters
 
Posts: 432
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.