您好StackExchange社区,

我的ECG / EKG设计中遇到问题。我正在尝试使用Arduino作为微控制器创建ECG,以通过蓝牙(JY-MCU)发送/获取心率测量值。我知道我的电路正在工作,因为当我在运放输出及其地上放置一个LED时,如果我将手轻轻地放在引线上,就会稍微变暗。我知道问题出在我的代码上。我已经在这个项目上工作了一段时间,但仍然找不到解决方案。这是我的示意图。

c - Arduino ECG溅射出完全随机的值-LMLPHP


抱歉,您可能需要翻转屏幕才能看到图片!这是我认为不正确的代码。该代码是最低限度的。

// External variables
const int  signal = 8;    // Pin connected to the filtered signal from the circuit
unsigned long time;
unsigned long frequency;
char freq[3];

// Internal variables
double period = 2000;
double starttime = 2000;
double input = 0;
double lastinput = 0;
unsigned long death = 0;

// initialize the library with the numbers of the interface pins

void setup() {
pinMode(signal, INPUT);
Serial.begin(9600);
}

void loop() {
delay(500);

time = millis();
input = digitalRead(signal);

 period = time - starttime; // Compute the time between the previous beat and the one that has just been detected
 starttime = time; // Define the new time reference for the next period computing
 death = time;
 frequency = 60000/period;
 freq[0] = frequency/100+48; // Sort the hundreds character and convert it in ASCII
 freq[1] = (frequency/10)%10+48; // Sort the thents character and convert it in ASCII
 freq[2] = frequency%10+48; // Sort the units character and convert it in ASCII
 Serial.println(freq);
}


我得到的只是120或119作为我的价值。它在这两个之间波动。我尝试更换电阻器,但无济于事。我也完全拔出了引脚8和面包板之间的导线,但它仍然在119到120之间波动。我不知道这里发生了什么!如果有人可以在这里帮助我,我将不胜感激。谢谢!

最佳答案

您的代码没有做任何远程有用的事情。它当然不是在测量输入频率-实际上,它甚至不在乎输入信号的值,并且无论外部发生什么,其行为都相同。它所做的只是测量两次调用loop()之间的时间,然后将此时间转换为以每分钟循环数为单位的频率。由于在loop()中有500 ms的延迟,因此得到的频率为2 Hz = 120周期/分钟,这与您看到的数字一致。

老实说,我怀疑即使您的代码正确,您的电路也将能够测量ECG信号-这太粗糙了-但是您至少可以测量与频率相关的某些信号,您可能想尝试并实现loop()中的以下代码:

input = digitalRead(signal);
while (input == digitalRead(signal))
    ; // wait for input signal to change state (sync)
start = millis();
while (input != digitalRead(signal))
    ; // wait for input signal to change state (first part of period)
while (input == digitalRead(signal))
    ; // wait for input signal to change state (one complete period)
end = millis();
period = end - start;
freq = 60000 / period;


请注意,如果您的输入信号没有定期更改状态,则此操作将挂起。

还要注意,只有在输入信号完全干净的情况下,这才可以进行有用的频率测量,即,仅以感兴趣的频率改变状态而没有噪声转换的信号。实际上,您可能只需要测量电源嗡嗡声或其他背景噪声的频率即可。

关于c - Arduino ECG溅射出完全随机的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28058806/

10-13 05:06