Skip to content

Commit

Permalink
first import, DRV8316 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
runger1101001 committed Apr 9, 2021
0 parents commit b48635f
Show file tree
Hide file tree
Showing 10 changed files with 1,557 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Richard Unger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SimpleFOC Driver and Support Library

This library contains an assortment of drivers and supporting code for SimpleFOC.

The intent is to keep the core of SimpleFOC clean, and thus easy to maintain, understand and port to different platforms. In addition to this core, there are various drivers and supporting code which has grown around SimpleFOC, and which we would like to make available to the community.

## How to use

#### Arduino Library Manager
The simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager.
- Open Arduino IDE and start Arduino Library Manager by clicking: `Tools > Manage Libraries...`.
- Search for `Simple FOC drivers` library and install the latest version.
- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC drivers`.

#### Using Github website
- Go to the [github repository](https://github.com/simplefoc/Arduino-FOC-drivers)
- Click first on `Clone or Download > Download ZIP`.
- Unzip it and place it in `Arduino Libraries` folder. Windows: `Documents > Arduino > libraries`.
- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC drivers`.

#### Using parts

You can copy parts of the library, for example to minimize your code size, or make it easier to add adaptations of your own.
If you do so, please be sure to adhere to and include the [LICENSE](https://github.com/simplefoc/Arduino-FOC-drivers/LICENSE).

## What's contained

What's here? See the sections below. Each driver or function should come with its own more detailed README.

### Motor/Gate driver ICs

[DRV8316 driver](src/drivers/drv8316/) - SPI driver for TI's DRV8316 motor driver IC.


## Further Documentation

Find out more information about the Arduino SimpleFOC project on the [docs website](https://docs.simplefoc.com/)
123 changes: 123 additions & 0 deletions examples/drivers/drv8316/drv8316_3pwm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@



#include "Arduino.h"
#include <Wire.h>
#include <SimpleFOC.h>
#include <Math.h>
#include "drivers/drv8316/drv8316.h"




BLDCMotor motor = BLDCMotor(11);
DRV8316Driver3PWM driver = DRV8316Driver3PWM(A3,A4,2,7,false); // MKR1010 3-PWM
#define ENABLE_A 0
#define ENABLE_B 1
#define ENABLE_C 6


void printDRV8316Status() {
DRV8316Status status = driver.getStatus();
Serial.println("DRV8316 Status:");
Serial.print("Fault: ");
Serial.println(status.isFault());
Serial.print("Buck Error: ");
Serial.print(status.isBuckError());
Serial.print(" Undervoltage: ");
Serial.print(status.isBuckUnderVoltage());
Serial.print(" OverCurrent: ");
Serial.println(status.isBuckOverCurrent());
Serial.print("Charge Pump UnderVoltage: ");
Serial.println(status.isChargePumpUnderVoltage());
Serial.print("OTP Error: ");
Serial.println(status.isOneTimeProgrammingError());
Serial.print("OverCurrent: ");
Serial.print(status.isOverCurrent());
Serial.print(" Ah: ");
Serial.print(status.isOverCurrent_Ah());
Serial.print(" Al: ");
Serial.print(status.isOverCurrent_Al());
Serial.print(" Bh: ");
Serial.print(status.isOverCurrent_Bh());
Serial.print(" Bl: ");
Serial.print(status.isOverCurrent_Bl());
Serial.print(" Ch: ");
Serial.print(status.isOverCurrent_Ch());
Serial.print(" Cl: ");
Serial.println(status.isOverCurrent_Cl());
Serial.print("OverTemperature: ");
Serial.print(status.isOverTemperature());
Serial.print(" Shutdown: ");
Serial.print(status.isOverTemperatureShutdown());
Serial.print(" Warning: ");
Serial.println(status.isOverTemperatureWarning());
Serial.print("OverVoltage: ");
Serial.println(status.isOverVoltage());
Serial.print("PowerOnReset: ");
Serial.println(status.isPowerOnReset());
Serial.print("SPI Error: ");
Serial.print(status.isSPIError());
Serial.print(" Address: ");
Serial.print(status.isSPIAddressError());
Serial.print(" Clock: ");
Serial.print(status.isSPIClockFramingError());
Serial.print(" Parity: ");
Serial.println(status.isSPIParityError());
if (status.isFault())
driver.clearFault();
delayMicroseconds(1); // ensure 400ns delay
DRV8316_PWMMode val = driver.getPWMMode();
Serial.print("PWM Mode: ");
Serial.println(val);
delayMicroseconds(1); // ensure 400ns delay
bool lock = driver.isRegistersLocked();
Serial.print("Lock: ");
Serial.println(lock);
}





void setup() {

Serial.begin(115200);
while (!Serial);
delay(1);
Serial.println("Initializing...");

pinMode(ENABLE_A, OUTPUT);
digitalWrite(ENABLE_A, 1); // enable
pinMode(ENABLE_B, OUTPUT);
digitalWrite(ENABLE_B, 1); // enable
pinMode(ENABLE_C, OUTPUT);
digitalWrite(ENABLE_C, 1); // enable

driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
motor.controller = MotionControlType::velocity_openloop;
motor.voltage_limit = 3;
motor.velocity_limit = 20;
motor.init();
Serial.println("Init complete...");

delay(100);
printDRV8316Status();
}


// velocity set point variable
float target_velocity = 7.0;


void loop() {
//delay(100);
//driver.setPwm(7.4/4, 7.4/2, 7.4/4*3);
motor.move(target_velocity);
}




111 changes: 111 additions & 0 deletions examples/drivers/drv8316/drv8316_6pwm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@



#include "Arduino.h"
#include <Wire.h>
#include <SimpleFOC.h>
#include <Math.h>
#include "drivers/drv8316/drv8316.h"




BLDCMotor motor = BLDCMotor(11);
DRV8316Driver6PWM driver = DRV8316Driver6PWM(A3,0,A4,1,2,6,7,false); // MKR1010 6-PWM



void printDRV8316Status() {
DRV8316Status status = driver.getStatus();
Serial.println("DRV8316 Status:");
Serial.print("Fault: ");
Serial.println(status.isFault());
Serial.print("Buck Error: ");
Serial.print(status.isBuckError());
Serial.print(" Undervoltage: ");
Serial.print(status.isBuckUnderVoltage());
Serial.print(" OverCurrent: ");
Serial.println(status.isBuckOverCurrent());
Serial.print("Charge Pump UnderVoltage: ");
Serial.println(status.isChargePumpUnderVoltage());
Serial.print("OTP Error: ");
Serial.println(status.isOneTimeProgrammingError());
Serial.print("OverCurrent: ");
Serial.print(status.isOverCurrent());
Serial.print(" Ah: ");
Serial.print(status.isOverCurrent_Ah());
Serial.print(" Al: ");
Serial.print(status.isOverCurrent_Al());
Serial.print(" Bh: ");
Serial.print(status.isOverCurrent_Bh());
Serial.print(" Bl: ");
Serial.print(status.isOverCurrent_Bl());
Serial.print(" Ch: ");
Serial.print(status.isOverCurrent_Ch());
Serial.print(" Cl: ");
Serial.println(status.isOverCurrent_Cl());
Serial.print("OverTemperature: ");
Serial.print(status.isOverTemperature());
Serial.print(" Shutdown: ");
Serial.print(status.isOverTemperatureShutdown());
Serial.print(" Warning: ");
Serial.println(status.isOverTemperatureWarning());
Serial.print("OverVoltage: ");
Serial.println(status.isOverVoltage());
Serial.print("PowerOnReset: ");
Serial.println(status.isPowerOnReset());
Serial.print("SPI Error: ");
Serial.print(status.isSPIError());
Serial.print(" Address: ");
Serial.print(status.isSPIAddressError());
Serial.print(" Clock: ");
Serial.print(status.isSPIClockFramingError());
Serial.print(" Parity: ");
Serial.println(status.isSPIParityError());
if (status.isFault())
driver.clearFault();
delayMicroseconds(1); // ensure 400ns delay
DRV8316_PWMMode val = driver.getPWMMode();
Serial.print("PWM Mode: ");
Serial.println(val);
delayMicroseconds(1); // ensure 400ns delay
bool lock = driver.isRegistersLocked();
Serial.print("Lock: ");
Serial.println(lock);
}





void setup() {
Serial.begin(115200);
while (!Serial);
delay(1);
Serial.println("Initializing...");

driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
motor.controller = MotionControlType::velocity_openloop;
motor.voltage_limit = 3;
motor.velocity_limit = 20;
motor.init();
Serial.println("Init complete...");

delay(100);
printDRV8316Status();
}


// velocity set point variable
float target_velocity = 7.0;


void loop() {
motor.move(target_velocity);
}




2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SimpleFOC KEYWORD1
DRV8316 KEYWORD1
11 changes: 11 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=Simple FOC drivers
version=1.0
author=Simplefoc <[email protected]>
maintainer=Simplefoc <[email protected]>
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.
paragraph=SimpleFOC runs BLDC and Stepper motors using the FOC algorithm. This library supports the core SimpleFOC code by adding support for specific hardware like motor driver ICs, encoders, current sensing and other supporting code.
category=Device Control
url=https://docs.simplefoc.com
architectures=*
includes=DRV8316.h
depends=Simple FOC
Loading

0 comments on commit b48635f

Please sign in to comment.