Go to the documentation of this file.
39 #ifdef PREINIT_SUPPORTED
43 #ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
52 #include "drv_i2c_master.h"
74 #define DCMOTOR22_REG_GCONF 0x00
75 #define DCMOTOR22_REG_GSTAT 0x01
76 #define DCMOTOR22_REG_IFCNT 0x02
77 #define DCMOTOR22_REG_SLAVECONF 0x03
78 #define DCMOTOR22_REG_IOIN 0x06
79 #define DCMOTOR22_REG_CURRENT_LIMIT 0x10
80 #define DCMOTOR22_REG_PWM_AB 0x22
81 #define DCMOTOR22_REG_CHOPCONF 0x6C
82 #define DCMOTOR22_REG_DRV_STATUS 0x6F
83 #define DCMOTOR22_REG_PWMCONF 0x70
91 #define DCMOTOR22_SYNC_BYTE 0x05
92 #define DCMOTOR22_READ_WRITE_BIT 0x80
93 #define DCMOTOR22_RETRY_SEND_TIMEOUT 100
94 #define DCMOTOR22_READ_TIMEOUT 1000
100 #define DCMOTOR22_GCONF_PWM_DIRECT ( 0x01ul )
101 #define DCMOTOR22_GCONF_EXTCAP_AVAILABLE ( 0x02ul )
102 #define DCMOTOR22_GCONF_PAR_MODE_DUAL_MOTOR ( 0x00ul )
103 #define DCMOTOR22_GCONF_PAR_MODE_SINGLE_MOTOR ( 0x04ul )
104 #define DCMOTOR22_GCONF_TEST_MODE ( 0x08ul )
110 #define DCMOTOR22_GSTAT_RESET ( 0x01ul )
111 #define DCMOTOR22_GSTAT_DRV_ERR ( 0x02ul )
112 #define DCMOTOR22_GSTAT_UNDER_3V5 ( 0x04ul )
113 #define DCMOTOR22_GSTAT_CLEAR_ALL ( 0x07ul )
119 #define DCMOTOR22_SLAVECONF_SENDDELAY_8BIT ( 0x0000ul )
120 #define DCMOTOR22_SLAVECONF_SENDDELAY_24BIT ( 0x0200ul )
121 #define DCMOTOR22_SLAVECONF_SENDDELAY_40BIT ( 0x0400ul )
122 #define DCMOTOR22_SLAVECONF_SENDDELAY_56BIT ( 0x0600ul )
123 #define DCMOTOR22_SLAVECONF_SENDDELAY_72BIT ( 0x0800ul )
124 #define DCMOTOR22_SLAVECONF_SENDDELAY_88BIT ( 0x0A00ul )
125 #define DCMOTOR22_SLAVECONF_SENDDELAY_104BIT ( 0x0C00ul )
126 #define DCMOTOR22_SLAVECONF_SENDDELAY_120BIT ( 0x0E00ul )
132 #define DCMOTOR22_IOIN_EN ( 0x01ul )
133 #define DCMOTOR22_IOIN_NSTDBY ( 0x02ul )
134 #define DCMOTOR22_IOIN_AD0 ( 0x04ul )
135 #define DCMOTOR22_IOIN_AD1 ( 0x08ul )
136 #define DCMOTOR22_IOIN_DIAG ( 0x10ul )
137 #define DCMOTOR22_IOIN_UART_ON ( 0x20ul )
138 #define DCMOTOR22_IOIN_UART_IN ( 0x40ul )
139 #define DCMOTOR22_IOIN_MODE_IN ( 0x80ul )
140 #define DCMOTOR22_IOIN_A2 ( 0x0100ul )
141 #define DCMOTOR22_IOIN_A1 ( 0x0200ul )
142 #define DCMOTOR22_IOIN_COMP_A1A2 ( 0x0400ul )
143 #define DCMOTOR22_IOIN_COMP_B1B2 ( 0x0800ul )
144 #define DCMOTOR22_IOIN_VERSION ( 0x40000000ul )
145 #define DCMOTOR22_IOIN_VERSION_MASK ( 0xFF000000ul )
151 #define DCMOTOR22_CURRENT_LIMIT_EN_FREEWHEELING ( 0x01ul )
152 #define DCMOTOR22_CURRENT_LIMIT_IRUN_1_32 ( 0x0000ul )
153 #define DCMOTOR22_CURRENT_LIMIT_IRUN_2_32 ( 0x0100ul )
154 #define DCMOTOR22_CURRENT_LIMIT_IRUN_3_32 ( 0x0200ul )
155 #define DCMOTOR22_CURRENT_LIMIT_IRUN_4_32 ( 0x0300ul )
156 #define DCMOTOR22_CURRENT_LIMIT_IRUN_5_32 ( 0x0400ul )
157 #define DCMOTOR22_CURRENT_LIMIT_IRUN_6_32 ( 0x0500ul )
158 #define DCMOTOR22_CURRENT_LIMIT_IRUN_7_32 ( 0x0600ul )
159 #define DCMOTOR22_CURRENT_LIMIT_IRUN_8_32 ( 0x0700ul )
160 #define DCMOTOR22_CURRENT_LIMIT_IRUN_9_32 ( 0x0800ul )
161 #define DCMOTOR22_CURRENT_LIMIT_IRUN_10_32 ( 0x0900ul )
162 #define DCMOTOR22_CURRENT_LIMIT_IRUN_11_32 ( 0x0A00ul )
163 #define DCMOTOR22_CURRENT_LIMIT_IRUN_12_32 ( 0x0B00ul )
164 #define DCMOTOR22_CURRENT_LIMIT_IRUN_13_32 ( 0x0C00ul )
165 #define DCMOTOR22_CURRENT_LIMIT_IRUN_14_32 ( 0x0D00ul )
166 #define DCMOTOR22_CURRENT_LIMIT_IRUN_15_32 ( 0x0E00ul )
167 #define DCMOTOR22_CURRENT_LIMIT_IRUN_16_32 ( 0x0F00ul )
168 #define DCMOTOR22_CURRENT_LIMIT_IRUN_17_32 ( 0x1000ul )
169 #define DCMOTOR22_CURRENT_LIMIT_IRUN_18_32 ( 0x1100ul )
170 #define DCMOTOR22_CURRENT_LIMIT_IRUN_19_32 ( 0x1200ul )
171 #define DCMOTOR22_CURRENT_LIMIT_IRUN_20_32 ( 0x1300ul )
172 #define DCMOTOR22_CURRENT_LIMIT_IRUN_21_32 ( 0x1400ul )
173 #define DCMOTOR22_CURRENT_LIMIT_IRUN_22_32 ( 0x1500ul )
174 #define DCMOTOR22_CURRENT_LIMIT_IRUN_23_32 ( 0x1600ul )
175 #define DCMOTOR22_CURRENT_LIMIT_IRUN_24_32 ( 0x1700ul )
176 #define DCMOTOR22_CURRENT_LIMIT_IRUN_25_32 ( 0x1800ul )
177 #define DCMOTOR22_CURRENT_LIMIT_IRUN_26_32 ( 0x1900ul )
178 #define DCMOTOR22_CURRENT_LIMIT_IRUN_27_32 ( 0x1A00ul )
179 #define DCMOTOR22_CURRENT_LIMIT_IRUN_28_32 ( 0x1B00ul )
180 #define DCMOTOR22_CURRENT_LIMIT_IRUN_29_32 ( 0x1C00ul )
181 #define DCMOTOR22_CURRENT_LIMIT_IRUN_30_32 ( 0x1D00ul )
182 #define DCMOTOR22_CURRENT_LIMIT_IRUN_31_32 ( 0x1E00ul )
183 #define DCMOTOR22_CURRENT_LIMIT_IRUN_32_32 ( 0x1F00ul )
189 #define DCMOTOR22_MAX_PWM 255
190 #define DCMOTOR22_MIN_PWM ( -255 )
191 #define DCMOTOR22_PWM_RES 0x01FF
192 #define DCMOTOR22_PWM_DUTY_0 ( 0x00ul )
198 #define DCMOTOR22_CHOPCONF_DISS2VS ( 0x80000000ul )
199 #define DCMOTOR22_CHOPCONF_DISS2G ( 0x40000000ul )
200 #define DCMOTOR22_CHOPCONF_TBL_0 ( 0x00000000ul )
201 #define DCMOTOR22_CHOPCONF_TBL_1 ( 0x00008000ul )
202 #define DCMOTOR22_CHOPCONF_TBL_2 ( 0x00010000ul )
203 #define DCMOTOR22_CHOPCONF_TBL_3 ( 0x00018000ul )
204 #define DCMOTOR22_CHOPCONF_ENABLEDRV ( 0x00000001ul )
210 #define DCMOTOR22_PWMCONF_FREEWHEEL_NORMAL_OP ( 0x00000000ul )
211 #define DCMOTOR22_PWMCONF_FREEWHEEL_FREEWHEELING ( 0x00100000ul )
212 #define DCMOTOR22_PWMCONF_FREEWHEEL_LS_SHORTED ( 0x00200000ul )
213 #define DCMOTOR22_PWMCONF_FREEWHEEL_HS_SHORTED ( 0x00300000ul )
214 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_1024 ( 0x00000000ul )
215 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_683 ( 0x00010000ul )
216 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_512 ( 0x00020000ul )
217 #define DCMOTOR22_PWMCONF_PWM_FREQ_2_410 ( 0x00030000ul )
223 #define DCMOTOR22_MOTOR_A 0x00
224 #define DCMOTOR22_MOTOR_B 0x01
230 #define DCMOTOR22_NUM_CONVERSIONS 100
231 #define DCMOTOR22_RSENSE 0.1
237 #define DCMOTOR22_ADC_REG_SETUP 0x80
238 #define DCMOTOR22_ADC_SETUP_VREF_VDD_REF_NC_OFF 0x00
239 #define DCMOTOR22_ADC_SETUP_VREF_EXT_REF_IN_OFF 0x20
240 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_NC_OFF 0x40
241 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_NC_ON 0x50
242 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_OUT_OFF 0x60
243 #define DCMOTOR22_ADC_SETUP_VREF_INT_REF_OUT_ON 0x70
244 #define DCMOTOR22_ADC_SETUP_CLK_INT 0x00
245 #define DCMOTOR22_ADC_SETUP_CLK_EXT 0x08
246 #define DCMOTOR22_ADC_SETUP_UNIPOLAR 0x00
247 #define DCMOTOR22_ADC_SETUP_BIPOLAR 0x04
248 #define DCMOTOR22_ADC_SETUP_RST_RESET 0x00
249 #define DCMOTOR22_ADC_SETUP_RST_NO_ACTION 0x02
255 #define DCMOTOR22_ADC_REG_CONFIG 0x00
256 #define DCMOTOR22_ADC_CONFIG_SCAN_AIN0_TO_CS0 0x00
257 #define DCMOTOR22_ADC_CONFIG_SCAN_CS0_8_TIMES 0x20
258 #define DCMOTOR22_ADC_CONFIG_SCAN_CS0 0x60
259 #define DCMOTOR22_ADC_CONFIG_CS0_AIN0 0x00
260 #define DCMOTOR22_ADC_CONFIG_CS0_AIN1 0x02
261 #define DCMOTOR22_ADC_CONFIG_DIFFERENTIAL 0x00
262 #define DCMOTOR22_ADC_CONFIG_SINGLE_ENDED 0x01
268 #define DCMOTOR22_ADC_REG_BIT_MASK 0x80
269 #define DCMOTOR22_ADC_SETUP_VREF_BIT_MASK 0x70
270 #define DCMOTOR22_ADC_SETUP_CLK_BIT_MASK 0x08
271 #define DCMOTOR22_ADC_SETUP_UNI_BIP_BIT_MASK 0x04
272 #define DCMOTOR22_ADC_SETUP_RST_BIT_MASK 0x02
273 #define DCMOTOR22_ADC_CONFIG_SCAN_BIT_MASK 0x60
274 #define DCMOTOR22_ADC_CONFIG_CS0_BIT_MASK 0x02
275 #define DCMOTOR22_ADC_CONFIG_SGL_DIF_BIT_MASK 0x01
281 #define DCMOTOR22_ADC_CHANNEL_0 0
282 #define DCMOTOR22_ADC_CHANNEL_1 1
288 #define DCMOTOR22_ADC_RESOLUTION 0x0FFF
289 #define DCMOTOR22_ADC_VREF 2.048
296 #define DCMOTOR22_ADC_DEVICE_ADDRESS 0x36
297 #define DCMOTOR22_UART_DEVICE_ADDRESS_0 0x00
298 #define DCMOTOR22_UART_DEVICE_ADDRESS_1 0x01
299 #define DCMOTOR22_UART_DEVICE_ADDRESS_2 0x02
300 #define DCMOTOR22_UART_DEVICE_ADDRESS_3 0x03
301 #define DCMOTOR22_UART_DEVICE_ADDRESS_MASK 0x03
308 #define DRV_BUFFER_SIZE 200
326 #define DCMOTOR22_MAP_MIKROBUS( cfg, mikrobus ) \
327 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
328 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
329 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
330 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
331 cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
332 cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
333 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
334 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
621 #endif // DCMOTOR22_H
dcmotor22_return_value_t
DC Motor 22 Click return value data.
Definition: dcmotor22.h:404
uint8_t adc_config_byte
Definition: dcmotor22.h:364
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:405
pin_name_t scl
Definition: dcmotor22.h:378
pin_name_t rx_pin
Definition: dcmotor22.h:376
digital_out_t a1
Definition: dcmotor22.h:347
#define DRV_BUFFER_SIZE
DC Motor 22 driver buffer size.
Definition: dcmotor22.h:308
err_t dcmotor22_default_cfg(dcmotor22_t *ctx)
DC Motor 22 default configuration function.
uint8_t i2c_slave_address
Definition: dcmotor22.h:358
pin_name_t en
Definition: dcmotor22.h:384
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:346
digital_in_t int_pin
Definition: dcmotor22.h:351
pin_name_t sda
Definition: dcmotor22.h:379
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:363
pin_name_t a1
Definition: dcmotor22.h:383
i2c_master_t i2c
Definition: dcmotor22.h:354
DC Motor 22 Click context object.
Definition: dcmotor22.h:344
uart_t uart
Definition: dcmotor22.h:355
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:390
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:377
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:394
uint8_t dcmotor22_get_int_pin(dcmotor22_t *ctx)
DC Motor 22 get int pin function.
digital_out_t en
Definition: dcmotor22.h:348
uint32_t baud_rate
Definition: dcmotor22.h:388
@ DCMOTOR22_ERROR
Definition: dcmotor22.h:406
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:385
pin_name_t a0
Definition: dcmotor22.h:382
uint8_t uart_device_address
Definition: dcmotor22.h:357
err_t dcmotor22_adc_get_voltage(dcmotor22_t *ctx, float *voltage)
DC Motor 22 ADC get voltage function.
bool uart_blocking
Definition: dcmotor22.h:389
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:392
DC Motor 22 Click configuration object.
Definition: dcmotor22.h:374
uart_parity_t parity_bit
Definition: dcmotor22.h:391
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:395
uint32_t pwm_ab
Definition: dcmotor22.h:365