AVRly - AVR Development Resources
|
Driver for the MCP4812 10 bit DAC (digital to analog converter) chip. More...
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Classes | |
struct | dac_channel_t |
Struct for config values for each channel - this is only to be used as a nested struct within the dac_config_t struct. More... | |
struct | dac_config_t |
Config struct for DAC. More... | |
Macros | |
#define | DAC_CHANNEL_A true |
#define | DAC_CHANNEL_B false |
Enumerations | |
enum | model_num_t { mcp4802 , mcp4812 , mcp4822 } |
Enumerated constants to select the DAC model number. More... | |
Functions | |
void | init_dac (dac_config_t *p_config) |
Initialisation routine (run once at startup). More... | |
void | dac_set_voltage (bool channel_a, uint16_t millivolts) |
Sends a new millivolts value to be output on DAC (Along with config settings). More... | |
void | dac_set_voltage_12_bit (bool channel_a, uint16_t millivolts, bool fractional) |
Sends a new millivolts value to be output on DAC (Along with config settings). More... | |
void | dac_reconfigure (void) |
Applies new config settings. More... | |
void | pulse_latch (void) |
Pulses LDAC pin low for a brief time (1uS). More... | |
Driver for the MCP4812 10 bit DAC (digital to analog converter) chip.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file provides the basic low-level functionality for the MCP4812 10 bit DAC from Microchip. This driver currently only allows for a single DAC to be used, but this might be improved on at a later date. This driver was written using the datasheet for the Microchip MCP4812 chip, which can be found at the link below.
Definition in file mcp48x2_dac.h.
#define DAC_CHANNEL_A true |
Definition at line 44 of file mcp48x2_dac.h.
#define DAC_CHANNEL_B false |
Definition at line 45 of file mcp48x2_dac.h.
enum model_num_t |
Enumerated constants to select the DAC model number.
Definition at line 51 of file mcp48x2_dac.h.
void init_dac | ( | dac_config_t * | p_config | ) |
Initialisation routine (run once at startup).
This function is to be called before using any other DAC functions. Instantiate the dac_config_t object first then pass it's address into and call init_lcd() before using any other lcd functions.
p_config | is a pointer to the dac_config_t object. |
Definition at line 89 of file mcp48x2_dac.c.
void dac_set_voltage | ( | bool | channel_a, |
uint16_t | millivolts | ||
) |
Sends a new millivolts value to be output on DAC (Along with config settings).
For 8 or 10 bit models only.
channel_a | true = Channel A, false = Channel B. |
millivolts | mV value to be output by DAC. Ensure that this value doesn't exceed the maxixum for the DAC model and gain setting. |
Definition at line 145 of file mcp48x2_dac.c.
void dac_set_voltage_12_bit | ( | bool | channel_a, |
uint16_t | millivolts, | ||
bool | fractional | ||
) |
Sends a new millivolts value to be output on DAC (Along with config settings).
For 12 bit models only.
channel_a | true = Channel A, false = Channel B. |
millivolts | mV value to be output by DAC. Ensure that this value doesn't exceed the maxixum for the DAC model and gain setting. |
fractional | true = millivolts value has 0.5mV added to it. Only to be used when gain_low is true. |
Definition at line 189 of file mcp48x2_dac.c.
void dac_reconfigure | ( | void | ) |
Applies new config settings.
This function takes updated config settings for both channels of DAC, then re-sends data so that the new settings take effect.
Definition at line 240 of file mcp48x2_dac.c.
void pulse_latch | ( | void | ) |
Pulses LDAC pin low for a brief time (1uS).
When sync_manually is true, call this function to latch both config settings and new voltage value into both channels of DAC simultaneously.
Definition at line 286 of file mcp48x2_dac.c.