Go to the documentation of this file.
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
38 #include "drv_i2c_master.h"
60 #define DCMOTOR22_REG_GCONF 0x00
61 #define DCMOTOR22_REG_GSTAT 0x01
62 #define DCMOTOR22_REG_IFCNT 0x02
63 #define DCMOTOR22_REG_SLAVECONF 0x03
64 #define DCMOTOR22_REG_IOIN 0x06
65 #define DCMOTOR22_REG_CURRENT_LIMIT 0x10
66 #define DCMOTOR22_REG_PWM_AB 0x22
67 #define DCMOTOR22_REG_CHOPCONF 0x6C
68 #define DCMOTOR22_REG_DRV_STATUS 0x6F
69 #define DCMOTOR22_REG_PWMCONF 0x70
77 #define DCMOTOR22_SYNC_BYTE 0x05
78 #define DCMOTOR22_READ_WRITE_BIT 0x80
79 #define DCMOTOR22_RETRY_SEND_TIMEOUT 100
80 #define DCMOTOR22_READ_TIMEOUT 1000
86 #define DCMOTOR22_GCONF_PWM_DIRECT ( 0x01ul )
87 #define DCMOTOR22_GCONF_EXTCAP_AVAILABLE ( 0x02ul )
88 #define DCMOTOR22_GCONF_PAR_MODE_DUAL_MOTOR ( 0x00ul )
89 #define DCMOTOR22_GCONF_PAR_MODE_SINGLE_MOTOR ( 0x04ul )
90 #define DCMOTOR22_GCONF_TEST_MODE ( 0x08ul )
96 #define DCMOTOR22_GSTAT_RESET ( 0x01ul )
97 #define DCMOTOR22_GSTAT_DRV_ERR ( 0x02ul )
98 #define DCMOTOR22_GSTAT_UNDER_3V5 ( 0x04ul )
99 #define DCMOTOR22_GSTAT_CLEAR_ALL ( 0x07ul )
105 #define DCMOTOR22_SLAVECONF_SENDDELAY_8BIT ( 0x0000ul )
106 #define DCMOTOR22_SLAVECONF_SENDDELAY_24BIT ( 0x0200ul )
107 #define DCMOTOR22_SLAVECONF_SENDDELAY_40BIT ( 0x0400ul )
108 #define DCMOTOR22_SLAVECONF_SENDDELAY_56BIT ( 0x0600ul )
109 #define DCMOTOR22_SLAVECONF_SENDDELAY_72BIT ( 0x0800ul )
110 #define DCMOTOR22_SLAVECONF_SENDDELAY_88BIT ( 0x0A00ul )
111 #define DCMOTOR22_SLAVECONF_SENDDELAY_104BIT ( 0x0C00ul )
112 #define DCMOTOR22_SLAVECONF_SENDDELAY_120BIT ( 0x0E00ul )
118 #define DCMOTOR22_IOIN_EN ( 0x01ul )
119 #define DCMOTOR22_IOIN_NSTDBY ( 0x02ul )
120 #define DCMOTOR22_IOIN_AD0 ( 0x04ul )
121 #define DCMOTOR22_IOIN_AD1 ( 0x08ul )
122 #define DCMOTOR22_IOIN_DIAG ( 0x10ul )
123 #define DCMOTOR22_IOIN_UART_ON ( 0x20ul )
124 #define DCMOTOR22_IOIN_UART_IN ( 0x40ul )
125 #define DCMOTOR22_IOIN_MODE_IN ( 0x80ul )
126 #define DCMOTOR22_IOIN_A2 ( 0x0100ul )
127 #define DCMOTOR22_IOIN_A1 ( 0x0200ul )
128 #define DCMOTOR22_IOIN_COMP_A1A2 ( 0x0400ul )
129 #define DCMOTOR22_IOIN_COMP_B1B2 ( 0x0800ul )
130 #define DCMOTOR22_IOIN_VERSION ( 0x40000000ul )
131 #define DCMOTOR22_IOIN_VERSION_MASK ( 0xFF000000ul )
137 #define DCMOTOR22_CURRENT_LIMIT_EN_FREEWHEELING ( 0x01ul )
138 #define DCMOTOR22_CURRENT_LIMIT_IRUN_1_32 ( 0x0000ul )
139 #define DCMOTOR22_CURRENT_LIMIT_IRUN_2_32 ( 0x0100ul )
140 #define DCMOTOR22_CURRENT_LIMIT_IRUN_3_32 ( 0x0200ul )
141 #define DCMOTOR22_CURRENT_LIMIT_IRUN_4_32 ( 0x0300ul )
142 #define DCMOTOR22_CURRENT_LIMIT_IRUN_5_32 ( 0x0400ul )
143 #define DCMOTOR22_CURRENT_LIMIT_IRUN_6_32 ( 0x0500ul )
144 #define DCMOTOR22_CURRENT_LIMIT_IRUN_7_32 ( 0x0600ul )
145 #define DCMOTOR22_CURRENT_LIMIT_IRUN_8_32 ( 0x0700ul )
146 #define DCMOTOR22_CURRENT_LIMIT_IRUN_9_32 ( 0x0800ul )
147 #define DCMOTOR22_CURRENT_LIMIT_IRUN_10_32 ( 0x0900ul )
148 #define DCMOTOR22_CURRENT_LIMIT_IRUN_11_32 ( 0x0A00ul )
149 #define DCMOTOR22_CURRENT_LIMIT_IRUN_12_32 ( 0x0B00ul )
150 #define DCMOTOR22_CURRENT_LIMIT_IRUN_13_32 ( 0x0C00ul )
151 #define DCMOTOR22_CURRENT_LIMIT_IRUN_14_32 ( 0x0D00ul )
152 #define DCMOTOR22_CURRENT_LIMIT_IRUN_15_32 ( 0x0E00ul )
153 #define DCMOTOR22_CURRENT_LIMIT_IRUN_16_32 ( 0x0F00ul )
154 #define DCMOTOR22_CURRENT_LIMIT_IRUN_17_32 ( 0x1000ul )
155 #define DCMOTOR22_CURRENT_LIMIT_IRUN_18_32 ( 0x1100ul )
156 #define DCMOTOR22_CURRENT_LIMIT_IRUN_19_32 ( 0x1200ul )
157 #define DCMOTOR22_CURRENT_LIMIT_IRUN_20_32 ( 0x1300ul )
158 #define DCMOTOR22_CURRENT_LIMIT_IRUN_21_32 ( 0x1400ul )
159 #define DCMOTOR22_CURRENT_LIMIT_IRUN_22_32 ( 0x1500ul )
160 #define DCMOTOR22_CURRENT_LIMIT_IRUN_23_32 ( 0x1600ul )
161 #define DCMOTOR22_CURRENT_LIMIT_IRUN_24_32 ( 0x1700ul )
162 #define DCMOTOR22_CURRENT_LIMIT_IRUN_25_32 ( 0x1800ul )
163 #define DCMOTOR22_CURRENT_LIMIT_IRUN_26_32 ( 0x1900ul )
164 #define DCMOTOR22_CURRENT_LIMIT_IRUN_27_32 ( 0x1A00ul )
165 #define DCMOTOR22_CURRENT_LIMIT_IRUN_28_32 ( 0x1B00ul )
166 #define DCMOTOR22_CURRENT_LIMIT_IRUN_29_32 ( 0x1C00ul )
167 #define DCMOTOR22_CURRENT_LIMIT_IRUN_30_32 ( 0x1D00ul )
168 #define DCMOTOR22_CURRENT_LIMIT_IRUN_31_32 ( 0x1E00ul )
169 #define DCMOTOR22_CURRENT_LIMIT_IRUN_32_32 ( 0x1F00ul )
175 #define DCMOTOR22_MAX_PWM 255
176 #define DCMOTOR22_MIN_PWM ( -255 )
177 #define DCMOTOR22_PWM_RES 0x01FF
178 #define DCMOTOR22_PWM_DUTY_0 ( 0x00ul )
184 #define DCMOTOR22_CHOPCONF_DISS2VS ( 0x80000000ul )
185 #define DCMOTOR22_CHOPCONF_DISS2G ( 0x40000000ul )
186 #define DCMOTOR22_CHOPCONF_TBL_0 ( 0x00000000ul )
187 #define DCMOTOR22_CHOPCONF_TBL_1 ( 0x00008000ul )
188 #define DCMOTOR22_CHOPCONF_TBL_2 ( 0x00010000ul )
189 #define DCMOTOR22_CHOPCONF_TBL_3 ( 0x00018000ul )
190 #define DCMOTOR22_CHOPCONF_ENABLEDRV ( 0x00000001ul )
196 #define DCMOTOR22_PWMCONF_FREEWHEEL_NORMAL_OP ( 0x00000000ul )
197 #define DCMOTOR22_PWMCONF_FREEWHEEL_FREEWHEELING ( 0x00100000ul )
198 #define DCMOTOR22_PWMCONF_FREEWHEEL_LS_SHORTED ( 0x00200000ul )
199 #define DCMOTOR22_PWMCONF_FREEWHEEL_HS_SHORTED ( 0x00300000ul )
200 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_1024 ( 0x00000000ul )
201 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_683 ( 0x00010000ul )
202 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_512 ( 0x00020000ul )
203 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_410 ( 0x00030000ul )
209 #define DCMOTOR22_MOTOR_A 0x00
210 #define DCMOTOR22_MOTOR_B 0x01
216 #define DCMOTOR22_NUM_CONVERSIONS 100
217 #define DCMOTOR22_RSENSE 0.1
223 #define DCMOTOR22_ADC_REG_SETUP 0x80
224 #define DCMOTOR22_ADC_SETUP_VREF_VDD_REF_NC_OFF 0x00
225 #define DCMOTOR22_ADC_SETUP_VREF_EXT_REF_IN_OFF 0x20
226 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_NC_OFF 0x40
227 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_NC_ON 0x50
228 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_OUT_OFF 0x60
229 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_OUT_ON 0x70
230 #define DCMOTOR22_ADC_SETUP_CLK_INT 0x00
231 #define DCMOTOR22_ADC_SETUP_CLK_EXT 0x08
232 #define DCMOTOR22_ADC_SETUP_UNIPOLAR 0x00
233 #define DCMOTOR22_ADC_SETUP_BIPOLAR 0x04
234 #define DCMOTOR22_ADC_SETUP_RST_RESET 0x00
235 #define DCMOTOR22_ADC_SETUP_RST_NO_ACTION 0x02
241 #define DCMOTOR22_ADC_REG_CONFIG 0x00
242 #define DCMOTOR22_ADC_CONFIG_SCAN_AIN0_TO_CS0 0x00
243 #define DCMOTOR22_ADC_CONFIG_SCAN_CS0_8_TIMES 0x20
244 #define DCMOTOR22_ADC_CONFIG_SCAN_CS0 0x60
245 #define DCMOTOR22_ADC_CONFIG_CS0_AIN0 0x00
246 #define DCMOTOR22_ADC_CONFIG_CS0_AIN1 0x02
247 #define DCMOTOR22_ADC_CONFIG_DIFFERENTIAL 0x00
248 #define DCMOTOR22_ADC_CONFIG_SINGLE_ENDED 0x01
254 #define DCMOTOR22_ADC_REG_BIT_MASK 0x80
255 #define DCMOTOR22_ADC_SETUP_VREF_BIT_MASK 0x70
256 #define DCMOTOR22_ADC_SETUP_CLK_BIT_MASK 0x08
257 #define DCMOTOR22_ADC_SETUP_UNI_BIP_BIT_MASK 0x04
258 #define DCMOTOR22_ADC_SETUP_RST_BIT_MASK 0x02
259 #define DCMOTOR22_ADC_CONFIG_SCAN_BIT_MASK 0x60
260 #define DCMOTOR22_ADC_CONFIG_CS0_BIT_MASK 0x02
261 #define DCMOTOR22_ADC_CONFIG_SGL_DIF_BIT_MASK 0x01
267 #define DCMOTOR22_ADC_CHANNEL_0 0
268 #define DCMOTOR22_ADC_CHANNEL_1 1
274 #define DCMOTOR22_ADC_RESOLUTION 0x0FFF
275 #define DCMOTOR22_ADC_VREF 2.048
282 #define DCMOTOR22_ADC_DEVICE_ADDRESS 0x36
283 #define DCMOTOR22_UART_DEVICE_ADDRESS_0 0x00
284 #define DCMOTOR22_UART_DEVICE_ADDRESS_1 0x01
285 #define DCMOTOR22_UART_DEVICE_ADDRESS_2 0x02
286 #define DCMOTOR22_UART_DEVICE_ADDRESS_3 0x03
287 #define DCMOTOR22_UART_DEVICE_ADDRESS_MASK 0x03
294 #define DRV_BUFFER_SIZE 200
312 #define DCMOTOR22_MAP_MIKROBUS( cfg, mikrobus ) \
313 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
314 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
315 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
316 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
317 cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
318 cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
319 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
320 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
607 #endif // DCMOTOR22_H
dcmotor22_return_value_t
DC Motor 22 Click return value data.
Definition: dcmotor22.h:390
uint8_t adc_config_byte
Definition: dcmotor22.h:350
err_t dcmotor22_adc_write_setup_byte(dcmotor22_t *ctx, uint8_t setup_byte)
DC Motor 22 ADC write setup byte function.
@ DCMOTOR22_OK
Definition: dcmotor22.h:391
pin_name_t scl
Definition: dcmotor22.h:364
pin_name_t rx_pin
Definition: dcmotor22.h:362
digital_out_t a1
Definition: dcmotor22.h:333
#define DRV_BUFFER_SIZE
DC Motor 22 driver buffer size.
Definition: dcmotor22.h:294
err_t dcmotor22_default_cfg(dcmotor22_t *ctx)
DC Motor 22 default configuration function.
uint8_t i2c_slave_address
Definition: dcmotor22.h:344
pin_name_t en
Definition: dcmotor22.h:370
err_t dcmotor22_get_motor_current(dcmotor22_t *ctx, uint8_t motor_sel, float *current)
DC Motor 22 get motor current function.
void dcmotor22_cfg_setup(dcmotor22_cfg_t *cfg)
DC Motor 22 configuration object setup function.
digital_out_t a0
Definition: dcmotor22.h:332
digital_in_t int_pin
Definition: dcmotor22.h:337
pin_name_t sda
Definition: dcmotor22.h:365
void dcmotor22_disable_device(dcmotor22_t *ctx)
DC Motor 22 disable device function.
err_t dcmotor22_adc_set_channel(dcmotor22_t *ctx, uint8_t channel)
DC Motor 22 ADC set channel function.
uint8_t adc_setup_byte
Definition: dcmotor22.h:349
pin_name_t a1
Definition: dcmotor22.h:369
i2c_master_t i2c
Definition: dcmotor22.h:340
DC Motor 22 Click context object.
Definition: dcmotor22.h:330
uart_t uart
Definition: dcmotor22.h:341
err_t dcmotor22_write_register(dcmotor22_t *ctx, uint8_t reg, uint32_t data_in)
DC Motor 22 write register function.
uart_data_bits_t data_bit
Definition: dcmotor22.h:376
err_t dcmotor22_adc_write_config_byte(dcmotor22_t *ctx, uint8_t config_byte)
DC Motor 22 ADC write config byte function.
pin_name_t tx_pin
Definition: dcmotor22.h:363
err_t dcmotor22_init(dcmotor22_t *ctx, dcmotor22_cfg_t *cfg)
DC Motor 22 initialization function.
err_t dcmotor22_set_motor_pwm(dcmotor22_t *ctx, uint8_t motor_sel, int16_t pwm_duty)
DC Motor 22 set motor pwm function.
uint32_t i2c_speed
Definition: dcmotor22.h:380
uint8_t dcmotor22_get_int_pin(dcmotor22_t *ctx)
DC Motor 22 get int pin function.
digital_out_t en
Definition: dcmotor22.h:334
uint32_t baud_rate
Definition: dcmotor22.h:374
@ DCMOTOR22_ERROR
Definition: dcmotor22.h:392
err_t dcmotor22_read_register(dcmotor22_t *ctx, uint8_t reg, uint32_t *data_out)
DC Motor 22 read register function.
pin_name_t int_pin
Definition: dcmotor22.h:371
pin_name_t a0
Definition: dcmotor22.h:368
uint8_t uart_device_address
Definition: dcmotor22.h:343
err_t dcmotor22_adc_get_voltage(dcmotor22_t *ctx, float *voltage)
DC Motor 22 ADC get voltage function.
bool uart_blocking
Definition: dcmotor22.h:375
void dcmotor22_enable_device(dcmotor22_t *ctx)
DC Motor 22 enable device function.
void dcmotor22_reset_device(dcmotor22_t *ctx)
DC Motor 22 reset device function.
uart_stop_bits_t stop_bit
Definition: dcmotor22.h:378
DC Motor 22 Click configuration object.
Definition: dcmotor22.h:360
uart_parity_t parity_bit
Definition: dcmotor22.h:377
void dcmotor22_set_device_address(dcmotor22_t *ctx, uint8_t addr)
DC Motor 22 set device address function.
uint8_t i2c_address
Definition: dcmotor22.h:381
uint32_t pwm_ab
Definition: dcmotor22.h:351