fix bringup issues

This commit is contained in:
2023-11-01 23:03:33 -04:00
parent 4e71a6c509
commit e15533d740
9 changed files with 1188 additions and 1020 deletions

View File

@@ -5,10 +5,10 @@
#define V_PWM PA9
#define W_PWM PA1
#define A1 PA0
#define A2 PA1
#define B1 PA9
#define B2 PA10
#define MOT_A1 PA0
#define MOT_A2 PA10
#define MOT_B1 PA9
#define MOT_B2 PA1
#define MOT_EN PB12
@@ -21,7 +21,6 @@
#define ENC_CIPO PA6
#define ENC_SCK PA5
#define ENC_CS PC4
#define ENC_CAL PA4
// CURRENT SENSE
#define ISENSE_U PA3
@@ -32,10 +31,12 @@
#define CAN_TX PB8
#define CAN_RX PB9
// CONTROL INPUTS
// PCB REV CHANGES
#ifdef PCB_REV1
#define STEP_PIN PB14
#define DIR_PIN PB15
#define CAL_EN PB1
#endif
#ifdef PCB_REV2
@@ -44,6 +45,8 @@
#define I2C_SDA PC11
#define I2C_SCL PA8
#define CAL_EN PA4
#endif
// AUX

View File

@@ -5,11 +5,12 @@
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/MT6835/MagneticSensorMT6835.h"
#include "encoders/stm32hwencoder/STM32HWEncoder.h"
#include "stm32g4xx_hal_conf.h"
#include "stm32g4xx_hal_fdcan.h"
#include "can.h"
// #include "can.h"
#include "dfu.h"
#include "lemon-pepper.h"
@@ -33,56 +34,69 @@ extern uint8_t TxData[8];
extern uint8_t RxData[8];
// simpleFOC things
#define POLEPAIRS 7
#define RPHASE 1.4
#define MOTORKV 1000
#define POLEPAIRS 50
#define RPHASE 3
#define MOTORKV 200
#define ENC_PPR 0xFFFD // 65533 -> 65534 ppr (65535 cause overflow on 16 bit timer)
SPISettings myMT6835SPISettings(1000000, MT6835_BITORDER, SPI_MODE3);
SPIClass spi1(ENC_COPI, ENC_CIPO, ENC_SCK);
SPISettings myMT6835SPISettings(168000000/16, MT6835_BITORDER, SPI_MODE3);
MagneticSensorMT6835 sensor = MagneticSensorMT6835(ENC_CS, myMT6835SPISettings);
STM32HWEncoder enc = STM32HWEncoder(ENC_PPR, ENC_A, ENC_B, ENC_Z);
BLDCDriver3PWM driver = BLDCDriver3PWM(U_PWM, V_PWM, W_PWM, U_EN, V_EN, W_EN);
BLDCMotor motor = BLDCMotor(POLEPAIRS, RPHASE, MOTORKV);
MagneticSensorMT6701SSI enc = MagneticSensorMT6701SSI(ENC_CS);
StepperDriver4PWM driver = StepperDriver4PWM(MOT_A1, MOT_A2, MOT_B1, MOT_B2);
StepperMotor motor = StepperMotor(POLEPAIRS, RPHASE, MOTORKV);
Commander commander = Commander(SerialUSB);
uint16_t counter = 0;
// Prototypes
void configureFOC(void);
void configureCAN(void);
void userButton_IT(void);
// void configureCAN(void);
// void configureEncoder(void);
void setup()
{
// SCB->VTOR == 0x08000000;
pinMode(USER_LED, OUTPUT);
attachInterrupt(USER_BUTTON, userButton_IT, HIGH);
pinMode(LED_GOOD, OUTPUT);
pinMode(LED_FAULT, OUTPUT);
pinMode(CAL_EN, OUTPUT);
pinMode(MOT_EN, OUTPUT);
SerialUSB.begin(115200);
EEPROM.get(0, boardData);
// EEPROM.get(0, boardData);
configureCAN();
configureFOC();
digitalWrite(MOT_EN, HIGH);
digitalWrite(CAL_EN, LOW);
if(boardData.canID == 0x000)
{
// If the can ID is not initialized, then we'll look for a free ID.
boardData.canID = FDCAN_FindUniqueID();
SerialUSB.println(boardData.canID);
}
// configureCAN();
// configureEncoder();
// configureFOC();
sensor.init(&spi1);
if(boardData.signature != magicWord)
{
// If the EEPROM has not been initalized yet, save all the known data.
EEPROM.put(0, boardData);
}
// if(boardData.canID == 0x000)
// {
// // If the can ID is not initialized, then we'll look for a free ID.
// boardData.canID = FDCAN_FindUniqueID();
// SerialUSB.println(boardData.canID);
// }
// if(boardData.signature != magicWord)
// {
// // If the EEPROM has not been initalized yet, save all the known data.
// EEPROM.put(0, boardData);
// }
}
void loop()
{
motor.loopFOC();
motor.move();
commander.run();
{
// motor.loopFOC();
// motor.move();
// commander.run();
sensor.update();
delay(10);
SerialUSB.printf("%#06x\n", sensor.readRawAngle21());
#ifdef HAS_MONITOR
motor.monitor();
#endif
@@ -102,13 +116,16 @@ void configureFOC(void){
#endif
// Encoder initialization.
// Encoder on SPI1
enc.init();
// Ideally configuring the sensor over SPI then use STM32HWEncoder
// sensor.init(&spi1);
// sensor.setABZResolution(ENC_PPR);
// enc.init();
// Driver initialization.
driver.pwm_frequency = 32000;
driver.voltage_power_supply = 5;
driver.voltage_limit = 2.5;
driver.voltage_power_supply = 9;
driver.voltage_limit = driver.voltage_power_supply/2;
driver.init();
// Motor PID parameters.
@@ -121,10 +138,10 @@ void configureFOC(void){
// Motor initialization.
motor.voltage_sensor_align = 2;
motor.current_limit = 0.5;
motor.current_limit = 0.35;
motor.velocity_limit = 50;
motor.controller = MotionControlType::velocity;
motor.foc_modulation = FOCModulationType::SinePWM;
motor.controller = MotionControlType::velocity_openloop;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// Monitor initialization
#ifdef HAS_MONITOR
@@ -137,27 +154,33 @@ void configureFOC(void){
motor.linkSensor(&enc);
motor.linkDriver(&driver);
motor.target = 0;
motor.target = 10;
if(boardData.signature != magicWord){
// If we have not initialized the EEPROM before.
motor.init();
motor.initFOC();
motor.zero_electric_angle = NOT_SET;
motor.sensor_direction = Direction::UNKNOWN;
boardData.signature = magicWord;
boardData.electricalZero = motor.zero_electric_angle;
boardData.electricalDir = motor.sensor_direction;
}
else{
motor.zero_electric_angle = boardData.electricalZero;
motor.sensor_direction = boardData.electricalDir;
motor.init();
motor.initFOC();
}
motor.init();
motor.initFOC();
// if(boardData.signature != magicWord){
// // If we have not initialized the EEPROM before.
// motor.init();
// motor.initFOC();
// boardData.signature = magicWord;
// boardData.electricalZero = motor.zero_electric_angle;
// boardData.electricalDir = motor.sensor_direction;
// }
// else{
// motor.zero_electric_angle = boardData.electricalZero;
// motor.sensor_direction = boardData.electricalDir;
// motor.init();
// motor.initFOC();
// }
}
void configureCAN(void){
FDCAN_Start(0x000);
}
// void configureCAN(void){
// FDCAN_Start(0x000);
// }

View File

@@ -712,12 +712,12 @@
(property "LCSC Part" "C146412" (at 125.73 87.63 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid d60ea7da-e95d-4c22-ad65-def1505307da))
(pin "1" (uuid d60ea7da-e95d-4c22-ad65-def1505307da))
(pin "1" (uuid d60ea7da-e95d-4c22-ad65-def1505307db))
(pin "1" (uuid d60ea7da-e95d-4c22-ad65-def1505307db))
(pin "11" (uuid e8d3a338-a773-49b8-a716-d1ab18131472))
(pin "12" (uuid 8c659ecd-ac7a-4f4a-9995-9dcc08bc6ebc))
(pin "2" (uuid e042e7b2-9853-43dd-9d84-0a27309e347b))
(pin "2" (uuid e042e7b2-9853-43dd-9d84-0a27309e347b))
(pin "2" (uuid e042e7b2-9853-43dd-9d84-0a27309e347c))
(pin "2" (uuid e042e7b2-9853-43dd-9d84-0a27309e347c))
(pin "6" (uuid 2c89c0c4-ec2f-42de-81b6-e62c8d188968))
(pin "10" (uuid 95506ff9-4ec7-44f1-b5f7-87c53697753f))
(pin "5" (uuid d5cf600e-4c97-43db-818b-ea3248045403))
@@ -776,12 +776,12 @@
(property "LCSC Part" "C146412" (at 125.73 158.75 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid f3a4724f-c83e-4357-93f5-de2b64412a0b))
(pin "1" (uuid f3a4724f-c83e-4357-93f5-de2b64412a0b))
(pin "1" (uuid f3a4724f-c83e-4357-93f5-de2b64412a0c))
(pin "1" (uuid f3a4724f-c83e-4357-93f5-de2b64412a0c))
(pin "11" (uuid 381951b5-9e1d-46d9-9fdd-5023089bf34f))
(pin "12" (uuid 4a0f3bdc-1b3f-4b5a-9fdd-ad98ac9347e8))
(pin "2" (uuid e061c3c4-4715-4c93-a856-a0881bf59bac))
(pin "2" (uuid e061c3c4-4715-4c93-a856-a0881bf59bac))
(pin "2" (uuid e061c3c4-4715-4c93-a856-a0881bf59bad))
(pin "2" (uuid e061c3c4-4715-4c93-a856-a0881bf59bad))
(pin "6" (uuid c4b7cfc6-3923-4e8e-beab-8edfebf00db1))
(pin "10" (uuid 2f7d9d6f-7117-437c-a6f9-ab265c02086b))
(pin "5" (uuid 040e7810-ff19-4cb2-8089-e98a109dca74))
@@ -940,12 +940,12 @@
(property "LCSC Part" "C146412" (at 125.73 123.19 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid ac305c0b-c868-41dc-8758-5dddab10c0b3))
(pin "1" (uuid ac305c0b-c868-41dc-8758-5dddab10c0b3))
(pin "1" (uuid ac305c0b-c868-41dc-8758-5dddab10c0b4))
(pin "1" (uuid ac305c0b-c868-41dc-8758-5dddab10c0b4))
(pin "11" (uuid 5f952846-310c-40d4-879c-8b224fb60661))
(pin "12" (uuid 9720c386-328c-42a4-97c9-f29be92781fd))
(pin "2" (uuid 81d43ea9-5248-42eb-8446-126bd3fa7bc4))
(pin "2" (uuid 81d43ea9-5248-42eb-8446-126bd3fa7bc4))
(pin "2" (uuid 81d43ea9-5248-42eb-8446-126bd3fa7bc5))
(pin "2" (uuid 81d43ea9-5248-42eb-8446-126bd3fa7bc5))
(pin "6" (uuid 15056b44-bd76-49d3-97b1-8f239c766f7b))
(pin "10" (uuid 43fa4b5b-1368-473b-a20c-160035bf6d2e))
(pin "5" (uuid 9f25a38a-708f-427f-b757-bac5c276de82))

View File

@@ -63,6 +63,61 @@
)
)
)
(symbol "Device:R_Small_US" (pin_numbers hide) (pin_names (offset 0.254) hide) (in_bom yes) (on_board yes)
(property "Reference" "R" (at 0.762 0.508 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "R_Small_US" (at 0.762 -1.016 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "r resistor" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Resistor, small US symbol" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "R_*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "R_Small_US_1_1"
(polyline
(pts
(xy 0 0)
(xy 1.016 -0.381)
(xy 0 -0.762)
(xy -1.016 -1.143)
(xy 0 -1.524)
)
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
(pts
(xy 0 1.524)
(xy 1.016 1.143)
(xy 0 0.762)
(xy -1.016 0.381)
(xy 0 0)
)
(stroke (width 0) (type default))
(fill (type none))
)
(pin passive line (at 0 2.54 270) (length 1.016)
(name "~" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
(pin passive line (at 0 -2.54 90) (length 1.016)
(name "~" (effects (font (size 1.27 1.27))))
(number "2" (effects (font (size 1.27 1.27))))
)
)
)
(symbol "matei:MT6835" (in_bom yes) (on_board yes)
(property "Reference" "U" (at 0 6.35 0)
(effects (font (size 1.27 1.27)))
@@ -251,6 +306,9 @@
(junction (at 146.05 73.66) (diameter 0) (color 0 0 0 0)
(uuid c050be98-8733-4343-82eb-6a8bc4c61fd3)
)
(junction (at 107.95 91.44) (diameter 0) (color 0 0 0 0)
(uuid e9ddc7b2-ddae-4e9c-98ee-de21a32e5c45)
)
(junction (at 124.46 101.6) (diameter 0) (color 0 0 0 0)
(uuid efeed434-25e1-4ada-93c5-51cd20539f0b)
)
@@ -292,11 +350,15 @@
(stroke (width 0) (type default))
(uuid 50be6cbb-8da9-49ff-a2a2-17593a74f7f2)
)
(wire (pts (xy 107.95 88.9) (xy 107.95 91.44))
(stroke (width 0) (type default))
(uuid 6819fbaf-39f8-4754-9417-82a9f1dc55f9)
)
(wire (pts (xy 119.38 83.82) (xy 129.54 83.82))
(stroke (width 0) (type default))
(uuid 6e8ee9e1-4438-4fb1-9e14-7d086988ce2b)
)
(wire (pts (xy 119.38 91.44) (xy 129.54 91.44))
(wire (pts (xy 100.33 91.44) (xy 107.95 91.44))
(stroke (width 0) (type default))
(uuid 7c34d609-0011-4a6b-adb7-a8659573f4ec)
)
@@ -308,6 +370,10 @@
(stroke (width 0) (type default))
(uuid 981a896b-423c-482d-a31b-17ebee459d09)
)
(wire (pts (xy 107.95 91.44) (xy 129.54 91.44))
(stroke (width 0) (type default))
(uuid 9e3c9c72-b542-4bc3-bff1-45354ab73c88)
)
(wire (pts (xy 119.38 96.52) (xy 129.54 96.52))
(stroke (width 0) (type default))
(uuid b3b35712-9358-4d34-b0a2-b35961fd0ae0)
@@ -336,6 +402,10 @@
(stroke (width 0) (type default))
(uuid e0bb936b-d948-44a4-a5df-b362e23d1f8c)
)
(wire (pts (xy 107.95 81.28) (xy 107.95 83.82))
(stroke (width 0) (type default))
(uuid f8327758-a4a8-4e98-99ba-63e000032b60)
)
(wire (pts (xy 146.05 107.95) (xy 146.05 109.22))
(stroke (width 0) (type default))
(uuid fa3368e1-2af4-4b7b-a324-8c426adbfbe0)
@@ -369,7 +439,7 @@
(effects (font (size 1.27 1.27)) (justify right))
(uuid b1ce5263-dec0-46fb-af56-5bf098ef6a95)
)
(hierarchical_label "CS" (shape input) (at 119.38 91.44 180) (fields_autoplaced)
(hierarchical_label "CS" (shape input) (at 100.33 91.44 180) (fields_autoplaced)
(effects (font (size 1.27 1.27)) (justify right))
(uuid efb6c989-9aea-4b99-aac5-ddc98df1817c)
)
@@ -449,6 +519,46 @@
)
)
(symbol (lib_id "Device:R_Small_US") (at 107.95 86.36 0) (mirror y) (unit 1)
(in_bom yes) (on_board yes) (dnp no)
(uuid 6ce927d7-7f7d-4606-9fa7-f6da06fdd47b)
(property "Reference" "R?" (at 105.41 85.09 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "10k" (at 105.41 87.63 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Resistor_SMD:R_0402_1005Metric" (at 107.95 86.36 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (at 107.95 86.36 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "LCSC Part" "C25744" (at 107.95 86.36 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid beede6db-7ea6-40d8-ae90-f61670d652c4))
(pin "2" (uuid 622f4233-7a57-4ac1-b922-f15f27105aef))
(instances
(project "lemon-pepper"
(path "/0306e2fa-4433-4288-91d9-65a3484207ad/7f2d245a-6dca-4eb9-9839-7fdf255edd98"
(reference "R?") (unit 1)
)
(path "/0306e2fa-4433-4288-91d9-65a3484207ad/e3a86f21-c1c7-4a99-9511-7bc9966878a0"
(reference "R401") (unit 1)
)
)
(project "stm32g431-mt6701-stspin233"
(path "/bcb2c98d-7159-437a-9ffb-b81c5fcc4307"
(reference "R?") (unit 1)
)
(path "/bcb2c98d-7159-437a-9ffb-b81c5fcc4307/ed84ebbf-b2e5-4959-b495-bf58cd9b4c8c"
(reference "R203") (unit 1)
)
)
)
)
(symbol (lib_id "Device:C_Small") (at 172.72 78.74 0) (unit 1)
(in_bom yes) (on_board yes) (dnp no)
(uuid 94834f1b-05ab-4bcf-9674-3eb1092330b6)
@@ -478,6 +588,42 @@
)
)
(symbol (lib_id "power:+3V3") (at 107.95 81.28 0) (unit 1)
(in_bom yes) (on_board yes) (dnp no) (fields_autoplaced)
(uuid a957ced1-9f14-450e-a1f3-96a8f9bbe8a3)
(property "Reference" "#PWR0313" (at 107.95 85.09 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "+3V3" (at 107.95 76.2 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (at 107.95 81.28 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (at 107.95 81.28 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid bcb42574-5cf1-4371-9c33-6adb5d7ffbc7))
(instances
(project "lemon-pepper"
(path "/0306e2fa-4433-4288-91d9-65a3484207ad/7f2d245a-6dca-4eb9-9839-7fdf255edd98"
(reference "#PWR0313") (unit 1)
)
(path "/0306e2fa-4433-4288-91d9-65a3484207ad/e3a86f21-c1c7-4a99-9511-7bc9966878a0"
(reference "#PWR0404") (unit 1)
)
)
(project "stm32g431-mt6701-stspin233"
(path "/bcb2c98d-7159-437a-9ffb-b81c5fcc4307"
(reference "#PWR0107") (unit 1)
)
(path "/bcb2c98d-7159-437a-9ffb-b81c5fcc4307/ed84ebbf-b2e5-4959-b495-bf58cd9b4c8c"
(reference "#PWR0203") (unit 1)
)
)
)
)
(symbol (lib_id "matei:MT6835") (at 146.05 96.52 0) (unit 1)
(in_bom yes) (on_board yes) (dnp no) (fields_autoplaced)
(uuid efd8885f-06c2-415b-876b-2a36a953a464)

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"board": {
"active_layer": 31,
"active_layer": 0,
"active_layer_preset": "",
"auto_track_width": true,
"hidden_netclasses": [],

View File

@@ -1271,7 +1271,7 @@
(stroke (width 0) (type default))
(uuid 3084df01-ff3d-4638-8f75-5d51c11d2a7f)
)
(wire (pts (xy 83.82 87.63) (xy 73.66 87.63))
(wire (pts (xy 73.66 87.63) (xy 83.82 87.63))
(stroke (width 0) (type default))
(uuid 3096a0d9-9931-408e-bbd6-97595170acec)
)

View File

@@ -569,9 +569,6 @@
(junction (at 173.99 74.93) (diameter 0) (color 0 0 0 0)
(uuid 5d2a52ab-55d7-4a38-8e1b-429bf841385a)
)
(junction (at 123.19 87.63) (diameter 0) (color 0 0 0 0)
(uuid 6588ba2f-70c6-44e8-ab08-aac32efb47cc)
)
(junction (at 173.99 99.06) (diameter 0) (color 0 0 0 0)
(uuid 86ffa4b7-677e-4b32-b514-31c800b95737)
)
@@ -591,6 +588,8 @@
(uuid f1a5df6a-ada6-4727-8f1a-7f907e0ccb66)
)
(no_connect (at 130.81 87.63) (uuid ac2d505b-dcd7-4619-89f6-a7123e35adf3))
(wire (pts (xy 181.61 82.55) (xy 181.61 83.82))
(stroke (width 0) (type default))
(uuid 02cf0f03-cd3b-44a9-acbd-ca38791bf148)
@@ -647,10 +646,6 @@
(stroke (width 0) (type default))
(uuid 348e6076-04fa-4ea8-b99a-05e8ad697051)
)
(wire (pts (xy 123.19 85.09) (xy 123.19 87.63))
(stroke (width 0) (type default))
(uuid 3ded0528-768e-4ae4-bd42-2e042b142767)
)
(wire (pts (xy 181.61 83.82) (xy 181.61 85.09))
(stroke (width 0) (type default))
(uuid 485f7c0a-964a-4ab7-be2c-4eba1dd16ea5)
@@ -663,7 +658,7 @@
(stroke (width 0) (type default))
(uuid 4a2caf97-1cb4-4a38-b31f-c2cda8447639)
)
(wire (pts (xy 123.19 87.63) (xy 123.19 91.44))
(wire (pts (xy 123.19 85.09) (xy 123.19 91.44))
(stroke (width 0) (type default))
(uuid 4d820462-0b60-48b1-9c5b-1a8e90d940b8)
)
@@ -731,10 +726,6 @@
(stroke (width 0) (type default))
(uuid 95ebb92f-b13b-49a2-aaca-414deb706288)
)
(wire (pts (xy 123.19 87.63) (xy 130.81 87.63))
(stroke (width 0) (type default))
(uuid a9c7e012-c780-4a46-8b7a-38b471f915e2)
)
(wire (pts (xy 58.42 71.12) (xy 78.74 71.12))
(stroke (width 0) (type default))
(uuid abb0d478-ba77-48e5-98bf-fc21c9d0cf82)

View File

@@ -23,7 +23,7 @@ board_build.f_cpu = 168000000
framework = arduino
upload_protocol = stlink
debug_tool = stlink
; monitor_port = /dev/cu.usbmodem207C345A56501
monitor_port = /dev/cu.usbmodem208A318D42531
monitor_speed = 115200
monitor_eol = LF
build_flags =
@@ -37,7 +37,7 @@ build_flags =
-D PCB_REV1 ; or PCB_REV2
lib_deps =
askuric/Simple FOC@^2.2.3
simplefoc/SimpleFOCDrivers@^1.0.2
askuric/Simple FOC@^2.3.1
simplefoc/SimpleFOCDrivers@^1.0.5
lib_archive = false