-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from simplefoc/dev
1.0.6 Release PR
- Loading branch information
Showing
20 changed files
with
1,071 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=SimpleFOCDrivers | ||
version=1.0.5 | ||
version=1.0.6 | ||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
# SimpleFOC STSPIN32G4 Driver | ||
|
||
This driver initializes the PWM stage of the STSPIN32G4, and provides access to its configuration via I2C. | ||
|
||
:warning: in development! | ||
|
||
## Setup | ||
|
||
Since there are currently no standard boards for Arduino based on the STSPIN32G4 you will need a custom board definition, associated linker script and project setup to compile for your board. These topics are out of scope for this driver, but you can find a working example for the [FunQi STSPIN32G4 board](TODO link) [here](TODO link); | ||
|
||
Once you can compile for your board, and flash it with a "blinky" test sketch, then you're ready to try SimpleFOC and more complex code. | ||
|
||
## Usage | ||
|
||
Basic usage, as you can see it is very simple. Since the pins are all pre-defined due to internal connections, setup | ||
is easier than with the standard drivers. Here is an example for open loop mode: | ||
|
||
```c++ | ||
#include <Arduino.h> | ||
#include "SimpleFOC.h" | ||
#include "SimpleFOCDrivers.h" | ||
#include "drivers/stspin32g4/STSPIN32G4.h" | ||
|
||
|
||
STSPIN32G4 driver = STSPIN32G4(); | ||
BLDCMotor motor = BLDCMotor(7); | ||
|
||
void setup() { | ||
driver.voltage_power_supply = 12.0f; | ||
driver.init(); | ||
motor.voltage_limit = driver.voltage_limit / 2.0f; | ||
motor.controller = MotionControlType::velocity_openloop; | ||
motor.linkDriver(&driver); | ||
motor.init(); | ||
} | ||
|
||
void loop(){ | ||
motor.move(5.0f); // 5 rad/s open loop | ||
delayMicroseconds(100); // STM32G4 is very fast, add a delay in open loop if we do nothing else | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
|
||
#include "./STSPIN32G4.h" | ||
|
||
#ifdef ARDUINO_GENERIC_G431VBTX | ||
|
||
|
||
STSPIN32G4::STSPIN32G4() : BLDCDriver6PWM(STSPIN32G4_PIN_INUH, STSPIN32G4_PIN_INUL, STSPIN32G4_PIN_INVH, | ||
STSPIN32G4_PIN_INVL, STSPIN32G4_PIN_INWH, STSPIN32G4_PIN_INWL), | ||
_wire(STSPIN32G4_PIN_SDA, STSPIN32G4_PIN_SCL) { | ||
|
||
}; | ||
|
||
|
||
|
||
STSPIN32G4::~STSPIN32G4(){ | ||
_wire.end(); | ||
}; | ||
|
||
|
||
|
||
int STSPIN32G4::init(){ | ||
// init pins | ||
pinMode(STSPIN32G4_PIN_WAKE, OUTPUT); | ||
digitalWrite(STSPIN32G4_PIN_WAKE, LOW); | ||
pinMode(STSPIN32G4_PIN_READY, INPUT_PULLUP); | ||
pinMode(STSPIN32G4_PIN_FAULT, INPUT_PULLUP); | ||
|
||
int result = this->BLDCDriver6PWM::init(); | ||
if(result == 0) return result; | ||
setPwm(0,0,0); // set the phases to off | ||
|
||
// init I2C | ||
_wire.begin(); | ||
|
||
delayMicroseconds(50); // give driver a moment to wake up | ||
clearFaults(); // clear the faults | ||
|
||
// TODO init fault monitor | ||
|
||
return isReady() ? 1 : 0; | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::wake() { | ||
digitalWrite(STSPIN32G4_PIN_WAKE, HIGH); | ||
delayMicroseconds(50); // 50ms high pulse to wake up | ||
digitalWrite(STSPIN32G4_PIN_WAKE, LOW); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::sleep() { | ||
digitalWrite(STSPIN32G4_PIN_WAKE, LOW); | ||
writeRegister(STSPIN32G4_REG_STBY, 0x01); | ||
}; | ||
|
||
|
||
|
||
bool STSPIN32G4::isReady(){ | ||
return digitalRead(STSPIN32G4_PIN_READY)==HIGH; | ||
}; | ||
|
||
|
||
|
||
bool STSPIN32G4::isFault(){ | ||
return digitalRead(STSPIN32G4_PIN_FAULT)==LOW; | ||
}; | ||
|
||
|
||
|
||
STSPIN32G4Status STSPIN32G4::status(){ | ||
STSPIN32G4Status result; | ||
result.reg = readRegister(STSPIN32G4_REG_STATUS); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::lock(){ | ||
writeRegister(STSPIN32G4_REG_LOCK, 0x00); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::unlock(){ | ||
writeRegister(STSPIN32G4_REG_LOCK, 0xF0); | ||
}; | ||
|
||
|
||
|
||
STSPIN32G4NFault STSPIN32G4::getNFaultRegister(){ | ||
STSPIN32G4NFault result; | ||
result.reg = readRegister(STSPIN32G4_REG_NFAULT); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
STSPIN32G4Ready STSPIN32G4::getReadyRegister(){ | ||
STSPIN32G4Ready result; | ||
result.reg = readRegister(STSPIN32G4_REG_READY); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
STSPIN32G4Logic STSPIN32G4::getLogicRegister(){ | ||
STSPIN32G4Logic result; | ||
result.reg = readRegister(STSPIN32G4_REG_LOGIC); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
STSPIN32G4PowMng STSPIN32G4::getPowMngRegister(){ | ||
STSPIN32G4PowMng result; | ||
result.reg = readRegister(STSPIN32G4_REG_POWMNG); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::setNFaultRegister(STSPIN32G4NFault value){ | ||
writeRegister(STSPIN32G4_REG_NFAULT, value.reg); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::setReadyRegister(STSPIN32G4Ready value){ | ||
writeRegister(STSPIN32G4_REG_READY, value.reg); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::setLogicRegister(STSPIN32G4Logic value){ | ||
writeRegister(STSPIN32G4_REG_LOGIC, value.reg); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::setPowMngRegister(STSPIN32G4PowMng value){ | ||
writeRegister(STSPIN32G4_REG_POWMNG, value.reg); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::resetRegisters(){ | ||
// write 0xFF to reset register | ||
writeRegister(STSPIN32G4_REG_RESET, 0xFF); | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::clearFaults(){ | ||
// write 0xFF to clear faults | ||
writeRegister(STSPIN32G4_REG_CLEAR, 0xFF); | ||
}; | ||
|
||
|
||
|
||
uint8_t STSPIN32G4::readRegister(uint8_t reg){ | ||
uint8_t result = 0; | ||
_wire.beginTransmission(STSPIN32G4_I2C_ADDR); | ||
_wire.write(reg); | ||
_wire.endTransmission(false); | ||
_wire.requestFrom(STSPIN32G4_I2C_ADDR, 1); | ||
result = _wire.read(); | ||
return result; | ||
}; | ||
|
||
|
||
|
||
void STSPIN32G4::writeRegister(uint8_t reg, uint8_t val){ | ||
_wire.beginTransmission(STSPIN32G4_I2C_ADDR); | ||
_wire.write(reg); | ||
_wire.write(val); | ||
_wire.endTransmission(); | ||
}; | ||
|
||
|
||
#endif |
Oops, something went wrong.