Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

optical Heart rate measurment algorithm and C code

Status
Not open for further replies.

mamush2013

Newbie level 4
Newbie level 4
Joined
Mar 10, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,339
i'm final year biomedical engineering student! i'm working my FYP!! my work is to design a multi- parameter human vital sign measuring device. the parameters are blood pressure,heart rate and body temperature! the project is embedded project. i use sensors micro-controller(pic18f452) and a display unit(LCD) to my design. i face a difficulty while writing the c program!! i can't convert the value i get from the light intensity from sensor(LDR) to a understandable heart rate!! i need the calculation or code that converts the voltage from the sensor to the readable heart rate value!!
let's make things clear i'm using the following materials for my design
1. proteus isis simulation software
2. mplab x current version for my c codding workbench
3 c18 c compiler
and lastly here is my code!
Code:
 * File:   Temprature.c
 * Author: TOSHIBA
 *
 * Created on May 5, 2013, 3:54 AM
 */

#include <stdio.h>
#include <stdlib.h>
#include <adc.h>
#include<delays.h>
#include<string.h>
#include<p18f452.h>
#pragma config WDT=OFF,OSC=HS,OSCS=OFF,BORV=45,PWRT=ON,BOR=ON


#define rs PORTCbits.RC5
#define rw PORTCbits.RC6
#define en PORTCbits.RC7
#define sdata PORTD





void lcdcmd(unsigned char);
void lcddata(unsigned char);
void adc_con(int);
void adc_con1(int);
void adc_init(void);
void Print_string(char *A);
void Delay_ms(int);

char HR[]="Heart Rate";
char NO[]="PRESS BUTTON";
float LDR[10],avg_output=0,temp;
unsigned int i=0;
/*
 *
 *
 */
void main(void)
{
    TRISA=0x0f;        // Configure RA3 as input pin
    TRISB=0;        // Configure Port B as output port
    TRISC=0;
    TRISD=0;
            // Set cursor position to 1st line, 1st column




     TRISBbits.RB4=1;
     TRISBbits.RB5=1;
     TRISBbits.RB6=1;

    adc_init();        //ADC Initialization

    while(PORTBbits.RB5==1)
    {
            lcdcmd(0x38);        // Configure the LCD in 8-bit mode, 2 line and 5x7 font
            lcdcmd(0x0C);        // Display On and Cursor Off
            lcdcmd(0x01);        // Clear display screen
            lcdcmd(0x06);        // Increment cursor
            lcdcmd(0x80);
            Print_string(HR);
            lcdcmd(0x87);
            ADCON0=0xD1;
            ADRES=0;
            temp=0;
            for(i=0;i<10;i++)
                {
                    ADCON0bits.GO=1;                     // Start A/D
                    while(ADCON0bits.DONE==1);             // Wait

                    LDR[i]=ADRES ;                     //Store data
                    Delay_ms(5);
                    temp=temp+LDR[i];

                }
                avg_output=temp/10;
                avg_output=(1024-avg_output);                  // Take average
                adc_con(avg_output);

    }
    while(PORTBbits.RB5==0){
        lcdcmd(0x38);        // Configure the LCD in 8-bit mode, 2 line and 5x7 font
        lcdcmd(0x0C);        // Display On and Cursor Off
        lcdcmd(0x01);        // Clear display screen
        lcdcmd(0x06);        // Increment cursor
        lcdcmd(0x80);
        Print_string(NO);
        lcdcmd(0x87);
        Delay_ms(1000);
    }
}
void lcdcmd(unsigned char cmdout)
{
    sdata=cmdout;        //Send command to lcdport=PORTB
    rs=0;
    rw=0;
    en=1;
    Delay_ms(20);
    en=0;
}

void Delay_ms(int d)
{
    int i,j;
    for(i=0;i<d;i++)
    {
        for(j=0;j<d;j++)
        {
        }
    }
}
void adc_init()
{
    ADCON1=0xC0;                   // Make RA0/AN0 ,RA1,RA2,RA3,RA4,RA5,RA6 and RA7 ANALOG
                                // Select Channel0 & ADC off
                                   //     ADCON2=0x85;                            //  Fosc/32 clock option
    ADCON0=0xD1;                          // AN3... clock drived from internal RC Enable ADC
}
void adc_con( int adc_out)
{
    int adc_out1;
    int i=0;
    char position=0xC3;
    for(i=0;i<=3;i++)
    {
        adc_out1=adc_out%10;                     // To exract the unit position digit
        adc_out=adc_out/10;
        lcdcmd(position);
        lcddata(48+adc_out1);                    // Convert into its corresponding ASCII
        position--;

    }
    Delay_ms(100);
}
void adc_con1( int adc)
{
    int adc_out2;
    int i=0;
    char position=0xCF;
    for(i=0;i<=3;i++)
    {
        adc_out2=adc%10;                     // To exract the unit position digit
        adc=adc/10;
        lcdcmd(position);
        lcddata(48+adc_out2);                    // Convert into its corresponding ASCII
        position--;

    }
}
void lcddata(unsigned char dataout)
{

    sdata=dataout;    //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    Delay_ms(30);
    en=0;
}
void Print_string(char *a)
{
 int i;
 for(i=0;(*(a+i))!='\0';i++)
   {
     lcddata(*(a+i));
   }
}
 

Could you explain more about your sensor? I need exact output of sensor.
 

thank you for your kindness
the sensor i use is Light dependent resistor(LDR)!! if you see in the code the analog digital conversion is already done!! but the output is not the heart rate!! it's the lights intensity on the LDR!! use any LDR datasheet and tell me clue or code how it works on proteus isis simulator!! it's better if i upload the circuit of my design but i face a challenge to upload it!! lets make an image what ma design look like!! there is a light source(LED) that shines it's light on the finger tip. the light pass/ reflected from the finger illuminated on the LDR! the LDR's resistance varies depending on the intensity of the light reached to it. due to this resistance variance the voltage output also varies. before feeding this voltage to the ADC of the MCU there is amplification and conditioning of this voltage!!
 

Attachments

  • HeartRate.zip
    206.2 KB · Views: 83
  • heart rate.JPG
    heart rate.JPG
    176.8 KB · Views: 102

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top