Incomplete library for configuration of a DRV8301 pre-driver through a SPI interface.
DRV8301 is 3-Phase Brushless Motor Pre-Driver with Dual Current Sense Amps and Buck Converter (PWM Ctrl w/ SPI). Please find more information on Texas Instruments web pages and datasheet.
DRV8301.cpp@2:bdca7d22b783, 2015-11-23 (annotated)
- Committer:
- pantunovi
- Date:
- Mon Nov 23 13:14:48 2015 +0000
- Revision:
- 2:bdca7d22b783
- Parent:
- 0:2825ac4882fd
- Child:
- 3:227ecd07b9cd
Somewhat improved but still incomplete, still problems with class constructor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pantunovi | 0:2825ac4882fd | 1 | #include "DRV8301.h" |
pantunovi | 0:2825ac4882fd | 2 | |
pantunovi | 0:2825ac4882fd | 3 | DRV8301::DRV8301(PinName mosi, PinName miso, PinName sck) : MOSI(mosi), MISO(miso), SCK(sck){ |
pantunovi | 0:2825ac4882fd | 4 | startup(); |
pantunovi | 0:2825ac4882fd | 5 | input = 0; |
pantunovi | 2:bdca7d22b783 | 6 | } |
pantunovi | 0:2825ac4882fd | 7 | |
pantunovi | 0:2825ac4882fd | 8 | //funkcija za ograničernje struje |
pantunovi | 0:2825ac4882fd | 9 | |
pantunovi | 0:2825ac4882fd | 10 | void DRV8301::setCurrentLimit(uint8_t input){ |
pantunovi | 0:2825ac4882fd | 11 | uint16_t register1; |
pantunovi | 2:bdca7d22b783 | 12 | maskCurrentLimit = 0x783F; |
pantunovi | 0:2825ac4882fd | 13 | register1 &= maskCurrentLimit; |
pantunovi | 0:2825ac4882fd | 14 | register1 |= input << 6; |
pantunovi | 2:bdca7d22b783 | 15 | } |
pantunovi | 0:2825ac4882fd | 16 | |
pantunovi | 0:2825ac4882fd | 17 | //funkcija za input PWM ulaza |
pantunovi | 0:2825ac4882fd | 18 | |
pantunovi | 0:2825ac4882fd | 19 | void DRV8301::setPWMNumber(uint8_t input){ |
pantunovi | 0:2825ac4882fd | 20 | uint16_t register1; |
pantunovi | 2:bdca7d22b783 | 21 | maskPWM = 0x7FF7; |
pantunovi | 0:2825ac4882fd | 22 | register1 &= maskPWM; |
pantunovi | 0:2825ac4882fd | 23 | register1 |= input << 3; |
pantunovi | 2:bdca7d22b783 | 24 | } |
pantunovi | 0:2825ac4882fd | 25 | |
pantunovi | 0:2825ac4882fd | 26 | //funkcija za input mod OCP-a |
pantunovi | 0:2825ac4882fd | 27 | |
pantunovi | 0:2825ac4882fd | 28 | void DRV8301::setOCPMode(uint8_t input){ |
pantunovi | 0:2825ac4882fd | 29 | uint16_t register1; |
pantunovi | 2:bdca7d22b783 | 30 | maskOCP = 0x7FCF; |
pantunovi | 0:2825ac4882fd | 31 | register1 &= maskOCP; |
pantunovi | 0:2825ac4882fd | 32 | register1 |= input << 4; |
pantunovi | 2:bdca7d22b783 | 33 | } |
pantunovi | 0:2825ac4882fd | 34 | |
pantunovi | 0:2825ac4882fd | 35 | //funkcija za input mod OCTW-a |
pantunovi | 0:2825ac4882fd | 36 | |
pantunovi | 0:2825ac4882fd | 37 | void DRV8301::setOCTW(uint8_t input){ |
pantunovi | 0:2825ac4882fd | 38 | uint16_t register2; |
pantunovi | 2:bdca7d22b783 | 39 | maskOCTW = 0x7FFC; |
pantunovi | 0:2825ac4882fd | 40 | register2 &= maskOCTW; |
pantunovi | 0:2825ac4882fd | 41 | register2 |= input; |
pantunovi | 2:bdca7d22b783 | 42 | } |
pantunovi | 0:2825ac4882fd | 43 | |
pantunovi | 0:2825ac4882fd | 44 | //funkcija za pojačanje |
pantunovi | 0:2825ac4882fd | 45 | |
pantunovi | 0:2825ac4882fd | 46 | void DRV8301::setGain(uint8_t input){ |
pantunovi | 0:2825ac4882fd | 47 | uint16_t register2; |
pantunovi | 2:bdca7d22b783 | 48 | maskGain = 0x7FF3; |
pantunovi | 0:2825ac4882fd | 49 | register2 &= maskGain; |
pantunovi | 0:2825ac4882fd | 50 | register2 |= input << 2; |
pantunovi | 2:bdca7d22b783 | 51 | } |
pantunovi | 0:2825ac4882fd | 52 | |
pantunovi | 0:2825ac4882fd | 53 | //funkcija za dobivanje stanja u registru 1 |
pantunovi | 0:2825ac4882fd | 54 | |
pantunovi | 0:2825ac4882fd | 55 | uint16_t getRegister1(){ |
pantunovi | 0:2825ac4882fd | 56 | uint16_t register1; |
pantunovi | 0:2825ac4882fd | 57 | return register1; |
pantunovi | 2:bdca7d22b783 | 58 | } |
pantunovi | 0:2825ac4882fd | 59 | |
pantunovi | 0:2825ac4882fd | 60 | // funkcija za dobivanje stanja u registru 2 |
pantunovi | 0:2825ac4882fd | 61 | |
pantunovi | 0:2825ac4882fd | 62 | uint16_t getRegister2(){ |
pantunovi | 0:2825ac4882fd | 63 | uint16_t register2; |
pantunovi | 0:2825ac4882fd | 64 | return register2; |
pantunovi | 2:bdca7d22b783 | 65 | } |
pantunovi | 0:2825ac4882fd | 66 | |
pantunovi | 0:2825ac4882fd | 67 | //funkcija za pokretanje (reboot) DRV-a |
pantunovi | 0:2825ac4882fd | 68 | |
pantunovi | 0:2825ac4882fd | 69 | void DRV8301::startup(){ |
pantunovi | 0:2825ac4882fd | 70 | EN_GATE = 0; |
pantunovi | 0:2825ac4882fd | 71 | wait_us (25); |
pantunovi | 0:2825ac4882fd | 72 | EN_GATE = 1; |
pantunovi | 2:bdca7d22b783 | 73 | } |