AVRly - AVR Development Resources
|
Driver for the MCP4812 10 bit DAC (digital to analog converter) chip. More...
#include <util/delay.h>
#include <avr/interrupt.h>
#include "mcp48x2_dac.h"
#include "atmega_spi.h"
#include "pin_defines.h"
Go to the source code of this file.
Macros | |
#define | CHANNEL_BIT 15U |
#define | GAIN_BIT 13U |
#define | SHUTDOWN_BIT 12U |
#define | TWELVE_BIT_LEVEL_OFFSET 0U |
#define | TEN_BIT_LEVEL_OFFSET 2U |
#define | EIGHT_BIT_LEVEL_OFFSET 4U |
#define | TWELVE_BIT_MV_OFFSET 0U |
#define | TEN_BIT_MV_OFFSET 1U |
#define | EIGHT_BIT_MV_OFFSET 3U |
Functions | |
void | chip_select (void) |
Private helper function - pulls CS line (Chip Select) low in order to begin SPI communication with DAC. More... | |
void | chip_deselect (void) |
Private helper function - pulls CS line (Chip Select) high to signal the end of SPI communication with DAC. More... | |
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.c.
#define CHANNEL_BIT 15U |
Definition at line 46 of file mcp48x2_dac.c.
#define GAIN_BIT 13U |
Definition at line 47 of file mcp48x2_dac.c.
#define SHUTDOWN_BIT 12U |
Definition at line 48 of file mcp48x2_dac.c.
#define TWELVE_BIT_LEVEL_OFFSET 0U |
Definition at line 51 of file mcp48x2_dac.c.
#define TEN_BIT_LEVEL_OFFSET 2U |
Definition at line 52 of file mcp48x2_dac.c.
#define EIGHT_BIT_LEVEL_OFFSET 4U |
Definition at line 53 of file mcp48x2_dac.c.
#define TWELVE_BIT_MV_OFFSET 0U |
Definition at line 56 of file mcp48x2_dac.c.
#define TEN_BIT_MV_OFFSET 1U |
Definition at line 57 of file mcp48x2_dac.c.
#define EIGHT_BIT_MV_OFFSET 3U |
Definition at line 58 of file mcp48x2_dac.c.
void chip_select | ( | void | ) |
Private helper function - pulls CS line (Chip Select) low in order to begin SPI communication with DAC.
Definition at line 302 of file mcp48x2_dac.c.
void chip_deselect | ( | void | ) |
Private helper function - pulls CS line (Chip Select) high to signal the end of SPI communication with DAC.
Definition at line 311 of file mcp48x2_dac.c.
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.