全球最实用的IT互联网信息网站!

AI人工智能P2P分享&下载搜索网页发布信息网站地图

当前位置:诺佳网 > 电子/半导体 > 工业控制 >

SimpleFOC之多路PWM驱动,相电流监测2

时间:2023-04-24 11:29

人气:

作者:admin

标签: 功率器件  IGBT  开关  MOS 

导读:开关元器件的和严格意义并不是相同的。IGBT,MOS并不是理想开关器件,其开通时间和关断时间不是严格一致的,如果两端有电压,将导致直流电源短路,损坏桥臂功率器件,称之为“桥...

低侧电流测试

低侧电流检测可能是最常见的电流检测技术。主要原因是它既不需要高性能PWM抑制电流检测放大器(如在线检测放大器),也不需要支持高压的放大器(如高侧放大器)。

采样电阻始终置于低侧MOSFET和地之间,确保放大器的端子上始终具有非常低的电压。这种方法的主要缺点是,由于只有相应的低侧mosfet开启时,通过采样电阻的电流才是相电流,而我们只能在这些时刻测量到相电流。PWM频率通常为20至50 kHz,这意味着低侧MOSFET每秒开关20000至50000次,因此PWM设置和ADC采集之间的同步非常重要。

目前这个在开发中。

图片

这个是高测测量一般也不用

https://www.ti.com.cn/product/cn/INA240
https://www.elecfans.com/analog/202007151246626.html
https://zhuanlan.zhihu.com/p/401573207
https://www.sohu.com/a/439655421_468638
https://baijiahao.baidu.com/s?id=1753450617334241521&wfr=spider&for=pc
https://m.elecfans.com/article/1107269.html
https://www.elecfans.com/d/1412716.html
// IN1     pwm1    9  27
// IN2     pwm2    6  26
// IN3     pwm3    5  25
// INH1   enable1  8  12
// INH2   enable2  7  13
// INH3   enable3  4  14
// in-line current sense - phase 1/A 35
// in-line current sense - phase 1/C 34


#include 


class LowPassFilte
{
public:
    LowPassFilte(float Tf); // 低通滤波器时间常量
    ~LowPassFilte() = default;
    float operator()(float x);
    float Tf; //!< 低通滤波器时间常量
protected:
    unsigned long timestamp_prev; //!< 上次执行时间戳
    float y_prev;                 //!< 经过上次执行后过滤到的值
};


LowPassFilte::LowPassFilte(float time_constant)
    : Tf(time_constant), y_prev(0.0f)
{
    timestamp_prev = micros();
}


float LowPassFilte::operator()(float x)
{
    unsigned long timestamp = micros();
    float dt = (timestamp - timestamp_prev) * 1e-6f;


    if (dt < 0.0f || dt > 0.5f)
        dt = 1e-3f;


    float alpha = Tf / (Tf + dt);
    float y = alpha * y_prev + (1.0f - alpha) * x;


    y_prev = y;
    timestamp_prev = timestamp;
    return y;
}


LowPassFilte LF_a(0.01); // 原始数据滤波器
LowPassFilte LF_b(0.01); // A相电流滤波器
LowPassFilte LF_c(0.01); // C相电流滤波器


// AS5600编码器支持spi,iic和模拟量三种数据传输方式,这里用iic(同时也是最常用的方式)
//  magnetic sensor instance - I2C
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
TwoWire I2Cone = TwoWire(0);


// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(27, 26, 25, 12, 13, 14);


InlineCurrentSense Cs_motor(0.001, 50.0, 35, 36, 34);


// voltage set point variable
float target_voltage = 5.0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char *cmd)
{
    command.scalar(&target_voltage, cmd);
}


void setup()
{
    // initialise magnetic sensor hardware
    I2Cone.begin(18, 5, 400000);
    sensor.init(&I2Cone);
    // link the motor to the sensor
    motor.linkSensor(&sensor);


    // power supply voltage
    driver.voltage_power_supply = 12;
    driver.init();
    motor.linkDriver(&driver);


    // aligning voltage
    motor.voltage_sensor_align = 5;
    // choose FOC modulation (optional)
    motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
    // set motion control loop to be used
    motor.controller = MotionControlType::torque;


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


    // add target command T
    command.add('T', doTarget, "target voltage");


    Serial.println(F("Motor ready."));
    Serial.println(F("Set the target voltage using serial terminal:"));
    _delay(1000);


    Cs_motor.init();
}


void loop()
{


    // main FOC algorithm function
    // the faster you run this function the better
    // Arduino UNO loop  ~1kHz
    // Bluepill loop ~10kHz
    motor.loopFOC();
    // Motion control function
    // velocity, position or voltage (defined in motor.controller)
    // this function can be run at much lower frequency than loopFOC() function
    // You can also use motor.move() and set the motor.target in the code
    motor.move(target_voltage);


    // Cs_motor.getPhaseCurrents();
    Serial.print(LF_b((Cs_motor.getPhaseCurrents()).a));
    Serial.print(",");
    Serial.println(LF_c((Cs_motor.getPhaseCurrents()).c));


    //  Serial.print(LF_a(analogRead(35)));
    //  Serial.print(",");
    //  Serial.print(LF_b((3.3 * ((float)analogRead(35) - 1930) / 4096.0) * 20.0));
    //  Serial.print(",");
    //  Serial.println(LF_c((-3.3 * ((float)analogRead(34) - 1930) / 4096.0) * 20.0));


    // user communication
    command.run();
}
温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信