CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2012
    Posts
    10

    Heartbeat Calculation Question

    Not really a programming ,but below is a heartbeat calculation and I just have a question on one of the calculations

    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()
    {
    
    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
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Heartbeat Calculation Question

    Bpm = frequency * 60

    Bpm = (1/tick) * 100 * 60

    Bpm = (1/tick) * 6000

    Bpm = 6000/tick

  3. #3
    Join Date
    Apr 2012
    Posts
    10

    Re: Heartbeat Calculation Question

    Quote Originally Posted by PredicateNormative View Post
    Bpm = frequency * 60

    Bpm = (1/tick) * 100 * 60

    Bpm = (1/tick) * 6000

    Bpm = 6000/tick
    But how come the come the value of tick is never divided into 1 and then multiplied?
    Is it canceled out like Bpm = (1/tick) * 6000/1,cancel both the one's out?

  4. #4
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Heartbeat Calculation Question

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

    However, if you want to think about it more deeply then, yes, 6000 is implicitly 6000/1, so you are really multiplying (1/tick)*(6000/1) = (1*6000)/(tick*1) = 6000/tick.

  5. #5
    Join Date
    Apr 2012
    Posts
    10

    Re: Heartbeat Calculation Question

    Quote Originally Posted by PredicateNormative View Post
    bpm = (1/tick) * 6000
    bpm = 6000 * (1/tick)
    bpm = (6000 * 1)/tick
    bpm = 6000/tick

    However, if you want to think about it more deeply then, yes, 6000 is implicitly 6000/1, so you are really multiplying (1/tick)*(6000/1) = (1*6000)/(tick*1) = 6000/tick.
    I need to work on my maths but thanks

  6. #6
    Join Date
    Apr 2012
    Posts
    10

    Re: Heartbeat Calculation Question

    Actually just on this
    Code:
    r=bpm%100;
    Is this wrong? I mean is the % operator used for finding remainders e.g 10 % 6 =4

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Heartbeat Calculation Question

    Quote Originally Posted by johnjameson View Post
    Actually just on this
    Code:
    r=bpm%100;
    Is this wrong? I mean is the % operator used for finding remainders e.g 10 % 6 =4
    Write a bit of code and compare the two approaches with some different input values.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured