Serial Ecg Frequency
ECG Simulator 2. Steps ECG SIMULATOR Purpose simulate the normal sinus rhythm ECG signal 3 leads RA,LA,RL Background In normal electrocardiography ECG or EKG if youre German, three leads make up the Einthovens triangle. Two leads are taped to the right and left side of the chest above the heart RA right arm, LA left arm and one lead is taped to the lower chest, typically on the right hip RL right leg. Its important to know that these ECG signals are millivolts in amplitude. This can be achieved by feeding the DA converter through a voltage divider to get to the millivolt levels. The ECG signal I found a suitable ECG waveform from the internet. Here is how I converted a picture from my monitor screen to a C language array of AD values, each spaced 1. A. Screen shot of waveform using the free screen capture program MWSNAP http www. B. Digitize the jpeg waveform using the free digitizing program ENGAUGE http digitizer. Serial Ecg Frequency' title='Serial Ecg Frequency' />C I wrote a Python program to convert the rather irregular samples from ENGAUGE to an array of values spaced 1. Then I created a text file where these data points were part of a C language array construct that is, the data points are C initializers. D Cut and paste from the text file the C data array with initializers into the Arduino sketch below. Arduino Resources Digital Output 9 chip select the 7 segment display SPI port low to select Digital Output 1. DA converter low to select Digital Output 1. SDI data to the DA converter SPI interface Digital Output 1. SCK clock to the DA converter SPI interface Analog Input 0 center wiper pin of 5k ohm pot heart rate adjust I followed the Timer. Sebastian Wallin http popdevelop. I set up the SPI interface according to the excellent instructions of Australian John Boxall, whose wonderful website has many excellent Arduino tutorials http tronixstuff. Programmer James P Lynch lynch. BBjpegwm-1024x408.jpg' alt='Serial Ecg Frequency' title='Serial Ecg Frequency' />SPI. SPI interface to the DA converter and 7 segment displayinclude lt Wire. Wire library various constants used by the waveform generatordefine INIT 0define IDLE 1define QRS 2define FOUR 4define THREE 3define TWO 2define ONE 1 ydata5. Waveform is scaled for a 1. DA converter 0. A 6. ECG would require this waveform 5. Num. Samples sizeofydata 2 number of elements in ydata aboveunsigned int QRSCount 0 running QRS period msec countunsigned int Idle. EE Times connects the global electronics community through news, analysis, education, and peertopeer discussion around technology, business, products and design. Search and browse Intel processors and chipsets by platform code name, brand name, application, or release date. DSC6000. The new DSC6000 family is the industrys smallest MEMS MHz oscillator with the lowest power consumption over full frequency range of 2 KHz to 100 MHz. Count 0 running Idle period msec countunsigned long Idle. Game Maker 8 Pinball Tutorial. Period 0 idle period is adjusted by pot to set heart rateunsigned int State INIT states are INIT, QRS, and IDLEunsigned int Display. Count 0 counts 5. Timer. 2 reload value, globally availablefloat Beats. Per. Minute floating point representation of the heart rateunsigned int Bpm integer version of heart rate times 1. Bpm. Low lowest heart rate allowed x. Bpm. High highest heart rate allowed x. Value place holder for analog input 0unsigned long Bpm. Values3. 2 0, 0, 0, 0, 0, 0, 0, 0, holds 3. Bpm. Average 0 used in a simple averaging filterunsigned char Index 0 used in a simple averaging filter unsigned int Display. Value 0 filtered Beats Per Minute sent to displayvoid setup Configure the output ports 1 msec intrerrupt indicator and DA SPI supportpin. Mode9, OUTPUT 7 segment display chip select low to select chippin. Mode1. 0, OUTPUT DA converter chip select low to select chippin. Mode1. 1, OUTPUT SDI datapin. TOMB050109Cwm21-1024x417.jpg' alt='Serial Ecg Frequency' title='Serial Ecg Frequency' />Mode1. OUTPUT SCK clock initial state of SPI interface. SPI. begin wake up the SPI bus. SPI. set. Data. Mode0 mode CPHA0, data captured on clocks rising edge low to highSPI. Clock. DividerSPICLOCKDIV6. SPI. set. Bit. OrderMSBFIRST bit 7 clocks out first establish the heart rate range allowed Bpm. Low 3. 00 3. 0 bpm x 1. Bpm. High 6. 0. Num. Samples 0. Bpm. Low 3. Bpm. High 6. 0. 0 floatNum. Samples 0. 0. 01 1. First disable the timer overflow interrupt while were configuring. Serial Ecg Frequency' title='Serial Ecg Frequency' />TIMSK2 1lt lt TOIE2 Configure timer. PWM etc. TCCR2. A 1lt lt WGM2. WGM2. 0 TCCR2. B 1lt lt WGM2. Select clock source internal IO clock ASSR 1lt lt AS2 Disable Compare Match A interrupt enable only want overflow TIMSK2 1lt lt OCIE2. A Now configure the prescaler to CPU clock divided by 1. TCCR2. B 1lt lt CS2. CS2. 0 Set bits. TCCR2. B 1lt lt CS2. Clear bit We need to calculate a proper value to load the timer counter. The following loads the value 1. Timer 2 counter register The math behind this is CPU frequency prescaler value 1. Hz 8us. desired period 8us 1. MAXuint. 8 1 1. Save value globally for later reload in ISR tcnt. Finally load end enable the timer TCNT2 tcnt. TIMSK2 1lt lt TOIE2 void loop read from the heart rate pot Analog Input 0 Value analog. Read0 map the Analog Input 0 range 0. Bpm range 3. 00. Bpm mapValue, 0, 1. Bpm. Low, Bpm. High To lessen the jitter or bounce in the displays least significant digit, a moving average filter 3. Bpm. ValuesIndex Bpm add latest sample to eight element arrayif Index 3. Index 0 Bpm. Average 0 for int i 0 i lt 3. Bpm. Average Bpm. Valuesi Bpm. Average 5 Divide by 3. XXX. X since update is a multi byte transfer, disable interrupts until its doneno. Interrupts Display. Value Bpm. Average interrupts given the pot value beats per minute read in, calculate the Idle. Period msec this value is used by the Timer. Beats. Per. Minute floatBpm 1. Interrupts Idle. Period unsigned intfloat6. Beats. Per. Minute floatNum. Samples interrupts delay2. Timer. 2 Interrupt Service Routine Interrupt Service Routine ISR for Timer.