Hello @runger
Thank you very much for your help and feedback. I had a look at the Encoder and it’s the same one as FinderSiri posted. And I found the cable My bad!!
But im still stuck that the motor in not turning.
I did the same wiring as this Image, the ORG version.
@runger could you please have a look at my code? Maybe im too blond or don’t understand what im missing. Thanks!!!
#include “Arduino.h”
#include “Wire.h”
#include “SPI.h”
#include “SimpleFOC.h”
#include “SimpleFOCDrivers.h”
#include “encoders/as5048a/MagneticSensorAS5048A.h”
// init BLDC motor
BLDCMotor motor = BLDCMotor(9, 5.8);
// init driver
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 8, 7, 6);
// init encoder
#define SENSOR1_CS 10 // some digital pin that you’re using as the nCS pin
MagneticSensorAS5048A sensor1(SENSOR1_CS);
// angle set point variable
float target_angle = 0;
// commander interface
Commander command = Commander(Serial);
void onTarget(char* cmd){ command.scalar(&target_angle, cmd); }
void setup() {
// initialize magnetic sensor hardware
sensor1.init();
// power supply voltage
// default 12V
driver.voltage_power_supply = 12;
driver.init();
//pinMode(7,OUTPUT); // declares pin 12 as output and sets it to LOW
// link the motor to the driver
motor.linkDriver(&driver);
// set control loop to be used
motor.controller = MotionControlType::angle;
// controller configuration based on the control type
// velocity PI controller parameters
// default P=0.5 I = 10
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
//default voltage_power_supply
motor.voltage_limit = 12;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor.LPF_velocity.Tf = 0.01;
// angle P controller
// default P=20
motor.P_angle.P = 20;
// maximal velocity of the position control
// default 20
motor.velocity_limit = 4;
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// add target command T
command.add(‘T’, onTarget, “target angle”);
// monitoring port
Serial.begin(115200);
Serial.println(“Motor ready.”);
Serial.println(“Set the target angle using serial terminal:”);
_delay(1000);
}
void loop() {
// iterative FOC function
motor.loopFOC();
// function calculating the outer position loop and setting the target position
motor.move(target_angle);
// user communication
command.run();
}