Hello, I use a teensy and an IFX007T and a hoveboard motor.
But for some time I can no longer make software adjustments,
I can only change / motor.move(); or the switching frequency. But I have no power to my motor, no torque
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can2;
CAN_message_t msg;
int StBy = 2; // Stby CanBus
int ReceptionPwm = 0 ;
float Cible = 0 ;
int SensDeRotation = 0 ;
int freewheel = 0 ;
int freewheelTemp = 0 ;
float Couple = 0;
#include <SimpleFOC.h>
#define PHASE_UH 6
#define PHASE_VH 7
#define PHASE_WH 8
#define PHASE_UL 3
#define PHASE_VL 4
#define PHASE_WL 5
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(15, 0.8);
BLDCDriver3PWM driver = BLDCDriver3PWM(PHASE_UH, PHASE_VH, PHASE_WH, PHASE_UL, PHASE_VL, PHASE_WL);
HallSensor sensor = HallSensor(21, 20, 19, 15); //21 20 19
void doA() {
sensor.handleA();
}
void doB() {
sensor.handleB();
}
void doC() {
sensor.handleC();
}
void setup() {
///////bus can fred///////
pinMode(StBy, OUTPUT);
digitalWrite(StBy, LOW);
Can2.begin();
Can2.setBaudRate(500000);
// initialize encoder sensor hardware
sensor.init();
sensor.enableInterrupts(doA, doB, doC);
motor.linkSensor(&sensor);
driver.pwm_frequency = 18000;
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
// aligning voltage
motor.voltage_sensor_align = 12;
// choose FOC modulation (optional)
motor.foc_modulation = FOCModulationType::SinePWM; // default
//motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
//motor.controller = MotionControlType::angle;
motor.controller = MotionControlType::torque;
//motor.controller = MotionControlType::velocity;
// use monitoring with serial
Serial.begin(115200);
// comment out if not needed
// motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align sensor and start FOC
motor.initFOC();
// velocity PI controller parameters
motor.PID_velocity.P = 0.02 ;//0.2
motor.PID_velocity.I = 1;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 8;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 3000;//300
// 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.05f;
// add target command T
//command.add('T', doTarget, "target voltage");
_delay(1000);
motor.enable();
//motor.disable();
}
void loop() {
motor.loopFOC();
motor.move(3); // for test
if ( Can2.read(msg) )
{
ReceptionPwm = msg.buf[0];
Cible = (float)ReceptionPwm / 20 ;//50 le 06/06/2022
SensDeRotation = msg.buf[1];
freewheel = msg.buf[2];
if (SensDeRotation == 0)//sens de rotation 0 ou 1
{
motor.move(Cible);
}
else
{
motor.move(Cible * (-1));
}
if (freewheelTemp != freewheel)
{
freewheelTemp = freewheel;
if (freewheel == 0)
{
motor.disable();
pinMode(PHASE_UH, INPUT_PULLDOWN);
pinMode(PHASE_UL, INPUT_PULLDOWN);
pinMode(PHASE_VH, INPUT_PULLDOWN);
pinMode(PHASE_VL, INPUT_PULLDOWN);
pinMode(PHASE_WH, INPUT_PULLDOWN);
pinMode(PHASE_WL, INPUT_PULLDOWN);
}
else
{
pinMode(PHASE_UH, OUTPUT);
pinMode(PHASE_UL, OUTPUT);
pinMode(PHASE_VH, OUTPUT);
pinMode(PHASE_VL, OUTPUT);
pinMode(PHASE_WH, OUTPUT);
pinMode(PHASE_WL, OUTPUT);
motor.enable();
}
}
}
}