PID no longer works

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();
      }

      
    }

  }


}

Was this code working before? What did you change since last time?

I’ve changed a lot since…
what surprises me, when I hold the motor by hand to force it, my traces on the oscilloscope do not vary, it does not regulate!

The modifications in the setup are not all taken into account.
For example the speed limit is not taken into account!
motor. velocity_limit = 5;
does not work for example

This sounds more like a compiler/environment problem? Can you flash your program changes to the Teensy successfully?

Hello, a bit late.
I use the BLDC-SHIELD_IFX007T shield
Yes I can flash my teensy and change the torque or the speed, even with my can bus
My hall sensors give the information with the example provided

When I block the motor by hand, the rotation cycle continues, like a stepper motor losing its steps.
I dry !!!

I reinstalled windows

Hi @Terrium7,

Which mode are you using? The behaviour you describe sounds like open loop mode?

Hello, Hello, can it come from this line?
I made a lot of modifications during this period.

I use hall sensors

Perhaps I don’t fully understand what’s going on here but you seem to have three problems:

  1. You use BLDCDriver3PWM like a BLDCDriver6PWM
  2. If you want BLDCDriver6PWM you need to call like

BLDCDriver3PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL, ENABLE);

but you must make sure the pins are correctly assigned, don’t just copy my line because I have no idea what pins you got for those phases.

  1. If you need BLDCDriver3PWM, you need to call like

BLDCDriver3PWM(PHASE_U, PHASE_V, PHASE_W, ENABLE);

but you must make sure the pins are correctly assigned, don’t just copy my line because I have no idea what pins you got for those phases.

In both cases ENABLE is optional depending on your hardware.

In any event, you must first read

and

to learn the basics.

Cheers,
Valentine

I corrected but I still have no regulation

BLDCDriver3PWM driver = BLDCDriver3PWM(PHASE_Ph_U, PHASE_Ph_V, PHASE_Ph_W, 3);

and

void setup() {
    digitalWrite(PHASE_En_V, HIGH);
    digitalWrite(PHASE_En_W, HIGH);

could I burn out my two infineon shields because of this error?

Why are you setting them high?

Please read the examples very carefully.

Cheers,
Valentine

I had a dead Hall sensor :rage: :rage: :rage: :rage:

So did you problem get fixed?