1 Star 0 Fork 3

rongxie/k-tx-foc

forked from kp9527/k-tx-foc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
svpwm_calculate_label.py 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
kp9527 提交于 2023-10-18 20:10 . 2023-10-18
# 计算公式
# 推到逻辑
# 载波为三角波,三角波顶点是B,三角波与sin波交点是A,三角波周期T,利用A点围成的三角形作为的底边作为Ton的时间
# OA/OB = Ton/T
# Ton = T * OA / OB
# OB = 1;OA = sin(wt) w=角速度,t时间积分
# 先需要求出不同幅值的正弦波波形
# 现在假设三角波周期幅值不变,三角波幅值Uc 需要求的正弦波幅值Us(yi'zhi)
# Ton = T * sin(wt) * Us / Uc
#制表标准
#只做弦波的正半波型,负半波一样
#计算公式 table[] = sin(rad) rad = 0~pi
import numpy as np
import matplotlib.pyplot as plt
#---------------------制表
#原理 将2pi分成512等分
table_num = 512
num = np.linspace(0, 2*np.pi, num = table_num)
table = np.sin(num)
table_big = (table*16384).astype(int)
# print(table_big)
# plt.plot(num, table_big,label='sin')
for i in range(int(table_num/10)):
for j in range(10):
print(table_big[i*10+j], ", ", end="")
print("")
#=========================
#------------------模拟计算
#边沿对齐方式
#-----已知量
Parse = 2
Tbase = 48 / 128 # 单位us 48mhz 128分频 霍尔计数值的时基单位 一个计数值的时间
Thall = 1000 #霍尔中断获取到的计数个数
Tpwm = 0.016 #mhz
Uc = 2400 #三角波最大幅值 最大占空比
Us = 2000 #sin波最大幅值 pid计算出来
eRPS = 1000000 * Tbase / Thall / 2 #电角度转速
w = 2 * np.pi * eRPS #角速度 根据霍尔得到 w = 2 * pi *rpm
# w = eRPS
num_pwm = int(Thall * 128 / 48 * Tpwm)#周期内可以产生多少个pwm 计算单位us
num_pwm = num_pwm * 2
print("hall:", Thall, "eRPS:", eRPS, "w:", w, "num_pwm", num_pwm)
#----需要求解
#获取时间递增数组
out_num = np.linspace(0, num_pwm, num = num_pwm, dtype=int)
# print(out_num)
#获取实际时间us
t_Int = (out_num * 1/Tpwm).astype(float)
# print(t_Int)
#跟进角速度与时间计算当前弧度
angle = w * t_Int / 1000000 #w * t
# print("get angle:")
# print(angle)
#弧度转换成数组下标
subscript = (512 * angle / 2 / np.pi).astype(int)#可以去掉2 pi 不用计算
# subscript = (512 * angle).astype(int)
# print(subscript)
#获取新的sin表格
newsin = table[subscript]
print("new sin:")
print(newsin)
#计算占空比
Ton = newsin * Us / Tpwm / Uc #us
# print(Ton)
Tduty = (Ton * Tpwm * Uc).astype(int)
print(Tduty)
plt.plot(out_num, Tduty, label='duty')
#=========================
#---图标显示
plt.xlabel('sin')
plt.ylabel('angel')
plt.title('sin table')
plt.legend()
plt.grid(True)
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rongxie/k-tx-foc.git
[email protected]:rongxie/k-tx-foc.git
rongxie
k-tx-foc
k-tx-foc
master

搜索帮助