Hi!
I’ve finally decided to ask for some help or thoughts, been reading the pages about setting up Storm32 BGC 1.32 to run 3 BLDC motors using SimpleFOC and as5048a encoders for feedback with SPI.
I can upload programs to the Storm32 BGC 1.32 using St-link and Platformio, I can make lights blink, and run a motor in openloop velocity using simpleFOC (using just one for testing purposes).
I can get the closed loop working with an arduino UNO and simpleFOC shield.
However I can’t get past motor initialization on the Storm32 with SPI for the as5048a.
I have soldered SCLK line to LED1 after removing the 2.2K resistor running to it, and I get a high pitched whirring from the motor as it searches back and forth and tries to align with the encoder, then gives up.
After going through the SimpleFOC library and BLDCMotor file, the initialization calls BLDCMotor:alignSensor() to find electrical zero angle.
I’m assuming the SCLK line is not functioning properly, so the motor can’t find the encoder Zero angle, so it quits and fails initialization?
I unplugged everything and removed the soldered SCLK line to LED1/PB13 to see what it looks like, have I screwed up that pin and that’s why I wasn’t getting a good SCLK signal?
Heres my wiring,
CS white = pot2/ PA15/aux2
SCLk red = LED1 PB13
MOSI black = PB15
MISO yellow = PB14
Grd Blue = Grnd
Green 3.3v = 3.3v
Heres my Platformio, its largely what @runger has provided in previous responses to attempts at this.
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:genericSTM32F103RC]
platform = ststm32
board = genericSTM32F103RC
framework = arduino
monitor_speed = 115200
#lib_archive = false
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USBD_VID=0x0483
-D USBD_PID=0x5740
-D USB_MANUFACTURER="runger"
-D USB_PRODUCT="\"Storm32_SPM\""
-D HAL_PCD_MODULE_ENABLED
lib_deps =
# RECOMMENDED
# Accept new functionality in a backwards compatible manner and patches
https://github.com/simplefoc/Arduino-FOC.git
#SPI
Heres the main as well
#include <Arduino.h>
#include "Wire.h"
#include "SPI.h"
#include "SimpleFOC.h"
#define V_PSU 10
#define V_LIMIT 10
#define V_INIT_LIMIT 10
// 3.3v is green on
MagneticSensorSPIConfig_s AS5048 = {
.spi_mode = SPI_MODE1,
.clock_speed = 1000000,
.bit_resolution = 14,
.angle_register = 0x3FFF,
.data_start_bit = 13,
.command_rw_bit = 14,
.command_parity_bit = 15
};
// Note: Storm32 SPI2 is PB13 == LED1 == CLK, PB14 == AUX0 == MISO, PB15 == AUX1 == MOSI
// Solder CLK line to PB13, which can be found on the 2k2 resistor R7 (see schematic) in the LED1 path
// top ring motor
#define SENSOR1_CS PC2 // POT2 //PA15 // AUX2 //White
MagneticSensorSPI sensor1 = MagneticSensorSPI(AS5048, SENSOR1_CS);
BLDCMotor motor1 = BLDCMotor(7);
BLDCDriver3PWM driver1 = BLDCDriver3PWM(PB1, PB0, PA7);
float target1;
void initMotors() {
pinMode(SENSOR1_CS, OUTPUT);
digitalWrite(SENSOR1_CS, 1);
sensor1.init();
motor1.linkSensor(&sensor1);
driver1.voltage_limit = V_LIMIT;
driver1.voltage_power_supply = V_PSU;
driver1.init();
motor1.linkDriver(&driver1);
motor1.voltage_limit = V_LIMIT;
motor1.voltage_sensor_align = V_INIT_LIMIT;
motor1.controller = MotionControlType::angle;
motor1.PID_velocity.P = .1;
motor1.PID_velocity.I = 20;
motor1.PID_velocity.D = 0;
motor1.PID_velocity.output_ramp = 1000;
motor1.LPF_velocity.Tf = .01;
motor1.P_angle.P = 1;
motor1.init();
motor1.initFOC();
// TODO store motor initialization params and only re-init if we can't load them (and provide a command to reset them)
motor1.sensor_offset = motor1.shaftAngle();
target1 = 20;
}
void setup() {
pinMode(PB12, OUTPUT);
digitalWrite(PB12, 1); // switch on lED for initialization
delay(2000);
digitalWrite(PB12,0);
delay(500);
motor1.velocity_limit = 10;
SPI.setMOSI(PB15); //Black
SPI.setMISO(PB14); //yellow
SPI.setSCLK(PB13); // Red
initMotors();
//Serial.println("SPM motor initialization complete.");
//digitalWrite(PB12,0);
}
void loop() {
//Serial.println("Loop running...");
//delay(1000); // Just to slow down the prints
}
Thanks for any ideas!