9.11commit

完成准确定时波形输出
This commit is contained in:
Shocky 2025-09-11 10:41:05 +08:00
parent 83d56969fb
commit b84ae4b6c7
25 changed files with 3400 additions and 5015 deletions

File diff suppressed because one or more lines are too long

View File

@ -200,7 +200,7 @@
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>410</LineNumber>
<LineNumber>430</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
@ -216,7 +216,7 @@
<Bp>
<Number>4</Number>
<Type>0</Type>
<LineNumber>430</LineNumber>
<LineNumber>431</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
@ -232,7 +232,7 @@
<Bp>
<Number>5</Number>
<Type>0</Type>
<LineNumber>431</LineNumber>
<LineNumber>410</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>

View File

@ -385,7 +385,7 @@ void Fuse_result(void)
// 注意这里不再直接调用EMS_Process(),而是通过状态控制
if (time_flags->T_1ms) {
// 1ms周期任务 - 高频控制任务
time_count++;
EMS_Process();
time_flags->T_1ms = 0; // 清除标志位
}
@ -417,6 +417,7 @@ void Fuse_result(void)
// 前10秒开启电刺激
if (ems_state == 0) {
ems_state = 1;
time_count = 0; // 重置时间计数器
EMS_Start(); // 启动电刺激
}
// 处理电刺激
@ -425,6 +426,7 @@ void Fuse_result(void)
// 后10秒关闭电刺激
if (ems_state == 1) {
ems_state = 0;
time_count = 0; // 重置时间计数器
EMS_Stop(); // 停止电刺激
}
} else {

View File

@ -53,7 +53,7 @@ int wavegen_driverA_sine_test(CMSDK_WAVE_GEN_TypeDef *CMSDK_WAVEGEN_DRVA, uint16
int return_val = 0;
int err_code = 0;
printf("\n驱动器A正弦波测试\n");
// printf("\n驱动器A正弦波测试\n");
CMSDK_WAVEGEN_DRVA->WAVE_GEN_DRV_REST_T_REG = 100; // 死区时间10ms //交替模式下死区时间失效即使CONFIG_REG使能了死区时间也无效
// CMSDK_WAVEGEN_DRVA->WAVE_GEN_DRV_SILENT_T_REG = 200; //静默时间20ms
@ -113,12 +113,12 @@ int wavegen_driverA_sine_test(CMSDK_WAVE_GEN_TypeDef *CMSDK_WAVEGEN_DRVA, uint16
CMSDK_WAVEGEN_DRVA->WAVE_GEN_DRV_CTRL_REG = 0x00000001; // 使能驱动器
/* 生成返回值 */
if (err_code != 0)
/*if (err_code != 0)
{
printf("\n错误 : 驱动器A测试失败\n");
return_val = 1;
err_code = 0;
}
}*/
return (return_val);
}
@ -172,6 +172,9 @@ void wavegen_Start(void)
{
g_current_intensity = g_ems_config.intensity; // 直接使用设定强度
}
// 初始化硬件配置(只执行一次)
wavegen_driverA_sine_test(WAVE_GEN_DRVA_BLK0, g_current_intensity);
}
// 电刺激参数配置
@ -209,69 +212,94 @@ void EMS_UpdateIntensity(uint16_t intensity)
// 缓进缓出处理函数(在电刺激处理中调用)
void EMS_Process_Ramp(void)
{
if(ems_state)
{
float up_period = ems_config.ramp_up_time;
float down_period = ems_config.ramp_down_time;
if (!g_ems_config.enable_ramp || !g_ems_running)
time_count++;
if (!g_ems_config.enable_ramp || !g_ems_running)
{
return; // 如果未启用缓进缓出或未运行,直接返回
}
// 计算每个强度步进需要的毫秒数
uint32_t ramp_up_ms = ems_config.ramp_up_time * 1000;
uint32_t hold_ms = ems_config.hold_time * 1000;
uint32_t ramp_down_ms = ems_config.ramp_down_time * 1000;
switch (g_ramp_phase)
{
case 0: // 缓进阶段
{
if ( time_count <= ems_config.ramp_up_time*1000 )
{
if (g_current_intensity < g_ems_config.intensity)
{
g_current_intensity += waves_per_step;
// 计算当前应该达到的强度
uint16_t target_intensity = (time_count * ems_config.intensity) / ramp_up_ms;
if (target_intensity > ems_config.intensity) {
target_intensity = ems_config.intensity;
}
g_current_intensity = target_intensity;
}
else
{
// 缓进完成,进入保持阶段
g_ramp_phase = 1;
g_current_intensity = g_ems_config.intensity; // 确保达到最大强度
g_current_intensity = ems_config.intensity; // 确保达到最大强度
}
break;
}
case 1:
break;
}
case 1: // 保持阶段
{
if(time_count <= (ems_config.ramp_up_time+ems_config.hold_time)*1000)
if(time_count <= (ramp_up_ms + hold_ms))
{
g_current_intensity = g_ems_config.intensity;
g_current_intensity = ems_config.intensity;
}
else
{
g_ramp_phase = 2;
}
else g_ramp_phase = 2;
break;
}
case 2:
case 2: // 缓出阶段
{
if(time_count <= (ems_config.ramp_up_time+ems_config.hold_time+ems_config.ramp_down_time)*1000)
if(time_count <= (ramp_up_ms + hold_ms + ramp_down_ms))
{
if (g_current_intensity > 0)
{
g_current_intensity -= waves_per_step;
}
// 计算缓出阶段的时间偏移
uint32_t ramp_down_start = ramp_up_ms + hold_ms;
uint32_t ramp_down_elapsed = time_count - ramp_down_start;
// 计算当前应该达到的强度从最大值递减到0
uint16_t target_intensity = ems_config.intensity -
(ramp_down_elapsed * ems_config.intensity) / ramp_down_ms;
if (target_intensity > ems_config.intensity) {
target_intensity = 0;
}
g_current_intensity = target_intensity;
}
else
{
g_ramp_phase = 0;
// 缓出完成,停止电刺激
g_current_intensity = 0;
g_ramp_phase = 0; // 重置为缓进阶段,准备下一轮
}
break;
break;
}
}
}
else time_count = 0;
// 注意不要在这里重置time_count让它继续计数
}
// 更新波形强度(不重新配置硬件)
void wavegen_UpdateIntensity(CMSDK_WAVE_GEN_TypeDef *CMSDK_WAVEGEN_DRVA, uint16_t intensity)
{
// 只更新波形数据,不重新配置硬件
for (int i = 0; i < 64; i++)
{
CMSDK_WAVEGEN_DRVA->WAVE_GEN_DRV_IN_WAVE_ADDR_REG = i;
CMSDK_WAVEGEN_DRVA->WAVE_GEN_DRV_IN_WAVE_REG = intensity;
}
}
// 电刺激主循环处理函数(在主循环中调用)
@ -279,9 +307,9 @@ void EMS_Process(void)
{
if (g_ems_running)
{
EMS_Process_Ramp();
EMS_Process_Ramp();
// 使用当前缓进缓出的强度
uint16_t current_intensity = g_current_intensity;
wavegen_driverA_sine_test(WAVE_GEN_DRVA_BLK0, current_intensity);
wavegen_UpdateIntensity(WAVE_GEN_DRVA_BLK0, current_intensity);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -21,17 +21,31 @@ Target DLL: Segger\JL2CM3.dll V2.99.42.0
Dialog DLL: TARMCM1.DLL V1.14.6.0
<h2>Project:</h2>
E:\Workspace\TIMER_DEMO\ENS001_BASIC_PRJ.uvprojx
E:\WeChat Files\wxid_2yspimlbsy4d22\xwechat_files\wxid_2yspimlbsy4d22_74fb\msg\file\2025-09\TIMER_DEMO\TIMER_DEMO\ENS001_BASIC_PRJ.uvprojx
Project File Date: 08/15/2025
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\Keil_v5\ARM\ARM_Compiler_5.06u7\Bin'
Build target 'ENS001_BASIC_PRJ'
compiling mian.c...
compiling ENS1_WAVEGEN.c...
FWLIB\source\ENS1_WAVEGEN.c(54): warning: #177-D: variable "err_code" was declared but never referenced
int err_code = 0;
FWLIB\source\ENS1_WAVEGEN.c: 1 warning, 0 errors
compiling ENS1_TIMER.c...
FWLIB\source\ENS1_TIMER.c(389): warning: #223-D: function "EMS_Process" declared implicitly
EMS_Process();
FWLIB\source\ENS1_TIMER.c(410): warning: #223-D: function "GPIO_Overturn" declared implicitly
GPIO_Overturn(GPIO_19);
FWLIB\source\ENS1_TIMER.c(421): warning: #223-D: function "EMS_Start" declared implicitly
EMS_Start(); // 启动电刺激
FWLIB\source\ENS1_TIMER.c(430): warning: #223-D: function "EMS_Stop" declared implicitly
EMS_Stop(); // 停止电刺激
FWLIB\source\ENS1_TIMER.c: 4 warnings, 0 errors
linking...
Program Size: Code=8328 RO-data=368 RW-data=140 ZI-data=532
Program Size: Code=8000 RO-data=368 RW-data=132 ZI-data=532
FromELF: creating hex file...
".\Objects\ENS001_BASIC_PRJ.axf" - 0 Error(s), 0 Warning(s).
".\Objects\ENS001_BASIC_PRJ.axf" - 0 Error(s), 5 Warning(s).
<h2>Software Packages used:</h2>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
Dependencies for Project 'ENS001_BASIC_PRJ', Target 'ENS001_BASIC_PRJ': (DO NOT MODIFY !)
CompilerVersion: 5060750::V5.06 update 6 (build 750)::.\ARM_Compiler_5.06u7
F (.\USER\mian.c)(0x68C14CF9)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\mian.o --omf_browse .\objects\mian.crf --depend .\objects\mian.d)
F (.\USER\mian.c)(0x68C23502)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\mian.o --omf_browse .\objects\mian.crf --depend .\objects\mian.d)
I (USER\my_header.h)(0x68C138EC)
I (D:\Keil_v5\ARM\ARM_Compiler_5.06u7\include\stdio.h)(0x599ECD2C)
I (D:\Keil_v5\ARM\ARM_Compiler_5.06u7\include\string.h)(0x599ECD2C)
@ -85,7 +85,7 @@ I (.\CORE\INCLUDE\core_cm0.h)(0x63648DE6)
I (.\CORE\INCLUDE\core_cmInstr.h)(0x63648DE6)
I (.\CORE\INCLUDE\core_cmFunc.h)(0x63648DE6)
I (.\CORE\INCLUDE\system_CMSDK_CM0.h)(0x63648DE6)
F (.\FWLIB\source\ENS1_TIMER.c)(0x68C14C52)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\ens1_timer.o --omf_browse .\objects\ens1_timer.crf --depend .\objects\ens1_timer.d)
F (.\FWLIB\source\ENS1_TIMER.c)(0x68C23503)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\ens1_timer.o --omf_browse .\objects\ens1_timer.crf --depend .\objects\ens1_timer.d)
I (.\FWLIB\include\ENS1_TIMER.h)(0x68C13790)
I (.\CORE\INCLUDE\CMSDK_CM0.h)(0x64D5ADE8)
I (.\CORE\INCLUDE\core_cm0.h)(0x63648DE6)
@ -108,7 +108,7 @@ I (D:\Keil_v5\ARM\ARM_Compiler_5.06u7\include\stdint.h)(0x599ECD2E)
I (.\CORE\INCLUDE\core_cmInstr.h)(0x63648DE6)
I (.\CORE\INCLUDE\core_cmFunc.h)(0x63648DE6)
I (.\CORE\INCLUDE\system_CMSDK_CM0.h)(0x63648DE6)
F (.\FWLIB\source\ENS1_WAVEGEN.c)(0x68C14BB4)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\ens1_wavegen.o --omf_browse .\objects\ens1_wavegen.crf --depend .\objects\ens1_wavegen.d)
F (.\FWLIB\source\ENS1_WAVEGEN.c)(0x68C23500)(--c99 -c --cpu Cortex-M0 -D__MICROLIB --li -g -O0 --apcs=interwork --split_sections -I .\CORE\INCLUDE -I .\USER -I .\FWLIB\include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARMCM0\Include -ID:\Keil_v5\ARM\Packs\ARM\Cortex_DFP\1.1.0\Device\ARM\ARMCM0\Include -D__UVISION_VERSION="538" -DARMCM0 -o .\objects\ens1_wavegen.o --omf_browse .\objects\ens1_wavegen.crf --depend .\objects\ens1_wavegen.d)
I (D:\Keil_v5\ARM\ARM_Compiler_5.06u7\include\stdio.h)(0x599ECD2C)
I (.\FWLIB\include\ENS1_WAVEGEN.h)(0x68C14AAF)
I (.\CORE\INCLUDE\CMSDK_CM0.h)(0x64D5ADE8)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -35,25 +35,26 @@ int main(){
// 初始化UART
UART_Init(CMSDK_UART1, &UART1_Init);
UART_ITConfig(CMSDK_UART1, &UART1_ITSet);
// 配置电刺激参数
EMS_Configure(&ems_config);
// 初始化时间管理器
Time_Manager_Init();
// 初始化定时器在wavegen_Init之前
TIMER0_Init(1);
// 初始化波形生成器(电刺激)
// 初始化波形生成器(电刺激)- 必须先初始化
wavegen_Init();
// 配置电刺激参数
EMS_Configure(&ems_config);
// 启动电刺激
EMS_Start();
while(1)
{
//if ( time_count <= ems_config.ramp_up_time*1000 ) waves_per_step = (g_ems_config.intensity ) / (ems_config.ramp_up_time*1000);
//else if(time_count <= (ems_config.ramp_up_time+ems_config.hold_time+ems_config.ramp_down_time)*1000) waves_per_step = (g_ems_config.intensity - 0) / (ems_config.ramp_down_time*1000);
}
}