Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MCP4922_HelloWorld NuMidi401 NuFM401 NuFM402
MCP4922 Class Reference
#include <MCP4922.h>
Public Types | |
| enum | DAC { DAC_A, DAC_B } |
Represents the different DACs in the MCP4922. More... | |
| enum | ReferenceMode { REF_UNBUFFERED, REF_BUFFERED } |
Represents the reference buffer mode of DAC A or B in the MCP4922. More... | |
| enum | GainMode { GAIN_2X, GAIN_1X } |
Represents the gain mode of DAC A or B in the MCP4922. More... | |
| enum | PowerMode { POWER_SHUTDOWN, POWER_NORMAL } |
Represents the power mode of DAC A or B in the MCP4922. More... | |
Public Member Functions | |
| MCP4922 (PinName mosi, PinName sclk, PinName cs, int hz=20000000) | |
| Create an MCP4922 object connected to the specified SPI pins. | |
| MCP4922::ReferenceMode | referenceMode (DAC dac) |
| Get the current reference mode of the specified DAC in the MCP4922. | |
| void | referenceMode (DAC dac, ReferenceMode mode) |
| Set the reference mode of the specified DAC in the MCP4922. | |
| MCP4922::GainMode | gainMode (DAC dac) |
| Get the current gain mode of the specified DAC in the MCP4922. | |
| void | gainMode (DAC dac, GainMode mode) |
| Set the gain mode of the specified DAC in the MCP4922. | |
| MCP4922::PowerMode | powerMode (DAC dac) |
| Get the current power mode of the specified DAC in the MCP4922. | |
| void | powerMode (DAC dac, PowerMode mode) |
| Set the power mode of the specified DAC in the MCP4922. | |
| float | read (DAC dac) |
| Get the current output voltage of the specified DAC in the MCP4922 as a percentage. | |
| void | write (DAC dac, float value) |
| Set the output voltage of the specified DAC in the MCP4922 from a percentage. | |
| void | write_u16 (DAC dac, unsigned short value) |
| Set the output voltage of the specified DAC in the MCP4922 from a 16-bit range. | |
Detailed Description
MCP4922 class.
Used for controlling an MCP4922 DAC connected via SPI.
Example:
#include "mbed.h" #include "MCP4922.h" //Create an MCP4922 object MCP4922 dac(p11, p13, p14); int main() { //Configure DAC A dac.referenceMode(MCP4922::DAC_A, MCP4922::REF_UNBUFFERED); dac.gainMode(MCP4922::DAC_A, MCP4922::GAIN_1X); dac.powerMode(MCP4922::DAC_A, MCP4922::POWER_NORMAL); while (1) { //Generate a sine wave on DAC A for (float i = 0.0; i < 360.0; i += 0.1) dac.write(MCP4922::DAC_A, 0.5 * (sinf(i * 3.14159265 / 180.0) + 1)); } }
Definition at line 48 of file MCP4922.h.
Member Enumeration Documentation
| enum DAC |
| enum GainMode |
| enum PowerMode |
| enum ReferenceMode |
Constructor & Destructor Documentation
| MCP4922 | ( | PinName | mosi, |
| PinName | sclk, | ||
| PinName | cs, | ||
| int | hz = 20000000 |
||
| ) |
Create an MCP4922 object connected to the specified SPI pins.
- Parameters:
-
mosi The SPI data out pin. sclk The SPI clock pin. cs The SPI chip select pin. hz The SPI bus frequency (defaults to 20MHz).
Definition at line 19 of file MCP4922.cpp.
Member Function Documentation
| MCP4922::GainMode gainMode | ( | DAC | dac ) |
Get the current gain mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to read from.
- Returns:
- The current gain mode of the specified DAC as a GainMode enum.
Definition at line 63 of file MCP4922.cpp.
Set the gain mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to write to. mode The new gain mode for the specified DAC as a GainMode enum.
Definition at line 72 of file MCP4922.cpp.
| MCP4922::PowerMode powerMode | ( | DAC | dac ) |
Get the current power mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to read from.
- Returns:
- The current power mode of the specified DAC as a PowerMode enum.
Definition at line 92 of file MCP4922.cpp.
Set the power mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to write to. mode The new power mode for the specified DAC as a PowerMode enum.
Definition at line 101 of file MCP4922.cpp.
| float read | ( | DAC | dac ) |
Get the current output voltage of the specified DAC in the MCP4922 as a percentage.
- Parameters:
-
dac The DAC to read from.
- Returns:
- The current output voltage of the specified DAC as a percentage (0.0 to 1.0 * VDD).
Definition at line 121 of file MCP4922.cpp.
| void referenceMode | ( | DAC | dac, |
| ReferenceMode | mode | ||
| ) |
Set the reference mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to write to. mode The new reference mode for the specified DAC as a ReferenceMode enum.
Definition at line 43 of file MCP4922.cpp.
| MCP4922::ReferenceMode referenceMode | ( | DAC | dac ) |
Get the current reference mode of the specified DAC in the MCP4922.
- Parameters:
-
dac The DAC to read from.
- Returns:
- The current reference mode of the specified DAC as a ReferenceMode enum.
Definition at line 34 of file MCP4922.cpp.
| void write | ( | DAC | dac, |
| float | value | ||
| ) |
Set the output voltage of the specified DAC in the MCP4922 from a percentage.
- Parameters:
-
dac The DAC to write to. value The new output voltage for the specified DAC as a percentage (0.0 to 1.0 * VDD).
Definition at line 130 of file MCP4922.cpp.
| void write_u16 | ( | DAC | dac, |
| unsigned short | value | ||
| ) |
Set the output voltage of the specified DAC in the MCP4922 from a 16-bit range.
- Parameters:
-
dac The DAC to write to. value The new output voltage for the specified DAC as a 16-bit unsigned short (0x0000 to 0xFFFF).
Definition at line 142 of file MCP4922.cpp.
Generated on Tue Jul 12 2022 19:00:42 by
1.7.2