Problems with custom firmware for ODrive v3.5 using SimpleFoc

i try to make custom firmware based on odrive v3.5 hardware. it uses driver DRV8301 and stmf405. i use a atm 103v encoder for a bldc motor.
moreover, i use a drv8301 lib developed probably by simplefoc: GitHub - QPLover/Arduino_SimpleFOC_DRV8301_Support_Library: Arduino DRV8301 library support for SimpleFOC, it also can use alone without SimpleFOC library

but when i run my code nothing happens. i’m new with simple foc. please help to find right way to solve this problem.

#include <DRV8301.h>
#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7, 0.03368961, 420);
BLDCDriver6PWM driver = BLDCDriver6PWM(PC6, PA7, PC7, PB0, PC8, PB1, PB12);
DRV8301 gate_driver = DRV8301(PC12, PC11, PC10, PC14, PB12, PD2);
Encoder encoder = Encoder(PB6, PB7, 2048);
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}

void setup() {
  pinMode(PA0, OUTPUT);

  encoder.enableInterrupts(doA, doB);

  driver.voltage_power_supply = 20;
  driver.dead_zone = 0.005;

  motor.controller = MotionControlType::velocity_openloop;

  motor.current_limit = 50;
  motor.voltage_limit = 12;

  // angle loop velocity limit
  motor.velocity_limit = 50;



float target_velocity = 5;  // [rad/s]
int kek = 0;

void loop() {
  kek = (kek + 1) % 2;
  digitalWrite(PA0, kek);

  // open loop velocity movement
  // using motor.voltage_limit and motor.velocity_limit

there is a schematic of odrive v3.5

i use the “motor 1” part of odrive

Hey Leo,

For standard operation of the Odrive v3.5 with the SimpleFOC you dont need the DRV8301 library.
There is an example code in the library examples that covers your use case more or less exactly:

You can access it directly using the Arduino IDE or just copy the code from the github to your sketch. :smiley:

1 Like

I tried to run this code with the spi template for the as5047 magnetic encoder and found an interesting problem

when activating the driver in BLDCDriver6PWM::enable(); the magnetic encoder only responds with zeros. because of this the motor cannot calibrate. when disabling the driver all responses from the encoder will be correct.

I have never had an issue like that to be honest. :smiley:
Can you share a bit more info,

  • sensor
  • code
  • hardware connections made

It will be easier to figure out what’s wrong

I use exactly the same code as here Arduino-FOC/odrive_example_spi.ino at master · simplefoc/Arduino-FOC · GitHub

my sensor is as5047p. i power the module from 3.3V. specific module here

motor is Surpass Hobby C3548-790KV ÜBERTREFFEN HOBBY 2826 C3548 790KV 900KV 1100KV Bürstenlosen Motor für RC Flugzeug Fest flügel Segelflugzeug Flugzeug|Teile & Zubehör| - AliExpress

hardware connections are default as in the defines in the code above.

The magnetic encoder is 99% still alive, because before the driver is on and after it is off, it works fine. but when I set the driver’s EN_GATE up, the encoder starts returning only zeros.

Ok, great.

I’ve got almost exactly the same setup and did not have such issues so far, so I’m pretty confident that its not an issue of the SPI communication.

Where did you connect the CS of your magnetic sensor?
To M0_INH_A?

This might be an issue with the magnet also, radially/axially polarized magnet issues.
When the driver is not enabled the interference is not big and the sensor kinda works fine, but when a bit of current passes through the motor it creates enough noise so that the sensor cannot read the anything anymore.

Also, is it an original Odrive or an aliexpress one ?
I’ve got an aliexpress one, able to drive only one moror.

no, cs of the encoder is connected to M0_ENC_A.

odrive from aliexpress too

i’ve checked that my magnet is radially

сould you please give advice on how to reduce the noise from the driver?

That’s great.

Is your encoder set up for 3.3V logic, is the jumper at the good position?

Huh, I am not sure how to test this well. You can try to disconnect the motor wires. This should reduce the noise as there is no current passing through the driver. If without the motor you still have the same behavior, then the noise is probably not the issue.

I finally figured out what the problem was.

In the init function in the example code you sent me, I manually set the drivers’ chip selects to high positions. This solved my problem.

Thank you very much Antun for your help!