用定时器获取数据效率很高

This commit is contained in:
2021-08-24 21:47:31 +08:00
parent 4c7ca7215e
commit 78f7d1c23a
43 changed files with 18086 additions and 15792 deletions
+43 -7
View File
@@ -8,12 +8,12 @@
#include "APP_blood.h"
#include "iic.h"
#include "FFT.h"
extern TIM_HandleTypeDef htim6;
window *blood_win;
uint16_t fifo_red;
uint16_t fifo_ir;
char blood_str[64];
uint16_t g_fft_index = 0; //fft输入输出下标
uint8_t Max30102_reset(void)
{
@@ -95,7 +95,7 @@ void APP_blood_init(window *a_window)
blood_win=a_window;
HAL_GPIO_WritePin(MAX_RD_GPIO_Port, MAX_RD_Pin, 0);
HAL_GPIO_WritePin(MAX_IRD_GPIO_Port, MAX_IRD_Pin, 0);
//HAL_TIM_Base_Start_IT(&htim6);
Max30102_reset();
MAX30102_Config();
@@ -397,7 +397,7 @@ void blood_data_translate(void)
s2[i].real= n_denom/8.00;
}
//开始变换显示
g_fft_index = 0;
//快速傅里叶变换
FFT(s1);
FFT(s2);
@@ -429,12 +429,28 @@ void blood_data_translate(void)
}
char get_data_lock=0;;
char get_data_flag=0;
uint16_t g_fft_index = 0; //fft输入输出下标
void APP_blood_loop()
{
if(get_data_lock==0)
{
get_data_lock=1;
get_data_flag=0;
g_fft_index = 0;
HAL_TIM_Base_Start_IT(&htim6);
}
if(get_data_flag==1)
{
blood_data_translate();
get_data_lock=0;
}
//标志位被使能时 读取FIFO
g_fft_index=0;
/*
while(g_fft_index < FFT_N)
{
while(MAX30102_INTPin_Read()==0)
@@ -453,7 +469,7 @@ void APP_blood_loop()
}
}
}
*/
/* for(int a=0;a<FFT_N;a++)
{
while(MAX30102_INTPin_Read());
@@ -465,7 +481,7 @@ void APP_blood_loop()
}
*/
//max30102_read_fifo();
blood_data_translate();
//blood_data_translate();
sprintf(blood_str,"fifo_red:%d",fifo_red);
LCD_ShowString(blood_win->x, blood_win->y+16, &blood_str, 16, WHITE, RED);
@@ -481,3 +497,23 @@ void APP_blood_loop()
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)//10us
{
if (htim == (&htim6))
{
max30102_read_fifo(); //read from MAX30102 FIFO2
//将数据写入fft输入并清除输出
s1[g_fft_index].real = fifo_red;
s1[g_fft_index].imag= 0;
s2[g_fft_index].real = fifo_ir;
s2[g_fft_index].imag= 0;
g_fft_index++;
if(g_fft_index>FFT_N)
{
get_data_flag=1;
HAL_TIM_Base_Stop_IT(&htim6);
}
}
}