关于 !define /date

本文详细介绍了NSIS日期插件中各种日期格式符号的含义及应用,包括日期、时间、星期、月份等元素的表示方法,为开发者提供了一站式的日期格式解析指南。

  Details of  !define /date
     %a    abbreviated weekday name (Sun)
     %A    full weekday name (Sunday)
     %b    abbreviated month name (Dec)
     %B    full month name (December)
     %c    date and time (Dec  2 06:55:15 1979)
     %d    day of the month (02)
     %H    hour of the 24-hour day (06)
     %I    hour of the 12-hour day (06)
     %j    day of the year, from 001 (335)
     %m    month of the year, from 01 (12)
     %M    minutes after the hour (55)
     %p    AM/PM indicator (AM)
     %S    seconds after the minute (15)
     %U    Sunday week of the year, from 00 (48)
     %w    day of the week, from 0 for Sunday (6)
     %W    Monday week of the year, from 00 (47)
     %x    date (Dec  2 1979)
     %X    time (06:55:15)
     %y    year of the century, from 00 (79)
     %Y    year (1979)
     %Z    time zone name, if any (EST)
     %%    percent character %

Ref:
http://nsis.sourceforge.net/NSIS-Date_plug-in

/************************************** Copyright 2009, Chint Power System Ltd. Co. File Name: Invcontroller.c Description: This file gives definition and implementation of Inverter control function Version : V1.0 Author: Zhou xu Date:2011-11-17 **************************************/ /**** head-files including****/ #include "Funheader.h" /**** macro definition****/ #define cFreq60Hz 15360 #define cFreq50Hz 12800 //macro constant for Clarke and Park converter #define cDivide3 5461 //Q14 #define cSqrt3 28378 //Q14 #define cDivideSqrt3 9459 //Q14 #define c3Divide2 24576 //Q14 //macro constant for svm use #define cSqrt3Divide2 14189 //Q14 sqrt(3)/2 *Q14 = 14189 #define cSqrt3Divide3 9459 //Q14 sqrt(3)/3 *Q14 = 9459 //macro constant for PLL use #define cSinTabNumb 720 #define cPLLMaxFreqAdjust 904 //Q4 [9Hz*2*pi*Q4 = 1005] #define cPLLFreqAngleGain 42723 //Q20 1/16/8000/pi*180*32768/360 Q20 #define cPLLAngleGainOpen 16777 //cPLLFreqAngleGain * 2 * pi * 16 / 256 8kHz #define cDCI40mA 320 //Q3 #define cDCI64mA 512 //Q3 #define cDCI150mA 1200 //Q3 #define cVSBusVoltFiltGainNum 158 #define cVSBusVoltFiltGainDen 3938 #define cBusSumDivideGridD 702 //8kHz #define cBusSumVoltFiltGainNum 410//208//105 #define cBusSumVoltFiltGainDen 3686//3888//3991 #define cBusSumVoltVKp 5147//5147//2574 #define cBusSumVoltVKi 12//24//6 #define cBusSumVoltKaw 10//19//10 #define cDCCurrFiltGainNum 410 #define cDCCurrFiltGainDen 3686 #define cDCCurrKp 1086//5147 #define cDCCurrKi 2//12 #define cDCCurrKaw 9//10 #define cBusDiffVoltFiltGainNum 0 //8kHz #define cBusDiffVoltFiltGainDen 0 #define cBusDiffVoltKp 774 #define cBusDiffVoltKi 1 #define cBusDiffVoltKaw 1 #define cInvOsCurrLimitHigh 16383 #define cInvOsCurrLimitLow -16383 #define cGridVoltFiltGainNum 26// 26 #define cGridVoltFiltGainDen 998// 998 #define cGridVoltKp 1112//1112//2224//1112 #define cGridVoltKi 5//5//3 #define cGridVoltKaw 10//10//10 //================================== //inverter control #define cInvCurrFiltGainNum 4090//3826// 3498 //3826//3498//3526//3498 //8kHz #define cInvCurrFiltGainDen 6//270// 598 //270//598//570//598 #define cInvCurrKp 9780*2// 4427 // 9780//4427//4632//4427 #define cInvCurrKi 355*2// 57// 355//57//130//57 #define cInvCurrKaw 149// 53// 149//53//115//53 #define cVSCurrFiltGainNum 3045//3826// 3045 #define cVSCurrFiltGainDen 1051//270//1051 #define cVSCurrKp 4890//9780// 4890 #define cVSCurrKi 89//355// 89 #define cVSCurrKaw 74//149// 74 #define cInertiaInvJ 2712;//3255//6510//15523//3255//31047//1/J/8000 Q20 J = D * T 0.02s #define cVSVoltIngQKi 279//556//279//K = T * w * Kv; 0.01s #define cInvPwmK 1135 #define cInvPwmKRec 7390 #define cInvModuLimitHigh 8191 #define cInvModuLimitLow -8191 #define cInvChkUdComp 16321//16182 //16224//16135////15897 #define cInvChkUqComp 1427//2595 //2302//2889////4085 //macro constant for svm use #define cMaxPwm 8160//8191 // #define cMinPwm 32//15 // update on 20100225 for DPWMMIN //50 //==========================================
最新发布
12-02
这段代码是一个用于**逆变器控制(Inverter Control)系统**的 C 语言头文件片段,常见于嵌入式电力电子控制系统中(如光伏逆变器、UPS、电机驱动等)。它定义了大量的宏常量,主要用于数字信号处理(DSP)、控制算法实现(如 PI 控制器、Clarke/Park 变换、SVM 调制、PLL 锁相环等),并使用了定点数运算(Q 格式)来提高计算效率。 --- ### 🔍 **详细解释与分析** #### ✅ 1. 宏定义用途分类 ##### 📌 (1) 基础频率相关 ```c #define cFreq60Hz 15360 #define cFreq50Hz 12800 ``` - 表示在某个 Q 格式下表示的角频率或周期计数值。 - 常用于定时器比较值或基准频率设定。例如,在一个固定主频(如 8kHz PWM 频率)下生成同步参考。 > 示例:若系统采样频率为 8kHz,则每周期需采样点数 = 8000 / 50 = 160 点 → 这些值可能用于角度累加器步进。 --- ##### 📌 (2) Clarke 和 Park 变换系数(三相到两相变换) 这些是用于三相交流系统坐标变换的缩放因子,采用 **Q14 定点格式**(即小数乘以 $2^{14} = 16384$)。 ```c #define cDivide3 5461 //Q14 ≈ 1/3 * 16384 = 5461.3 #define cSqrt3 28378 //Q14 ≈ √3 ≈ 1.732 * 16384 ≈ 28378 #define cDivideSqrt3 9459 //Q14 ≈ 1/√3 ≈ 0.577 * 16384 ≈ 9459 #define c3Divide2 24576 //Q14 ≈ 3/2 * 16384 = 24576 ``` 👉 这些常量用于实现 **Clarke 变换** 和 **Park 变换** 中的比例调整: - Clarke 变换中需要乘以 $\frac{2}{3}$ 或 $\frac{1}{\sqrt{3}}$ - 使用整数避免浮点运算,提升性能 📌 典型 Clarke 变换公式(幅值不变): $$ I_\alpha = I_a \\ I_\beta = \frac{1}{\sqrt{3}}(I_b - I_c) $$ 但在实际实现中会结合比例合并优化。 --- ##### 📌 (3) SVM(空间矢量调制)相关参数 ```c #define cSqrt3Divide2 14189 //Q14: sqrt(3)/2 ≈ 0.866 * 16384 ≈ 14189 #define cSqrt3Divide3 9459 //Q14: sqrt(3)/3 ≈ 0.577 * 16384 ≈ 9459 ``` - 用于将电压矢量从 αβ 坐标系映射到 SVPWM 扇区计算中。 - 在扇区判断和作用时间计算时使用。 --- ##### 📌 (4) PLL(锁相环)相关参数 ```c #define cSinTabNumb 720 #define cPLLMaxFreqAdjust 904 //Q4 #define cPLLFreqAngleGain 42723 //Q20 #define cPLLAngleGainOpen 16777 //Q? ``` - `cSinTabNumb`: 正弦表有 720 个点 → 每度一个点,高精度角度查找。 - `cPLLMaxFreqAdjust`: 最大频率调节量(对应 ±9Hz),用 Q4 表示(×16)→ 实际值 ≈ 904 / 16 ≈ 56.5 rad/s²? - `cPLLFreqAngleGain`: 将频率误差转换为角度增量的增益,单位 Q20,用于积分环节。 典型 PLL 结构: ```text Phase_error → PI控制器 → 角频率ω → 积分得θ → 查sin/cos表 → 与输入电压比对 ``` 这些增益经过精心设计以保证动态响应和平稳跟踪电网相位。 --- ##### 📌 (5) ADC/DAC 和电流检测校准 ```c #define cDCI40mA 320 //Q3 → 320 / 8 = 40mA #define cDCI64mA 512 //Q3 → 512 / 8 = 64mA #define cDCI150mA 1200 //Q3 → 1200 / 8 = 150mA ``` - Q3 表示定点小数乘以 8。 - 用于将 ADC 读取的数字量转换为实际物理电流值(mA级偏移或阈值)。 --- ##### 📌 (6) 滤波器增益(一阶低通滤波器 IIR) 这类结构广泛用于电压/电流信号滤波: ```c // 形如:y(n) = y(n-1) + K * [x(n) - y(n-1)] // 即:y = y + num/den * (x - y) #define cVSBusVoltFiltGainNum 158 #define cVSBusVoltFiltGainDen 3938 ``` 等效时间常数由 `K = num/den` 决定,约为 0.04,适合抑制高频噪声。 类似地还有: - `cDCCurrFiltGainNum/Den` - `cGridVoltFiltGainNum/Den` - `cInvCurrFiltGainNum/Den` --- ##### 📌 (7) PI 控制器参数(大量出现) 这是核心控制逻辑部分,用于各种闭环控制: | 参数 | 含义 | |------|------| | `Kp` | 比例增益 | | `Ki` | 积分增益(通常很小,因离散化后需除以采样频率) | | `Kaw` | 抗积分饱和(anti-windup)反馈系数 | ###### 示例:直流母线电压外环控制 ```c #define cBusSumVoltVKp 5147 #define cBusSumVoltVKi 12 #define cBusSumVoltKaw 10 ``` 典型离散 PI 控制器实现(伪代码): ```c error = ref - fb; integral += Ki * error; // Anti-windup if (!(output > limit_high && error > 0) && !(output < limit_low && error < 0)) integral += Kaw * (output - saturated_output); // 或 Kaw * error output = Kp * error + integral; ``` --- ##### 📌 (8) 逆变器 PWM 相关参数 ```c #define cInvPwmK 1135 #define cInvPwmKRec 7390 #define cInvModuLimitHigh 8191 #define cInvModuLimitLow -8191 ``` - `cInvPwmK` 和 `cInvPwmKRec` 可能是调制比到占空比的缩放系数或其倒数。 - `cInvModuLimit*` 是调制波输出限幅值,防止过调制(通常 ±8191 对应 ±1.0 in Q13/Q14) --- ##### 📌 (9) SVM 调制边界限制 ```c #define cMaxPwm 8160 #define cMinPwm 32 ``` - 设置 PWM 计数器的最大最小值,防止上下桥臂直通(shoot-through)。 - `MinPwm=32` 提供死区时间保护。 --- ##### 📌 (10) 故障检测补偿阈值 ```c #define cInvChkUdComp 16321 #define cInvChkUqComp 1427 ``` - 用于检测 d/q 轴电压是否异常,判断是否发生过压、短路等情况。 - 可能在软件保护逻辑中使用。 --- ### ✅ 总结:整体架构理解 该文件属于一个典型的基于 DSP 的**数字电源控制器固件**,包含以下子系统: | 子系统 | 功能 | |--------|------| | **ADC采集与滤波** | 对电网电压、直流母线电压、输出电流进行采样和滤波 | | **Clarke & Park 变换** | 将三相量转为旋转坐标系下的直流量便于控制 | | **PLL 锁相环** | 实时跟踪电网相位和频率 | | **PI 控制器组** | 包括电流内环、电压外环、功率控制等 | | **SVPWM 发生器** | 生成六步驱动波形 | | **保护机制** | 过流、过压、调制饱和检测 | 所有算法均使用 **定点运算(Fixed-point Arithmetic)** 实现,以适应无 FPU 的 MCU/DSP(如 TI C2000 系列)。 --- ### 💡 示例:如何使用这些宏实现一个 PI 控制器? ```c // 定义 PI 控制器状态结构体 typedef struct { int32_t Ref; // Reference int32_t Fb; // Feedback int32_t Err; // Error int32_t Integral; // Integral term int32_t Output; // Output int32_t Kp; int32_t Ki; int32_t Kaw; int32_t Lim_High; int32_t Lim_Low; } PI_Controller; // 初始化函数 void PI_Init(PI_Controller *pi) { pi->Integral = 0; pi->Output = 0; } // 执行一次 PI 控制(假设运行在中断中) void PI_Update(PI_Controller *pi) { pi->Err = pi->Ref - pi->Fb; // 比例项 int32_t Pout = (pi->Kp * pi->Err) >> 14; // 假设 Kp 是 Q14 // 积分项 + 抗饱和 int32_t last_output = pi->Output; pi->Integral += (pi->Ki * pi->Err) >> 14; // Anti-windup: 如果输出饱和且误差同向,则停止积分 if ((pi->Output >= pi->Lim_High && pi->Err > 0) || (pi->Output <= pi->Lim_Low && pi->Err < 0)) { // 不更新积分 } else { pi->Integral += (pi->Kaw * (pi->Output - last_output)) >> 14; } pi->Output = Pout + pi->Integral; // 输出限幅 if (pi->Output > pi->Lim_High) pi->Output = pi->Lim_High; if (pi->Output < pi->Lim_Low) pi->Output = pi->Lim_Low; } ``` 📌 使用示例(电流环): ```c PI_Controller IqCtrl = { .Ref = 0, .Fb = 0, .Kp = cInvCurrKp, // 来自宏定义 .Ki = cInvCurrKi, .Kaw = cInvCurrKaw, .Lim_High = cInvModuLimitHigh, .Lim_Low = cInvModuLimitLow }; ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值