📄 sigproc.c
字号:
#include "PSoCApi.h"
#include <m8c.h>
#include "globdefs.h"
#include "utils.h"
#define TH_DELTA 200
#define LPF_SHIFT 2
extern INT ADC_iResult;
#define HPF_BUFFER_LEN 7
static INT hpf_buffer[HPF_BUFFER_LEN];
static INT adc_max_prev = 0;
static PULSE_INTERVAL_TYPE peak_delta = 0;
#define RANGE_POINTS 200
#define TH_MIN 300
#define TH_MAX 1500
#define TH_FILTER_SHIFT 1
#define AGC_DOWN_THESHOLD 10000
#define AGC_UP_THESHOLD 4000
#define GAIN_LEVELS 8
#define AGC_GAIN_HIGH 6
#define AGC_GAIN_LOW 0
static const BYTE gain_table[GAIN_LEVELS] = {1, 2, 3, 4, 5, 8, 12, 16};
static BYTE gain_level = 0;
#if DEBUG
static INT debug = 0;
#endif
#pragma interrupt_handler adc_sig_proc;
void adc_sig_proc(void)
{
static INT lpf1 = 0, lpf2 = 0;
static BYTE loop = 0;
static INT hpf_data;
static INT temp;
static BYTE ran_cnt = 0;
static INT th = TH_MIN, adc_max = 0;
static INT peak_max = 0;
static PULSE_INTERVAL_TYPE int_cnt = 0, peak_ind = 0, peak_ind_old;
lpf1 -= (lpf1 >> LPF_SHIFT) - (ADC_iResult - ADC_SHIFT);
lpf2 += (lpf1 >> 1) - (lpf2 >> LPF_SHIFT);
M8C_EnableGInt;
if ((lpf2 > AGC_DOWN_THESHOLD) && (gain_level > AGC_GAIN_LOW))
In_BPF_FILT_C1_REG = (In_BPF_FILT_C1_REG & 0xE0) | gain_table[--gain_level];
if ((lpf2 < AGC_UP_THESHOLD) && (gain_level < AGC_GAIN_HIGH))
In_BPF_FILT_C1_REG = (In_BPF_FILT_C1_REG & 0xE0) | gain_table[++gain_level];
loop = HPF_BUFFER_LEN-1; while(loop) {hpf_buffer[loop] = hpf_buffer[loop-1]; loop--;}
hpf_buffer[0] = lpf2;
hpf_data = hpf_buffer[6] - hpf_buffer[0];
temp = hpf_buffer[1] - hpf_buffer[5];
hpf_data += temp;
temp <<= 3;
hpf_data += temp;
temp = hpf_buffer[4] - hpf_buffer[2];
hpf_data -= temp;
temp <<= 1;
hpf_data -= temp;
temp <<= 3;
hpf_data += temp;
temp <<= 1;
hpf_data += temp;
if (RANGE_POINTS == ran_cnt++)
{
temp = th + TH_DELTA;
th += (adc_max >> (TH_FILTER_SHIFT+1)) - (th >> TH_FILTER_SHIFT);
th = MIN(th, temp);
if (th < TH_MIN) th = TH_MIN;
if (th > TH_MAX) th = TH_MAX;
adc_max_prev = adc_max;
adc_max = ran_cnt = 0;
}
else
if (hpf_data > adc_max) adc_max = hpf_data;
int_cnt++;
if (hpf_data < th)
{
if (peak_max > 0)
{
if (peak_ind > peak_ind_old) peak_delta = peak_ind - peak_ind_old;
else
{
peak_delta = PULSE_INTERVAL_MAX - peak_ind_old;
peak_delta += peak_delta + 1;
}
peak_ind_old = peak_ind;
peak_max = 0;
}
}
else
if (hpf_data > peak_max)
{
peak_max = hpf_data;
peak_ind = int_cnt;
}
}
INT GetADCRange(void)
{
INT temp;
M8C_DisableGInt;
temp = adc_max_prev;
M8C_EnableGInt;
return temp;
}
PULSE_INTERVAL_TYPE GetPulseDelta(void)
{
PULSE_INTERVAL_TYPE temp;
M8C_DisableGInt;
temp = peak_delta;
peak_delta = 0;
M8C_EnableGInt;
return temp;
}
BYTE GetGainLevel(void)
{
return gain_level;
}
#if DEBUG
INT GetDebugVar(void)
{
INT temp;
M8C_DisableGInt;
temp = debug;
M8C_EnableGInt;
return temp;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -