Added support for MCP4725’s power-down mode #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My personal motivation for implementing the power-down functionality was that I needed to be able to set 0V in my project. I didn't actually care about saving power while the MCP4725 sleeps. The offset error in the MCP4725 meant that with
setVoltage(0, false)
, I had 2.6mV on the output pin, which was too high for my purposes.The only thing I'm not 100% happy with is the names of the constants used to set the power-down output impedance (
MCP4725_OUTPUT_LOAD_RESISTANCE_1K
etc). They seem a bit long and hard to remember, but we obviously need them to be unique enough that there wouldn't be clashes out in the field and descriptive enough so as to make it clear what their purpose is.In case you're wondering why I didn't just set the value of those constants to the appropriate bit masks, then directly use that in the powerDown function (instead of using the switch statement), it's because that would give client code the potential to invoke undesired behaviour on the MCP4725 if an incorrect value was passed in. At present, the worst that could happen is that they could fail to invoke power-down mode, but who knows what the future holds and what those two extra bits either side of the power-down bits might be used for.
Testing
I have tested this change on an Arduino Duemilanove.
I ran the triangle sample and my new powerdown sample and verified that the output was as expected using both a multimeter as a failsafe sanity check and an analogue input pin on the Arduino to plot the output voltages using the Arduino IDE's plotter function.
I tested the power down modes by attaching an ohmmeter between the out and gnd pins and checking that the power-down output impedance was as expected.
I also tested passing in
true
to bothsetVoltage
andpowerDown
, each time, cycling power to the MCP4725 and verifying that the output state when power returned was as expected.