目录

前言&&准备材料

arduino程序

参考链接:


前言&&准备材料

我这里用的控制器是esp32,它的adc采集器分辨率是12位,工作电压是3.3V。因此我们读取到的模拟数值0~4096就是对应的0~3.3V。

这里我的ina240型号是I240A2。也就是说ina240的增益是50V/V。

我的驱动器型号是simplefoc v0.2。采用内置电流采样,具体电流采样电路如下图:

双向

arduino程序

/**使用电压控制回路的扭矩控制示例。大多数低端无刷电机驱动器没有电流测量功能,因此SimpleFOC为您提供了一种通过设置电机电压而不是电流来控制电机扭矩的方法。这使无刷直流电机有效地成为直流电机,您可以以相同的方式使用它。
*/
// 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 <SimpleFOC.h>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 hardwareI2Cone.begin(18, 5, 400000);sensor.init(&I2Cone);// link the motor to the sensormotor.linkSensor(&sensor);// power supply voltagedriver.voltage_power_supply = 12;driver.init();motor.linkDriver(&driver);// aligning voltagemotor.voltage_sensor_align = 5;// choose FOC modulation (optional)motor.foc_modulation = FOCModulationType::SpaceVectorPWM;// set motion control loop to be usedmotor.controller = MotionControlType::torque;// use monitoring with serialSerial.begin(115200);// comment out if not neededmotor.useMonitoring(Serial);// initialize motormotor.init();// align sensor and start FOCmotor.initFOC();// add target command Tcommand.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 ~10kHzmotor.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 codemotor.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 communicationcommand.run();
}

串口打印效果:

用Baize_Foc的测试代码

/**使用电压控制回路的扭矩控制示例。大多数低端无刷电机驱动器没有电流测量功能,因此SimpleFOC为您提供了一种通过设置电机电压而不是电流来控制电机扭矩的方法。这使无刷直流电机有效地成为直流电机,您可以以相同的方式使用它。
*/
// 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 <SimpleFOC.h>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(17, 18, 19, 21, 22, 23);InlineCurrentSense Cs_motor(0.001, 50.0, 34, 35);// 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 hardwareI2Cone.begin(26, 25, 400000);sensor.init(&I2Cone);// link the motor to the sensormotor.linkSensor(&sensor);// power supply voltagedriver.voltage_power_supply = 12;driver.init();motor.linkDriver(&driver);// aligning voltagemotor.voltage_sensor_align = 5;// choose FOC modulation (optional)motor.foc_modulation = FOCModulationType::SpaceVectorPWM;// set motion control loop to be usedmotor.controller = MotionControlType::torque;// use monitoring with serialSerial.begin(115200);// comment out if not neededmotor.useMonitoring(Serial);// initialize motormotor.init();// align sensor and start FOCmotor.initFOC();// add target command Tcommand.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 ~10kHzmotor.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 codemotor.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 communicationcommand.run();
}

参考链接:

1.【INA240】产品参数介绍、INA240数据手册、中英文PDF资料下载-TI资料-电子发烧友

2.

INA240三相无刷电机电流采样实例(arduino)相关推荐

  1. SimpleFOC移植STM32(五)—— 电流采样及其变换

    目录 一.原理说明 1.1.电流采样 1.1.1.为什么要采样电流 1.1.2.电流采样方式 1.1.2.1.低侧电流采样 1.1.2.2.高侧电流采样 1.1.2.3.内置电流采样 1.2.电流变换 ...

  2. FOC 电流采样为什么不准?你忽略了这个细节

    文章目录 1 引言 2 延迟类型及典型时间 3 延迟源详细分析 3.1PWM死区时间插入 3.2 光耦延迟和预驱动器延迟 3.3晶体管开关延迟 3.4其他延迟 4 结语 在电机驱动的FOC控制开发过程 ...

  3. 基于PSoC4的矢量控制方案 :电流采样

    Cypress在2013年3月推出PSoC4可编程片上系统架构, 它将赛普拉斯一流的PSoC模拟和数字架构以及业界领先的CapSense电容式触摸技术同ARM的低功耗Cortex-M0内核完美相结合. ...

  4. FOC——13.电流采样与运放电路

    文章目录 1.电流采样方案 1.1.不同数量的采样电阻方案 1.2.采样电阻的位置 1.3.采样窗口问题 2.运放电路 2.1.运放和比较器 2.2.差分放大 2.3.偏置电压 2.4.运放放大倍数的 ...

  5. FOC 电流采样方案对比(单电阻/双电阻/三电阻)

    原文:https://www.cnblogs.com/unclemac/p/12783352.html 文章目录 1 电流采样的作用 2 硬件架构 3 采样关键 4 采样方案 5 三电阻采样 5.1 ...

  6. 双电阻差分电流采样_矢量控制中的常见电流检测方式

    矢量控制技术中,一个关键的技术环节是相电流的采集和重构.电流采集方式有多种,但是鉴于成本和易用性的考虑,目前应用较多的电流采集方式只有三种.单电阻法.双电阻法以及三电阻法. 1 单电阻采集方案,成本低 ...

  7. 永磁同步电机控制系统——电流采样

    文章目录 前言 一.电流采样注意事项 二.电流采样时刻 1. 规则通道 2. 注入通道 总结 前言 在电机控制中,电流环是最重要的环节,是整个控制系统的核心.电流环涉及一个最基础的问题,那就是电流采样 ...

  8. 基于FPGA的FOC电流采样Bug调试记录

    #基于FPGA的FOC电流采样Bug调试记录 博主在调试FOC闭环控制中遇到了一个bug,冥思苦想两三天,最终一步步地调试时序,最终找到了bug,在调试过程中学会了debug的思想,也明白了调试过程中 ...

  9. 三相无刷电机驱动STC

    三相无刷电机驱动-STC8H1K28 /**********************************************/ void main(void) {u8 i;u16 j;P2n_ ...

最新文章

  1. python中平均值函数_python自定义函数ma(x,y)求简单平均值输出结果到列表
  2. 检查Bash数组是否包含值
  3. linux 进程数量限制,LINUX下每进程限制线程数量
  4. win10 便签无法联网_便签 | win10无法搜索到wifi的解决方案
  5. 史上最详细最容易理解的HMM文章
  6. mariadb数据库备份与恢复
  7. RegExp 构造函数
  8. mac下打开多个相同应用程序
  9. ES6更新的3种精简化代码,(1.速写属性 2.速写方法 3.模板字符串)
  10. 嵌入式软件设计第11次实验报告
  11. SpringBoot项目从IE浏览器跳转至谷歌浏览器并打包成windows环境下可行EXE文件
  12. SimpleITK读取DCM文件
  13. ARM版本的IAR的下载和安装
  14. 计算机编程领域最伟大的20个发明
  15. JS实现浏览器打印、打印预览
  16. 少儿编程兴起,作为老一辈程序员的你,怕了么?
  17. Javascript(JS) leetcode 804. 唯一摩尔斯密码词
  18. 最牛散户最新版唐亮一年获利超3亿
  19. 数据挖掘算法之时间序列算法(平稳时间序列模型,AR(p),MA(q),(平稳时间序列模型,AR(p),MA(q),ARMA(p,q)模型和非平稳时间序列模型,ARIMA(p,d,q)模型)学习笔记梳理
  20. 超全金属PBR多通道贴图素材网站整理

热门文章

  1. unity水下模糊效果
  2. 小游戏之斗兽棋(uniapp)
  3. 微信支付分700分,有什么好处?
  4. 2022谷粒商城学习笔记(二十二)rabbitMQ学习
  5. 搭建智能语音交互系统重要点那些
  6. Android sockot连接打印机EPSON ESC/POS指令打印
  7. Excel2013打印时怎么固定表头及表尾让打印后的每页都可以看得到
  8. 山东科技大学计算机学院奖学金,山东科技大学:一份特殊“奖学金”
  9. 过零检测法MATLAB仿真,过零检测 - MATLAB Simulink - MathWorks 中国
  10. base ring shell skirt skirt 压力容器_压力容器工程规定(2)