This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS3in1/1.Cabin/1.Software/STM32_AD7606/VM_App/VM_Sampling_Control.c

107 lines
2.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "VM_Sampling_Control.h"
#include "VM_AD7606.h"
#include "usbd_cdc_if.h"
uint8_t Control_Buf[8] = {3}; //指令存储buf
uint8_t Control_Ins_Flag = 0; //指令接收标志 0未接收 1已接收
uint8_t instruct_flag = 0; //指令判断标志符
//各指令控制器
uint8_t frequency_control = 3; //频率控制器 2 : 10k ; 1 : 20k ; 0 : 40k
uint8_t sampling_control = 2; //采样控制器 0 : 停止采样 ; 1 : 开始采样
uint8_t reset_control = 0; //软件复位控制器 1 : 执行复位
uint8_t hall_control = 2; //霍尔传感器频率检测控制器 0 : 停止检测 ; 1 : 开始检测
//采集指令控制
void Sampling_Control(void){
//采样频率设置
switch (frequency_control){
case 0:
AD7606_SFC = 1; //40k
break;
case 1:
AD7606_SFC = 2; //20k
break;
case 2:
AD7606_SFC = 4; //10k
break;
default :
break;
}
if(sampling_control == 1){ //开始采样
AD7606_Sampling_Flag = 1;
}
else if(sampling_control == 0){ //停止采样
AD7606_Sampling_Flag = 0;
}
//软件复位
if(reset_control == 1){
__set_FAULTMASK(1); //关闭中断
NVIC_SystemReset(); //复位
}
//霍尔频率检测 暂定
if(hall_control == 1){
}
//AD电流检测 暂定
}
//采样数据发送
void CDC_Data_Send(void){
if(AD_Arr_Num == 1028){
CDC_Transmit_HS(AD_Data_Arr,8224);
AD_Arr_Num = 8228;
}
if(AD_Arr_Num == 9252){
CDC_Transmit_HS(&AD_Data_Arr[8224],8224);
AD_Arr_Num = 4;
}
}
//指令判断
void Instruct_Judgment(void){
// if(Control_Ins_Flag == 1)
// {
//心跳判断
if(Control_Buf[0] == 0x00 && Control_Buf[1] == 0x00 && Control_Buf[2] == 0x00 && Control_Buf[3] == 0x00)
{
}
//指令判断
else if(Control_Buf[0] == 0x01 && Control_Buf[1] == 0x01 && Control_Buf[2] == 0x01 && Control_Buf[3] == 0x01)
{
//开始/停止 采样
if(Control_Buf[4] == 0 && Control_Buf[5] == 0)
{
sampling_control = 0;
}
else if(Control_Buf[4] == 1 && Control_Buf[5] == 1)
{
sampling_control = 1;
}
//设置采样频率
if(Control_Buf[6] == 0 && Control_Buf[7] == 0)
{
frequency_control = 0;
}
else if(Control_Buf[6] == 1 && Control_Buf[7] == 1)
{
frequency_control = 1;
}
else if(Control_Buf[6] == 2 && Control_Buf[7] == 2)
{
frequency_control = 2;
}
}
// Control_Ins_Flag = 0;
// }
}