You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that with analogWrite() function, even I put 0, the output is not zero, something around xx - xxx mV, I happened to find that it is due to DAC buffer on - maybe by default? refer to below link ... I have no negative power available so this non-zero output is a little bit disturbing.
Is that possible we can turn the buffer off to get the zero voltage output using Arduino way? I anyway have to connect a buffer using low drift opamp so it does not matter.
Sounds like we should disable the DAC altogether when analogWrite(0); is called and output LOW as a GPIO pin? How bad is the offset at analogWrite(1);? is it a general offset that is always there as long as the buffer is enabled?
I tested writing 0 on a standalone bluepill plus board,
without dac_output_buffer_disable(DAC0);
PA4 = 6.303 mV
with dac_output_buffer_disable(DAC0);
PA4 = 0.228 mV
it makes notable difference at 0 output now.
We can definitely add an API for this but I'm not sure if this should be the default behavior. The datasheet says that the purpose of the buffer is to provide a low-impedence output that can directly drive stuff without needing an external opamp. I can't repredict the user's application for this, whether the drive capability or voltage accuracy is more important :( .
A static +6mV offset in a total voltage swing of 3300mV doesn't seem neck-breaking to me, but I'm also willing to be convinced of the opposite.
Activity
maxgerhardt commentedon Jun 20, 2023
The DAC buffer is indeed turned on by default.
ArduinoCore-GD32/cores/arduino/analog.cpp
Lines 73 to 125 in dfa7ccb
Sounds like we should disable the DAC altogether when
analogWrite(0);is called and output LOW as a GPIO pin? How bad is the offset at analogWrite(1);? is it a general offset that is always there as long as the buffer is enabled?flute2k3 commentedon Jun 20, 2023
the output changes proportionally with 1, 2 ... etc, it is a constant offset as far as I tested.
maxgerhardt commentedon Jun 20, 2023
So when you put
after every
analogWrite()call, the offset problem is mostly gone and the DAC output curve is more ideal?flute2k3 commentedon Jun 20, 2023
I tested writing 0 on a standalone bluepill plus board,
without dac_output_buffer_disable(DAC0);
PA4 = 6.303 mV
with dac_output_buffer_disable(DAC0);
PA4 = 0.228 mV
it makes notable difference at 0 output now.
maxgerhardt commentedon Jun 20, 2023
We can definitely add an API for this but I'm not sure if this should be the default behavior. The datasheet says that the purpose of the buffer is to provide a low-impedence output that can directly drive stuff without needing an external opamp. I can't repredict the user's application for this, whether the drive capability or voltage accuracy is more important :( .
A static +6mV offset in a total voltage swing of 3300mV doesn't seem neck-breaking to me, but I'm also willing to be convinced of the opposite.
flute2k3 commentedon Jun 20, 2023
keep the default maxgerhardt, no action needed, I will use dac_output_buffer_disable(DAC0) for my application :-) cheers ~