Heart Rate Pulse

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Hi,

I am building a heart rate sensor. I have already built a heart rate receiver circuit and i would like to input the pulse into the ADC of my pic microcontroller. I have written the code to display the analog voltage on the LCD. However i think that the pulse is too fast for the LCD to display it. Is there a way of slowing this down. Because i would like to know if the PIC is receiving the pulse. I am using PIC16f887.

Thanks
 

beenthere

Joined Apr 20, 2004
15,819
Sure, you take in the data at the real-world rate, and display the converted numbers at whatever rate you can keep up with. This isn't too likely to be meaningful. If you had a graphics display, you could scroll the waveshape across it.
 

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Thanks for your help. I am now trying to write the code to calculate and display the heart rate in BPM. I am using MikroC. I am using the MikroC example to display an analog voltage on the LCD. And i would like to adapt it to show heart rate.

The heart rate pulses occur on average over once a second. I have written the following code but cant quite manage to get the LCD to display my value. my code i have added is in bold. When a pulse is picked up the voltage is at least 1 volt. Therefore when the volts digit is great than 0 i would like to record the time on the counter. i would like the counter to carry on and then record the next pulse time. then i would like to use the time interval to calculate the bpm. does this sound okay? i am unsure of whether the counter is written correctly? and also i cannot display the value? Could you please help me in any way possible? Thanks

unsigned char ch;
unsigned char heart_rate_char;
unsigned int adc_rd;
unsigned int T1;
unsigned int T2;
int Heart_Rate;
char *text;
long tlong;
unsigned counter, tmp; // counter variable, temporary variable
unsigned short T1_count = 0; // Timer1 counter
void main() {
INTCON = 0; // disable all interrupts
ANSEL = 0x04; // Configure AN2 pin as analog input
TRISA = 0x04;
ANSELH = 0; // Configure other AN pins as digital I/O
Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init_EP5, see Autocomplete
LCD_Cmd(LCD_CURSOR_OFF); // send command to LCD (cursor off)
LCD_Cmd(LCD_CLEAR); // send command to LCD (clear LCD)
text = "Heart Rate"; // assign text to string
LCD_Out(1,1,text); // print string a on LCD, 1st row, 1st column
ADCON1 = 0x82; // configure VDD as Vref, and analog channels
TRISA = 0xFF; // designate PORTA as input

while (1){
adc_rd = ADC_read(2); // get ADC value from 2nd channel

tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
ch = tlong / 1000; // extract volts digit
LCD_Chr(2,9,48+ch); // write ASCII digit at 2nd row, 9th column
}
/// Heart Rate ///

for (;;){
T1_count++ ;}

if (ch > 0) {
T1 = T1_count;}

Delay_ms(50) ;
if (ch > 0) {
T2 = T1_count;}

Heart_Rate = 60 / (T2 - T1) ;
T2 = T1 ;
heart_rate_char = (char) Heart_Rate;
LCD_Chr_CP(heart_rate_char) ;


//
//
// LCD_Chr_CP('.');
//
// ch = (tlong / 100) % 10; // extract 0.1 volts digit
// LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
//
// ch = (tlong / 10) % 10; // extract 0.01 volts digit
// LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
//
// ch = tlong % 10; // extract 0.001 volts digit
// LCD_Chr_CP(48+ch); // write ASCII digit at cursor point
// LCD_Chr_CP('V');
//
// Delay_ms(1);
// }
}//~!
 

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Hi i have spent three weeks trying to get this code to work. still not working i need help please. This is my code, i dont think 'Count' is incrementing correctly.

unsigned int temp_res;
int i;
int T1;
int T2;
int T3;
int Count;
int Heart_Rate;
char Heart_Rate_char;
int x;
int y;
void main() {



ANSEL = 0x04; // Configure AN2 pin as analog
TRISA = 0xFF; // PORTA is input
ANSELH = 0; // Configure other AN pins as digital I/O
// TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
TRISC = 0x3F;



do {
Count=0;
// Loop:

Count=Count+1;

temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTD = temp_res; // Send lower 8 bits to PORTD
PORTC = temp_res >> 2; // Send 2 most significant bits to RB7, RB6

if (temp_res > 100 && (T1=0)){
T1=T1+1;
T2= Count;}
// Delay_ms(50);


if (temp_res > 100 && (T1=1)){
T1=T1+1;
T3 = Count;}
if (T1=2){
Heart_Rate = 60 / (T3 - T2) ;
T1 = 0 ;
T2 = 0 ;
T3 = 0 ;
Count = 0 ;
Heart_Rate_char = (char) Heart_Rate;
x = (Heart_Rate/10);
y = (Heart_Rate%10);
Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init_EP5, see Autocomplete
ANSEL = 0;
ANSELH =0;
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
LCD_Chr(1,2,x+48);
LCD_Chr_CP(y+48);
LCD_Chr_CP(' ');
LCD_Chr_CP('B');
LCD_Chr_CP('P');
LCD_Chr_CP('M');

// goto Loop
}
} while(1);
}
 
Top