dac10  2.0.0.0
dac10.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef DAC10_H
29 #define DAC10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define DAC10_REG_STATUS 0xD0
74 #define DAC10_REG_GENERAL_CONFIG 0xD1
75 #define DAC10_REG_TRIGGER 0xD3
76 #define DAC10_REG_DAC_DATA 0x21
77 #define DAC10_REG_DAC_MARGIN_HIGH 0x25
78 #define DAC10_REG_DAC_MARGIN_LOW 0x26
79 #define DAC10_REG_PMBUS_OPERATION 0x01
80 #define DAC10_REG_PMBUS_STATUS_BYTE 0x78
81 #define DAC10_REG_PMBUS_VERSION 0x98
82  // dac10_reg
84 
99 #define DAC10_STATUS_NVM_CRC_ALARM_USER 0x8000
100 #define DAC10_STATUS_NVM_CRC_ALARM_INTERNAL 0x4000
101 #define DAC10_STATUS_NVM_BUSY 0x2000
102 #define DAC10_STATUS_DAC_UPDATE_BUSY 0x1000
103 #define DAC10_STATUS_DEVICE_ID 0x000C
104 #define DAC10_STATUS_DEVICE_ID_MASK 0x003C
105 #define DAC10_STATUS_VERSION_ID_MASK 0x0003
106 
111 #define DAC10_GEN_CONFIG_FCFG_TRIANGLE_WAVE 0x0000
112 #define DAC10_GEN_CONFIG_FCFG_SAW_TOOTH_WAVE_RISING 0x4000
113 #define DAC10_GEN_CONFIG_FCFG_SAW_TOOTH_WAVE_FALLING 0x8000
114 #define DAC10_GEN_CONFIG_FCFG_SQUARE_WAVE 0xC000
115 #define DAC10_GEN_CONFIG_FCFG_CLR_MASK 0xC000
116 #define DAC10_GEN_CONFIG_DEVICE_LOCKED 0x2000
117 #define DAC10_GEN_CONFIG_DEVICE_NOT_LOCKED 0x0000
118 #define DAC10_GEN_CONFIG_DEVICE_LOCK_MASK 0x2000
119 #define DAC10_GEN_CONFIG_PMBUS_ENABLE 0x1000
120 #define DAC10_GEN_CONFIG_PMBUS_DISABLE 0x0000
121 #define DAC10_GEN_CONFIG_PMBUS_EN_MASK 0x1000
122 #define DAC10_GEN_CONFIG_CODE_STEP_1LSB 0x0000
123 #define DAC10_GEN_CONFIG_CODE_STEP_2LSB 0x0200
124 #define DAC10_GEN_CONFIG_CODE_STEP_3LSB 0x0400
125 #define DAC10_GEN_CONFIG_CODE_STEP_4LSB 0x0600
126 #define DAC10_GEN_CONFIG_CODE_STEP_6LSB 0x0800
127 #define DAC10_GEN_CONFIG_CODE_STEP_8LSB 0x0A00
128 #define DAC10_GEN_CONFIG_CODE_STEP_16LSB 0x0C00
129 #define DAC10_GEN_CONFIG_CODE_STEP_32LSB 0x0E00
130 #define DAC10_GEN_CONFIG_CODE_STEP_MASK 0x0E00
131 #define DAC10_GEN_CONFIG_SLEW_RATE_25p6US 0x0000
132 #define DAC10_GEN_CONFIG_SLEW_RATE_25p6USx1p25 0x0020
133 #define DAC10_GEN_CONFIG_SLEW_RATE_25p6USx1p50 0x0040
134 #define DAC10_GEN_CONFIG_SLEW_RATE_25p6USx1p75 0x0060
135 #define DAC10_GEN_CONFIG_SLEW_RATE_204p8US 0x0080
136 #define DAC10_GEN_CONFIG_SLEW_RATE_204p8USx1p25 0x00A0
137 #define DAC10_GEN_CONFIG_SLEW_RATE_204p8USx1p50 0x00C0
138 #define DAC10_GEN_CONFIG_SLEW_RATE_204p8USx1p75 0x00E0
139 #define DAC10_GEN_CONFIG_SLEW_RATE_1p6384MS 0x0100
140 #define DAC10_GEN_CONFIG_SLEW_RATE_1p6384MSx1p25 0x0120
141 #define DAC10_GEN_CONFIG_SLEW_RATE_1p6384MSx1p50 0x0140
142 #define DAC10_GEN_CONFIG_SLEW_RATE_1p6384MSx1p75 0x0160
143 #define DAC10_GEN_CONFIG_SLEW_RATE_12US 0x0180
144 #define DAC10_GEN_CONFIG_SLEW_RATE_8US 0x01A0
145 #define DAC10_GEN_CONFIG_SLEW_RATE_4US 0x01C0
146 #define DAC10_GEN_CONFIG_SLEW_RATE_NO_SLEW 0x01E0
147 #define DAC10_GEN_CONFIG_SLEW_RATE_MASK 0x01E0
148 #define DAC10_GEN_CONFIG_DAC_PDN_POWER_UP 0x0000
149 #define DAC10_GEN_CONFIG_DAC_PDN_POWER_DOWN_10K 0x0008
150 #define DAC10_GEN_CONFIG_DAC_PDN_POWER_DOWN_HIGH_Z 0x0010
151 #define DAC10_GEN_CONFIG_DAC_PDN_MASK 0x0018
152 #define DAC10_GEN_CONFIG_INT_REF_ENABLE 0x0004
153 #define DAC10_GEN_CONFIG_INT_REF_DISABLE 0x0000
154 #define DAC10_GEN_CONFIG_INT_REF_EN_MASK 0x0004
155 #define DAC10_GEN_CONFIG_DAC_SPAN_GAIN_1p5X 0x0000
156 #define DAC10_GEN_CONFIG_DAC_SPAN_GAIN_2X 0x0001
157 #define DAC10_GEN_CONFIG_DAC_SPAN_GAIN_3X 0x0002
158 #define DAC10_GEN_CONFIG_DAC_SPAN_GAIN_4X 0x0003
159 #define DAC10_GEN_CONFIG_DAC_SPAN_MASK 0x0003
160 
165 #define DAC10_TRIGGER_DEVICE_UNLOCK_CODE 0x5000
166 #define DAC10_TRIGGER_DEVICE_UNLOCK_CODE_MASK 0xF000
167 #define DAC10_TRIGGER_DEVICE_CONFIG_RESET_INITIATED 0x0200
168 #define DAC10_TRIGGER_DEVICE_CONFIG_RESET_NOT_INITIATED 0x0000
169 #define DAC10_TRIGGER_DEVICE_CONFIG_RESET_MASK 0x0200
170 #define DAC10_TRIGGER_START_FUNC_GEN_ENABLE 0x0100
171 #define DAC10_TRIGGER_START_FUNC_GEN_DISABLE 0x0000
172 #define DAC10_TRIGGER_START_FUNC_GEN_MASK 0x0100
173 #define DAC10_TRIGGER_PMBUS_MARGIN_HIGH_INITIATED 0x0080
174 #define DAC10_TRIGGER_PMBUS_MARGIN_HIGH_NOT_INITIATED 0x0000
175 #define DAC10_TRIGGER_PMBUS_MARGIN_HIGH_MASK 0x0080
176 #define DAC10_TRIGGER_PMBUS_MARGIN_LOW_INITIATED 0x0040
177 #define DAC10_TRIGGER_PMBUS_MARGIN_LOW_NOT_INITIATED 0x0000
178 #define DAC10_TRIGGER_PMBUS_MARGIN_LOW_MASK 0x0040
179 #define DAC10_TRIGGER_NWM_RELOAD_INITIATED 0x0020
180 #define DAC10_TRIGGER_NWM_RELOAD_NOT_INITIATED 0x0000
181 #define DAC10_TRIGGER_NWM_RELOAD_MASK 0x0020
182 #define DAC10_TRIGGER_NWM_PROG_INITIATED 0x0010
183 #define DAC10_TRIGGER_NWM_PROG_NOT_INITIATED 0x0000
184 #define DAC10_TRIGGER_NWM_PROG_MASK 0x0010
185 #define DAC10_TRIGGER_SW_RESET_INITIATED 0x0008
186 #define DAC10_TRIGGER_SW_RESET_NOT_INITIATED 0x000A
187 #define DAC10_TRIGGER_SW_RESET_MASK 0x000F
188 
193 #define DAC10_PMBUS_OPERATION_CMD_TURN_OFF 0x0000
194 #define DAC10_PMBUS_OPERATION_CMD_TURN_ON 0x8000
195 #define DAC10_PMBUS_OPERATION_CMD_MARGIN_HIGH 0xA400
196 #define DAC10_PMBUS_OPERATION_CMD_MARGIN_LOW 0x9400
197 #define DAC10_PMBUS_OPERATION_CMD 0xFF00
198 
203 #define DAC10_PMBUS_STATUS_BYTE_CML_NO_FAULT 0x0000
204 #define DAC10_PMBUS_STATUS_BYTE_CML_FAULT 0x0200
205 #define DAC10_PMBUS_STATUS_BYTE_CML_MASK 0x0200
206 
211 #define DAC10_PMBUS_VERSION_DEFAULT 0x2200
212 #define DAC10_PMBUS_VERSION_MASK 0xFF00
213 
218 #define DAC10_MIN_DAC_VALUE 0x0000
219 #define DAC10_MAX_DAC_VALUE 0x03FF
220 
225 #define DAC10_VREF_3V3 3.3
226 #define DAC10_VREF_5V 5
227 #define DAC10_VREF_INT 1.21
228 
234 #define DAC10_DEV_ADDR_GND 0x48
235 #define DAC10_DEV_ADDR_VCC 0x49
236 #define DAC10_DEV_ADDR_SDA 0x4A
237 #define DAC10_DEV_ADDR_SCL 0x4B
238 #define DAC10_DEV_ADDR_BROADCAST 0x47
239 
240  // dac10_set
242 
257 #define DAC10_MAP_MIKROBUS( cfg, mikrobus ) \
258  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
259  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
260  // dac10_map // dac10
263 
268 typedef struct
269 {
270  // Modules
271  i2c_master_t i2c;
273  // I2C slave address
274  uint8_t slave_address;
276 } dac10_t;
277 
282 typedef struct
283 {
284  pin_name_t scl;
285  pin_name_t sda;
287  uint32_t i2c_speed;
288  uint8_t i2c_address;
290 } dac10_cfg_t;
291 
296 typedef enum
297 {
298  DAC10_OK = 0,
299  DAC10_ERROR = -1
300 
302 
319 
334 err_t dac10_init ( dac10_t *ctx, dac10_cfg_t *cfg );
335 
350 err_t dac10_reg_write ( dac10_t *ctx, uint8_t reg, uint16_t data_in );
351 
366 err_t dac10_reg_read ( dac10_t *ctx, uint8_t reg, uint16_t *data_in );
367 
380 err_t dac10_set_dac_value ( dac10_t *ctx, uint16_t data_in );
381 
396 err_t dac10_set_output_voltage ( dac10_t *ctx, float vref, float voltage );
397 
410 err_t dac10_set_output_voltage_int_vref ( dac10_t *ctx, float voltage );
411 
424 err_t dac10_set_dac_margin_high ( dac10_t *ctx, uint16_t data_in );
425 
438 err_t dac10_set_dac_margin_low ( dac10_t *ctx, uint16_t data_in );
439 
452 
464 err_t dac10_enable_dac ( dac10_t *ctx );
465 
466 #ifdef __cplusplus
467 }
468 #endif
469 #endif // DAC10_H
470  // dac10
472 
473 // ------------------------------------------------------------------------ END
dac10_enable_dac
err_t dac10_enable_dac(dac10_t *ctx)
DAC 10 enable DAC output function.
dac10_cfg_t
DAC 10 Click configuration object.
Definition: dac10.h:283
DAC10_OK
@ DAC10_OK
Definition: dac10.h:298
dac10_cfg_t::sda
pin_name_t sda
Definition: dac10.h:285
dac10_set_dac_value
err_t dac10_set_dac_value(dac10_t *ctx, uint16_t data_in)
DAC 10 set dac value function.
dac10_set_output_voltage_int_vref
err_t dac10_set_output_voltage_int_vref(dac10_t *ctx, float voltage)
DAC 10 set output voltage with internal reference function.
dac10_set_output_voltage
err_t dac10_set_output_voltage(dac10_t *ctx, float vref, float voltage)
DAC 10 set output voltage function.
dac10_cfg_t::scl
pin_name_t scl
Definition: dac10.h:284
dac10_cfg_t::i2c_address
uint8_t i2c_address
Definition: dac10.h:288
dac10_set_dac_margin_low
err_t dac10_set_dac_margin_low(dac10_t *ctx, uint16_t data_in)
DAC 10 set dac margin low function.
dac10_check_device_id
err_t dac10_check_device_id(dac10_t *ctx)
DAC 10 check device ID function.
dac10_t
DAC 10 Click context object.
Definition: dac10.h:269
dac10_init
err_t dac10_init(dac10_t *ctx, dac10_cfg_t *cfg)
DAC 10 initialization function.
dac10_reg_write
err_t dac10_reg_write(dac10_t *ctx, uint8_t reg, uint16_t data_in)
DAC 10 I2C writing function.
dac10_reg_read
err_t dac10_reg_read(dac10_t *ctx, uint8_t reg, uint16_t *data_in)
DAC 10 I2C reading function.
dac10_set_dac_margin_high
err_t dac10_set_dac_margin_high(dac10_t *ctx, uint16_t data_in)
DAC 10 set dac margin high function.
dac10_cfg_setup
void dac10_cfg_setup(dac10_cfg_t *cfg)
DAC 10 configuration object setup function.
dac10_t::slave_address
uint8_t slave_address
Definition: dac10.h:274
dac10_t::i2c
i2c_master_t i2c
Definition: dac10.h:271
dac10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dac10.h:287
DAC10_ERROR
@ DAC10_ERROR
Definition: dac10.h:299
dac10_return_value_t
dac10_return_value_t
DAC 10 Click return value data.
Definition: dac10.h:297