Go to the source code of this file.
#define MCP4822_CS_DISABLED 0x01 |
#define MCP4822_CS_ENABLED 0x00 |
#define MCP4822_CS_PORT PORTAbits.RA5 |
#define MCP4822_CS_TRIS TRISAbits.TRISA5 |
#define MCP4822_DAC_A 0x00 |
#define MCP4822_DAC_B 0x80 |
#define MCP4822_GAIN_1 0x20 |
#define MCP4822_GAIN_2 0x00 |
#define MCP4822_LDAC_DISABLED 0x01 |
#define MCP4822_LDAC_ENABLED 0x00 |
#define MCP4822_LDAC_PORT PORTEbits.RE0 |
#define MCP4822_LDAC_TRIS TRISEbits.TRISE0 |
#define MCP4822_OUT_DEFAULT_VALUE 0x00 |
#define MCP4822_PULSE_DELAY _delay(1) |
#define MCP4822_SHUTDOWN_OFF 0x10 |
#define MCP4822_SHUTDOWN_ON 0x00 |
#define MCP4822_SPI_MODULE_1 |
void MCP4822_initialize |
( |
unsigned char |
clock | ) |
|
This function initializes the MCP4822 and PIC signals. SDO, SS, SCK from the PIC side are automatically set by this function.
- Parameters
-
clock | It sets the clock source for the SPI module. Use the following constants [MCP4822_CLOCK_FOSC_64, MCP4822_CLOCK_FOSC_16, MCP4822_CLOCK_FOSC_4, MCP4822_CLOCK_FOSC_TMR2] |
- Returns
- void
- Note
- By default the DAC outputs are set to high impedance.
- Warning
- You must properly set the Analog inputs which are muxed with the SPI lines.
Definition at line 60 of file MCP4822.c.
References MCP4822_CS_DISABLED, MCP4822_CS_PORT, MCP4822_CS_TRIS, MCP4822_DAC_A, MCP4822_DAC_B, MCP4822_GAIN_2, MCP4822_LDAC_DISABLED, MCP4822_LDAC_PORT, MCP4822_LDAC_TRIS, MCP4822_OUT_DEFAULT_VALUE, MCP4822_set_amplitude(), MCP4822_set_options(), MCP4822_SHUTDOWN_ON, MCP4822_SPI_baudrate, MCP4822_SPI_mode, MCP4822_SPI_open, MCP4822_SPI_read_byte, PIN_AS_OUTPUT, SPI_MASTER_DEVICE, and SPI_MODE_0.
void MCP4822_latch_pulse |
( |
void |
| ) |
|
void MCP4822_set_amplitude |
( |
unsigned int |
value, |
|
|
unsigned char |
channel |
|
) |
| |
This function sets the output value of the DAC. By Gain 2 the value is expressed in mV, while by Gain 1 is 1/2 mV.
- Parameters
-
value | It sets the output value of the DAC [12 bits]. |
channel | It sets the channel to which the value refers to [MCP4822_DAC_A, MCP4822_DAC_B]. |
- Returns
- void
- Note
- This function does generate the LATCH pulse to load the DAC value right after the SPI writing.
Definition at line 120 of file MCP4822.c.
References MCP4822_latch_pulse(), and MCP4822_set_value().
void MCP4822_set_options |
( |
unsigned char |
gain, |
|
|
unsigned char |
power, |
|
|
unsigned char |
channel |
|
) |
| |
This function sets the DAC Options. The options which are set in the function, take place after the next writing to the corresponding DAC Channel.
- Parameters
-
gain | It sets the output gain [MCP4822_GAIN_1, MCP4822_GAIN_2] |
power | It sets the channel power mode [MCP4822_SHUTDOWN_ON, MCP4822_SHUTDOWN_OFF] |
channel | It sets the channel to which the options refer to [MCP4822_DAC_A, MCP4822_DAC_B] |
- Returns
- void
- Note
- This function does NOT generate the LATCH pulse to load the DAC value right after the writing. The settings take place by the next amplitude writing.
Definition at line 143 of file MCP4822.c.
References gain_value_DAC_A_MCP4822, gain_value_DAC_B_MCP4822, MCP4822_DAC_A, MCP4822_DAC_B, power_mode_DAC_A_MCP4822, and power_mode_DAC_B_MCP4822.
void MCP4822_set_value |
( |
unsigned int |
value, |
|
|
unsigned char |
channel |
|
) |
| |
This function sets the output value of the DAC. By Gain 2 the value is expressed in mV, while by Gain 1 is 1/2 mV.
- Parameters
-
value | It sets the output value of the DAC [12 bits]. |
channel | It sets the channel to which the value refers to [MCP4822_DAC_A, MCP4822_DAC_B]. |
- Returns
- void
- Note
- This function does not generate the LATCH pulse to load the DAC values. This it means that the pulse latch pulse must be generated separately. This option is used in case both DAC must be set before loading the output value.
Definition at line 89 of file MCP4822.c.
References gain_value_DAC_A_MCP4822, gain_value_DAC_B_MCP4822, MCP4822_CS_DISABLED, MCP4822_CS_ENABLED, MCP4822_CS_PORT, MCP4822_DAC_A, MCP4822_SPI_write_byte, power_mode_DAC_A_MCP4822, and power_mode_DAC_B_MCP4822.