Home > other >  Used on STC12C5A pulsesensor, the program is available but still have error rate
Used on STC12C5A pulsesensor, the program is available but still have error rate

Time:09-25

Program can be run on a single chip, but there is a lot of heart rate error, just put finger module data is normal, but moments later reached 200 (maximum), don't know how to solve the
Please teach a great god,
The code below

://MCU STC12C5A60S2
//ADC PIN: P1.0
//the SYSTEM CLOCK: 11.0592 MHz
//Baudrate: 115200
//UART: P3.0 P3.1
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
#include
# include "stdio.h"
#include

# define false 0
# define true 1
11059200 l//# define FOSC system clock
115200//# define BAUD BAUD rate
# define T0MS (65536 - FOSC/12/500)//500 hz in 12 t MODE

# define ADC_POWER 0 x80//ADC POWER CONTROL BIT
# define ADC_FLAG 0 x10//ADC COMPLETE FLAG
# define ADC_START 0 x08;//ADC START CONTROL BIT
# define ADC_SPEEDLL 0 x00//540 CLOCKS
# define ADC_SPEEDL 0 x20//360 CLOCKS
# define ADC_SPEEDH 0 x40//180 CLOCKS
# define ADC_SPEEDHH 0 x60//90 CLOCKS
# define ADC_MASK 0 x01


Void UART_init (void);
Void ADC_init (unsigned char channel);
Void T0_init (void); Dat);
Void UART_send (char dat);

Unsigned char PulsePin=0;//Pulse Sensor purple wire connected to analog pin 0 (P1.0 to AD)
Sbit blinkPin=P2 ^ 0;//pin to blink the led at each beat
Sbit fadePin=P2 ^ 3;//pin to do fancy classy fading blink at each beat
Sbit led1=P2 ^ 1;
Sbit led2=P2 ^ 2;
Int fadeRate=0;//2 to fade the LED on with PWM on fadePin


//these variables are volatile because they are 2 during the interrupt service routine. These variables is variable, because they are used in the interrupt service routine!
Volatile unsigned int BPM;//2 to hold the pulse rate to keep the pulse frequency
Volatile unsigned int Signal;//doesn the incoming raw data, save the incoming raw data
Volatile unsigned int IBI=600;//doesn the time between beats, must be seeded. Keep the rhythm, the time between the seeds must be!
Volatile bit Pulse=false;//true when pulse wave is high, false when it 's low pulse wave is true, when high pulse wave low false
Volatile bit QS=false;//becomes true when Arduoino finds a beat. When Arduoino find a rhythm, becomes a true
Volatile int rate [10].//an array to hold the last ten IBI values array to hold the last 10 IBI value
Volatile unsigned long sampleCounter=0;//2 to determine pulse timing used to determine the pulse timing
Volatile unsigned long lastBeatTime=0;//2 to find IBI looking for IBI
Volatile int Peak=512;//2 to find peak in pulse wave, seeded used to find the peak value of pulse wave, seed
Volatile int Trough=512;//2 to find trough in pulse wave, seeded for finding pulse wave in the troughs, seed
Volatile int thresh=512;//2 to find instant moment of heart beat, seeded to look for the seeds of instantaneous heart
Volatile int amp=100;//2 to hold amplitude of pulse waveform, seeded to help maintain the amplitude of the pulse shape, seed
Volatile bit firstBeat=true;//2 to seed rate array so we startup with reasonable BPM array used to seed rate, so we start the reasonable BPM
Volatile bit secondBeat=false;//2 to seed rate array so we startup with reasonable BPM array used to seed rate, so we start the reasonable BPM
The static unsigned char order=0;

Unsigned char code ucForum0 []="Pulsesensor test".
Unsigned char code ucForum1 []="BPM:";
Unsigned char DisBuff [4]={0};

Void sys_init ()
{
UART_init ();//we have something to talk fast!
ADC_init (PulsePin);
T0_init ();//sets up to read Pulse Sensor signal every 2 ms
LCD1602_Init();//LCD initialization
}

Void main (void)
{
Sys_init ();
LCD1602_DisplayString (ucForum0);//display the contents of the
LCD1602_MoveToPosition (1, 0);//display position to move to the specified location
LCD1602_DisplayString (ucForum1);//display the contents of the
While (1)
{
SendDataToProcessing (' S ', Signal);//send Processing the raw Pulse Sensor data sent to deal with the original Pulse Sensor data
If (QS==true) {//Quantified Self flag is true when the arduino finds a heartbeat Quantified Self flag is true
FadeRate=255;//Set 'fadeRate Variable to 255 to fade the LED with pulse will "fadeRate" Variable is Set to 255, the LED with pulse out
SendDataToProcessing (' B ', BPM);//send heart rate with a 'B' prefix to send with "B" prefix heart rate
SendDataToProcessing (' Q ', IBI);//the send time between beats with a 'Q' prefix sent between the beat time with "Q" prefix
QS=false;//reset the Quantified Self flag for next time for the next untap Quantified Self sign
LCD1602_MoveToPosition (1, 9);
LCD1602_DisplayString (DisBuff);
}

//ledFadeToBeat ();

Delay (138);//take a break of 19.6 ms

}
}


//void ledFadeToBeat () {
//fadeRate -=15;//set value set LED LED fade out value
//fadeRate=constrain (fadeRate, 0255);//keep the LED fade value from going into negative Numbers. Keep the LED attenuation values are not turned negative!
//analogWrite (fadePin fadeRate);//fade LED away
//}


Void sendDataToProcessing (char symbol, int dat) {
Putchar (symbol);//symbol prefix tells Processing what type of data is what kind of data is processed by the prefix "coming symbols tell
Printf (" % d \ r \ n ", dat);//the data to send culminating in a carriage return to enter the end of the data sending
}

Void UART_init (void)
{
PCON & amp;=0 x7f;//baud rate not 2 x
SCON=0 x50;//8 bits of data, variable baud rate
BRT=0 XFD;//independent baud rate generator initial
AUXR |=0 x04;//the clock mode is set to 1 t
AUXR |=0 x01;//select independent baud rate generator
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related