Hello,
I’m new to the forum. First of all I appreciate the time reading my concern.
I’m using a Teensy 4.1 with the BOSTXL-DRV8301 to test the Controller with the Teensy. When I run the motor another interrupt gets activated. I’ve spent several days trying to find why this is happening but I can’t figure out. I attached a screen capture of my results. I did the 3 new prototypes and still get the same results; can anyone point out what I’m missing?
Constraints: I need to use Teensy and I need to measure the RPM from the interrupt specified in my code. I’m open to change the Driver but It needs to handle a lot of RPM/Current (100K RPM, ~30-50A) for an RC application.
Here is my code:
// Open loop motor control example
#include <SimpleFOC.h>
#include <DRV8301.h>
#define rpm_PIN 5
#define INHA 3
#define INLA 2
#define INHB 8
#define INLB 7
#define INHC 29
#define INLC 28
#define HALLA 6
#define HALLB 9
#define HALLC 14
#define DRV_EN_GATE 17
#define DRV_CS 10
#define DRV_MOSI 11
#define DRV_MISO 12
#define DRV_CLK 13
#define FAULT 24
// Motor instance
BLDCMotor motor = BLDCMotor(4);
BLDCDriver3PWM driver = BLDCDriver3PWM(INHA, INHB, INHC);
// DRV8301 gate_driver = DRV8301(MOSI, MISO, SCLK, CS, EN_GATE, FAULT);
DRV8301 gate_driver = DRV8301(DRV_MOSI, DRV_MISO, DRV_CLK, DRV_CS, DRV_EN_GATE, FAULT);
// hall sensor instance
HallSensor sensor = HallSensor(HALLA, HALLB, HALLC, 4);
// Interrupt routine intialisation
// channel A, B and C callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
void setup()
{
// initialize encoder sensor hardware
//sensor.init();
//sensor.enableInterrupts(doA, doB, doC);
// link the motor to the sensor
//motor.linkSensor(&sensor);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 6;
driver.init();
gate_driver.begin(PWM_INPUT_MODE_3PWM);
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
motor.voltage_limit = 0.2; // [V]
motor.velocity_limit = 20; // [rad/s]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
Serial.begin(115200);
Serial.println("Motor ready!");
_delay(1000);
pinMode(rpm_PIN, INPUT_PULLDOWN);
attachInterrupt(rpm_PIN, interrupt_BLDC_RPM, FALLING );
}
float target_velocity = 0; // [rad/s]
void loop()
{
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
motor.move(target_velocity);
// receive the used commands from serial
serialReceiveUserCommand();
}
// utility function enabling serial communication with the user to set the target values
// this function can be implemented in serialEvent function as well
void serialReceiveUserCommand()
{
// a string to hold incoming data
static String received_chars;
while (Serial.available())
{
// get the new byte:
char inChar = (char)Serial.read();
// add it to the string buffer:
received_chars += inChar;
// end of user input
if (inChar == '\n')
{
// change the motor target
target_velocity = received_chars.toFloat();
Serial.print("Target velocity ");
Serial.println(target_velocity);
// reset the command buffer
received_chars = "";
}
}
}
void interrupt_BLDC_RPM()
{
/*rev_count_t = micros();
rev_count++;
//read_sensors();
Serial.print(rev_count_t);
Serial.print("\t");
Serial.println(rev_count);*/
Serial.println("Test 1");
}