adafruit / ArduinoCore-samd

115 stars 119 forks source link

AnalogWrite on M4 not working when delay is used #35

Closed freemovers closed 6 years ago

freemovers commented 6 years ago

AnalogWrite on A0 and A1 works great as long as no delay, or millis is used in the program. As soon as a delay is used the output creeps back to zero volts. At a lower analog value, about a 1000, it takes longer to creep down to zero volt (about 3 seconds). At a higher value, 4000, it returns to zero within 1 second.

dhalbert commented 6 years ago

@deanm1278 on SAMD51, the DAC peripheral has a "refresh period" setting, which has to be set to >= 2, or else the output is not maintained. I had to set this correctly in CircuitPython: https://github.com/adafruit/circuitpython/blob/f02cbeabab3091c70a9d40b6a9f9bea3516b2eec/ports/atmel-samd/asf4_conf/samd51/hpl_dac_config.h#L71 . See DACCTRLx.REFRESH (p.1412 in the datasheet).

deanm1278 commented 6 years ago

Thanks @dhalbert! ok this appears to be fixed in the most recent master