Arduino-FOC-dcmotor icon indicating copy to clipboard operation
Arduino-FOC-dcmotor copied to clipboard

BUG? enable_active_high logic inverted

Open rambrosteam opened this issue 5 months ago • 0 comments

MCU: Esp32-S3 Driver IC: DRV8212

Here's the modified code from the open loop example.

#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleDCMotor.h"

#define enPin 11
#define pwm1pin 14
#define pwm2pin 15
DCDriver2PWM driver = DCDriver2PWM(pwm1pin, pwm2pin, enPin);

void setup() {
  driver.voltage_power_supply = 10.0f;
  driver.voltage_limit = 10.0f;
  // init driver
  driver.init();
  // this enables the driver
  driver.enable();
}
void loop() {
  driver.setPwm(5.0f);
  delay(1000);
}

I think this is reversed since drivers like these are usually enabled when the sleep pin is HIGH image

All the drivers have this in their init() function: digitalWrite(pinEN, enable_active_high ? LOW : HIGH); If this is infact the issue, then this fixes the issue digitalWrite(pinEN, enable_active_high ? HIGH : LOW);

If it is an issue with just the open loop example: calling enable function after init() would fix this driver.enable();

My use case is pretty simple, I just want to drive Brushed motors with mcpwm using arduino compatible code. I'm have created this issue since I'm not sure if it is a library bug or just a bug with the open loop example.

Anyway thanks again @runger1101001, This seems to be the only arduino compatible library that supports the mcpwm

rambrosteam avatar Sep 17 '24 11:09 rambrosteam