Thread: Heartbeat Calculation Question

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    7

    Heartbeat Calculation Question

    Hey guys,just have a question on the heartbeat calculation below

    Code:
    #include <REG51.H>                /* special function register declarations   */ #include <stdio.h>                /* prototype declarations for I/O 
     
    
    
    unsigned char sec,sec100;
    unsigned int bt,tick,r,bpm;
    void msdelay(unsigned int);
    
    
    void extrint (void) interrupt 0 // external Interrupt to detect the heart pulse
    {
    bt=tick; // number of ticks are picked
    tick=0; // reset for next counting
    }
    void timer0 (void) interrupt 1 using 1 // Timer 0 for one second time
    {
    TH0 = 0xdc; //The value is taken for Ssc/100 at crystal 11.0592MHz
    sec100++; // It is incremented every Ssc/100 at crystal 11.0592MHz
    tick++; // This variable counts the time period of incoming pulse in Sec/100
    if(tick>=3500){tick=0;} // tick are limited to less trhan 255 for valid calculation
    if(sec100 >=100) // 1 sec = sec100 * 100
    {
    sec++;
    sec100=0;
    }
    }
    void main()
    {
    serial_init(); 
    P0=0xff;
    P1=0xff;
    P2=0xff;
    P3=0xff;
    
    
    EA = 1;
    TMOD = 0x21;
    IT0 = 1;
    EX0 = 1;
    ET0 = 1;
    TR0 = 1;
    msdelay(1000);
    
    
    msdelay(1000);
    printf("Heart beat ");
    msdelay(1500);
    msdelay(500);
    //delay(15000);
    bpm=0;bt=0;
    while(1)
    {
    if(sec >=1)
    {
    sec=0;
    /*
    The sampling time is fixed 1 sec.
    A variable "tick" is incremented with one tick per 100mSc in the timer 0 interrupt routine.
    Each on occurring of external interrupt the value in the "tick" is picked up
    and it is set to zero for recounting.
    The process continues till next external interrupt.
    Formula for calculating beats per minutes (microcontroller based heartbeat monitor ) is
    as tick is the time period in Sec/100. so extract the frequency of pulses at external interrupt
    Frequency = (1/tick)* 100 i.e pulses /sec
    Then
    bpm = frequency * 60 for one minutes i.e pulses per minute
    in short we can do it as
    bpm = 6000/ bt
    */
    
    
    if(bt >=7){
    bpm = 6000/bt; // for valid output bt is limited so that it should be greater than 6
    msdelay(500);
    //printf("Pulse. ");
    r=bpm%100;
    //printf("bpm: %d\r\n", bpm);
    printf(" %d\r\n", bpm);    
    }
    else {
    printf("out of range");} // otherwise bpm will be shown zero
    }
    }
    }
    
    
    void msdelay(unsigned int i)
    {
    //unsigned int i;
    while(i --);
    }
    Frequency = (1/tick)* 100 i.e pulses /sec
    Then
    bpm = frequency * 60 for one minutes i.e pulses per minute
    in short we can do it as
    bpm = 6000/ bt

    How is this shortcut working? or what I mean is where did the 6000 figure come from?

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    this has nothing to do with c...Sigh

    Frequency = (1/tick)* 100 i.e pulses /sec

    bpm = frequency * 60 forone minutes i.e pulses per minute

    bpm = (1/tick)* 100 * 60 forone minutes i.e pulses per minute

    100* 60 = 6000

    bpm = (1/tick)* 6000

    tick = bt

    bpm =(1/bt)*6000 = 6000/bt

    Last edited by africanwizz; 09-02-2014 at 03:12 AM. Reason: meh..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple calculation question.
    By Dave11 in forum C Programming
    Replies: 1
    Last Post: 02-08-2014, 08:39 AM
  2. calculation
    By Rohit88 in forum C Programming
    Replies: 9
    Last Post: 01-03-2012, 01:53 PM
  3. Calculation Question
    By NinjaFish in forum C Programming
    Replies: 4
    Last Post: 04-07-2011, 06:21 PM
  4. calculation always gives 0
    By Emma K in forum C Programming
    Replies: 18
    Last Post: 11-24-2010, 06:00 PM
  5. Help With Calculation
    By WackoWolf in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2005, 05:18 PM