Bluetooth enabled control of a BLDC via the Allegro MicroSystems A4960.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_ModularRobot by Annie Mao

Committer:
anniemao
Date:
Tue May 16 19:31:49 2017 +0000
Revision:
11:4251b62991ac
Annie Mao 2017

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anniemao 11:4251b62991ac 1 #ifndef _A4960_H_
anniemao 11:4251b62991ac 2 #define _A4960_H_
anniemao 11:4251b62991ac 3
anniemao 11:4251b62991ac 4 #include "mbed.h"
anniemao 11:4251b62991ac 5 #include "spi_master.h"
anniemao 11:4251b62991ac 6
anniemao 11:4251b62991ac 7 class a4960
anniemao 11:4251b62991ac 8 {
anniemao 11:4251b62991ac 9 public:
anniemao 11:4251b62991ac 10 a4960();
anniemao 11:4251b62991ac 11 void SPI_init();
anniemao 11:4251b62991ac 12 void write_to_a4960(uint8_t addr, uint16_t msg);
anniemao 11:4251b62991ac 13 void write_run();
anniemao 11:4251b62991ac 14 void write_brake();
anniemao 11:4251b62991ac 15 bool motor_started;
anniemao 11:4251b62991ac 16 float PWM_freq; // Hz
anniemao 11:4251b62991ac 17 float PWM_duty; // 0 to 1
anniemao 11:4251b62991ac 18 private:
anniemao 11:4251b62991ac 19 // the default configurations of the 8 a4960 registers
anniemao 11:4251b62991ac 20 // 0. Config0: basic timing settings
anniemao 11:4251b62991ac 21 // CB(2 bits) comm. blank time
anniemao 11:4251b62991ac 22 // BT (4 bits) blank time in 400ns increments
anniemao 11:4251b62991ac 23 // DT (6 bits) dead time in 50ns increments
anniemao 11:4251b62991ac 24 // 1. Config1: basic voltage settings
anniemao 11:4251b62991ac 25 // VR (4 bits) current limit reference voltage as ratio of Vref
anniemao 11:4251b62991ac 26 // VT (6 bits) drain-source thresh. voltage in 25 mV increments
anniemao 11:4251b62991ac 27 // 2. Config2: PWM settings
anniemao 11:4251b62991ac 28 // PT (5 bits) off-time for PWM current control, limits motor current
anniemao 11:4251b62991ac 29 // 3. Config3: start-up hold settings
anniemao 11:4251b62991ac 30 // IDS (1 bit) select current control or duty cycle control for init. holding torque
anniemao 11:4251b62991ac 31 // HQ (4 bits) holding torque for initial start position
anniemao 11:4251b62991ac 32 // hold current or duty cycle in increments of 6.25%
anniemao 11:4251b62991ac 33 // HT (4 bits) hold time of init. start position, increments of 8ms from 2ms
anniemao 11:4251b62991ac 34 // 4. Config4: start-up timing settings
anniemao 11:4251b62991ac 35 // EC (4 bits) end comm. time in incr. of 200us
anniemao 11:4251b62991ac 36 // SC (4 bits) start comm. time in incr. of 8ms
anniemao 11:4251b62991ac 37 // 5. Config5: start-up ramp settings
anniemao 11:4251b62991ac 38 // PA (4 bits) phase advance in incr. of 1.875 deg
anniemao 11:4251b62991ac 39 // RQ (4 bits) torque during ramp up (duty cycle or current control dep. on IDS) in 6.25% incr.
anniemao 11:4251b62991ac 40 // RR (4 bits) accel. rate during forced comm. ramp up
anniemao 11:4251b62991ac 41 // 6. Mask: fault masking bit for each fault bit in Diagnostic register
anniemao 11:4251b62991ac 42 // each bit: 1 means diagnostic is diabled
anniemao 11:4251b62991ac 43 // 7. Run: bits to set running conditions
anniemao 11:4251b62991ac 44 // BH (2 bits) select BEMF hysteresis
anniemao 11:4251b62991ac 45 // BW (3 bits) BEMF window
anniemao 11:4251b62991ac 46 // ESF (1 bit) enable stop on fault
anniemao 11:4251b62991ac 47 // DG (2 bits) select output routed to DIAG terminal, default general fault output flag (low if fault detected)
anniemao 11:4251b62991ac 48 // RSC (1 bit) 1 to enable restart after loss of sync if RUN 1, BRK 0, else coast to stop
anniemao 11:4251b62991ac 49 // BRK (1 bit) brake control
anniemao 11:4251b62991ac 50 // DIR (1 bit) direction control
anniemao 11:4251b62991ac 51 // RUN (1 bit) run control
anniemao 11:4251b62991ac 52 uint16_t _config[8];
anniemao 11:4251b62991ac 53 SPIClass SPI;
anniemao 11:4251b62991ac 54 DigitalOut _cs_pin;
anniemao 11:4251b62991ac 55 DigitalOut _blink_pin;
anniemao 11:4251b62991ac 56 PwmOut _PWM_pin;
anniemao 11:4251b62991ac 57 };
anniemao 11:4251b62991ac 58
anniemao 11:4251b62991ac 59 #endif