Heart-rate measurement

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

Heart-rate measurement

Postby arivalagan13 » Tue Apr 01, 2014 1:52 am

Hi all,
I'm about to measure the heart-rate beats-per minute.
I'll be using the technique of passing IR through ring finger and detecting the IR by photo transistor.
This Photo transistor output will be amplified and filtered.
The output frequency of this signal is around 1.3Hz, an extremely low frequency sinusoid.
This signal will be converted into square using a comparator.

Now, how should I do the low frequency processing (amplification and filtering) with PSoC1(29466-24pxi)?
Can anybody help me with some application notes? or any other relevant information.

Regards
Arivalagan M
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby danadak » Tue Apr 01, 2014 3:20 am

Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Heart-rate measurement

Postby arivalagan13 » Wed Apr 02, 2014 4:23 am

The documents attached shows different techniques in measuring heart-rate.
But the one I would like use is based on near infra-red spectroscopy. I attach the relevant paper for Ur reference.
Requesting U to pay particular attention to fig.7 & 8. I want to implement this with PSoC1. Any reference would be of great support.

Regards
Arivalagan M
Attachments
bio wearable2012.pdf
(1.69 MiB) Downloaded 224 times
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby danadak » Wed Apr 02, 2014 10:49 am

If you look at this circuit its DC G is the product of the first gain stage
followed by the next, or ~ 121 x 561, ~ 67K, or pretty high. Plus that design
has limited 60 Hz CM rejection, even though both G stages rolled off. You
could use a simple spice simulation to determine where the response curve
breaks, probably around a few hundred hertz.

You could use external IA to get the CM rejection, and the high G. And/or use
a much higher powered IR LED to get more source signal.

The last amp is being used as nothing more that a comparator, PSOC easily
handles that.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Heart-rate measurement

Postby arivalagan13 » Mon Apr 21, 2014 1:36 am

Hi all,
I managed to get a pulse and with the comparator am now generating approximate square pulses of frequency approximately 1.4Hz.
Now, I want to measure the width with PSoC1.How do I measure this with PSoC1 timer or any other facility available with PSoC1.

Regards
Arivalagan M
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby danadak » Mon Apr 21, 2014 3:18 am

Several methods –

1) Using sleep timer, set it to fire at resolution you want for PW measurement.
Set a variable, say myPW so that when sleep timer ISR fires it is incremented
by 1. Now poll the comparator output, when it rises set a flag, set myPW = 0.
When it falls test if rise flag set, read myPW, thats your PW in sleep timer
T increments. Reset flag.

If you do not want to poll you can setup comparator ISR. See following.

http://www.cypress.com/?id=4&rID=27301

http://www.psocdeveloper.com/forums/viewtopic.php?f=3&t=11413

2) Use a counter, route comparator output to counter enable. Set counter period
to its full scale value, eg. 255 for 8 bit, 65535 for 16 bit. When comparator out is
high, either by ISR or polling, start the counter, when low stop counter, read it,
subtract that from full scale value, that is your PW in terms of its clock period
increments you choose when you set it up.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Heart-rate measurement

Postby arivalagan13 » Thu May 01, 2014 7:28 am

Hi
I followed the second method.
The logic I followed is as follows:
P0[0] is connected to the comparator (external comparator)..
I'm reading the value of this port pin and test it for high.if the pin is enabled counter is started.
If not the counter will be stopped.
But am getting few errors of the project.

I've attached the Archive of the project...
My humble request is
Kindly go through the entire project from settings to code and suggest me for corrections..
(My frequency of the input signal is <10 Hz approx. 1.3 Hz)

Note: I should complete my work in a day time for my M.tech thesis and help accordingly will be of great help. I should not mention this.But, its situation.
Sorry, if am mistaken..


Regards
M.Arivalagan
Attachments
counter.Archive1.zip
(216.11 KiB) Downloaded 192 times
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby bobmarlowe » Thu May 01, 2014 7:58 am

The error is on line 23 in main.c
You wrote
Code: Select all
    count = Counter16_wReadCounter(void);

but should simply read
Code: Select all
    count = Counter16_wReadCounter();



Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Heart-rate measurement

Postby arivalagan13 » Thu May 01, 2014 10:26 am

Thats great..now the error got cleared..
But, now when I program it am not getting the desired output.

First, the LCD output BPM count is getting displayed like this

BPM count: 0FFFF

If I comment the line 26(LCD_PrHexInt(count)..the display reads BPM count:0..

Donno what is happening...Also I've the following doubt..
I declare count as WORD...but line 26 prints integer...Am slipping anywhere.

Also,are the project settings are correct?

Kindly support

Regards
Arivalagan M
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby bobmarlowe » Thu May 01, 2014 12:06 pm

Some more bugs:
What is, when your program main() has finished the last statement? main() exits and this would be a reboot.
you need an initialization part and a loop that executes forever (or as long as the PSoC is powered). Since the PSoC is very fast you should think about to wait for having a result ready and then display it.

To the displaying: You position to Line 0, column 5 and write some text "BPM Count:0" you should write "BPM Count:" to position 0,0 and then within the Loop position to line 0 column 10 and print your value which should be a 16 bit unsigned integer (which is a word)
I did not look at your settings yet.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Heart-rate measurement

Postby danadak » Thu May 01, 2014 3:50 pm

Code: Select all
//Use the following to convert integer (word, count) to a string
//then print on display.

char lcdbpm[10];
     
     LCD_Position(0,0);
     LCD_PrCString("BPM Count:0");

     itoa (lcdbpm, count, 10);
     LCD_Position(0,9);
     LCD_PrString( “          “ );            // Clear old value off LCD
     LCD_Position(0,9);
     LCD_PrString( lcdbpm );            // Print the decimal value of BPM



Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Heart-rate measurement

Postby arivalagan13 » Thu May 01, 2014 5:40 pm

I've done the said changes..But still getting error. Also am archiving the project.requesting to have a check with settings...

#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
WORD count;
char lcdbpm[10];

void main(void)
{
M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
LCD_Start(); // Initialize LCD
LCD_Position(0,0);
LCD_PrCString("BPM is: 0");
if (PRT0DR && 0x01)
{
Counter16_Start();
}
if (PRT0DR && 0x00)
{
Counter16_Stop();
}
count = Counter16_wReadCounter();
itoa(lcdbpm,count,10);
LCD_Position(0,9);
LCD_PrString(" ");
LCD_Position(0,9);
LCD_PrString(lcdbpm);

}


But, am getting these errors
!W C:\Users\ARIVAZ~1\DOCUME~1\PSOCDE~1.3PR\counter\counter\counter\main.c(25):[warning] [MISRA 2200]calling an undeclared function may cause unexpected behavior if the function
takes or returns values other than int
!W C:\Users\ARIVAZ~1\DOCUME~1\PSOCDE~1.3PR\counter\counter\counter\main.c(25):[warning] [MISRA 2714]calling a function without prototype may cause unexpected behavior if the function
takes or returns values other than int
!E C:\Users\ARIVAZ~1\DOCUME~1\PSOCDE~1.3PR\counter\counter\counter\main.c(27): type error in argument 1 to `LCD_PrString'; found `pointer to __flash char' expected `pointer to char'
make: *** [obj/main.o] Error 1
counter - 2 error(s) 2 warning(s) 07:03:37

Regards
Arivalagan M
Attachments
counter.Archive2.zip
(220.54 KiB) Downloaded 179 times
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby arivalagan13 » Thu May 01, 2014 5:56 pm

Now I included the two headers #include "stdlib.h" & #include"string.h" and now the warning gets cleared and getting only the second point as error
c(29):type error in argument 1 to 'LCD_PrString':found 'pointer to __flash char' expected 'pointer to char'.

Regards
Arivalagan M
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby arivalagan13 » Thu May 01, 2014 9:36 pm

I managed to clear the errors n I was able to download the program to psoc
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby danadak » Fri May 02, 2014 2:50 am

Sorry I forgot to tell you about the .h includes.

Program work as you expected ?

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Heart-rate measurement

Postby arivalagan13 » Fri May 02, 2014 8:41 am

No Dana,its not working the way it is expected...In the last archive attachment the only change I've done was I replaced LCD_PrCString(" "); and errors got cleared..

Now the problem seems to be different..When I place my finger I get the pulse of less than 10Hz(attached the screenshot)...Now the counter starts and counts until
some value say 105...then after a short while again counts to some value say 400 or so..this cycle continues forever...

Am stuck at this point...trying to troubleshoot it the whole day with failure..

I attach the archive of the current project..Kindly go through it...

Not yet done the subtraction of counter value from 65535..before that I faced with this problem..
(attaching the CRO screenshot in the next post)
Attachments
counter.Archive3.zip
(297.03 KiB) Downloaded 196 times
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby arivalagan13 » Fri May 02, 2014 8:43 am

Attaching the heart rate pulse viewed with the CRO

Regards
Arivalagan M
Attachments
Heart Pulse in CRO_BPM.jpg
arivalagan13
Cheese Wheel
Cheese Wheel
 
Posts: 129
Joined: Sun Dec 23, 2012 3:32 am

Re: Heart-rate measurement

Postby danadak » Fri May 02, 2014 2:14 pm

To measure PW you basically -

1) Start counter with API, then its enable with a high from a pin or from comparator starts it counting
2) Counter starts counting down from 65535
3) When enable pin or comparator goes low (by polling or an interrupt on comparator out going low)
a. Stop counter with API (its already stopped because of enable going low, but
you have to do this to insure all logic is stopped)
b. Read counter with API
c. Subtract value in b. from 65535, thats the number of counter clks in time pulse was high
d. Reload counter with 65535
c. Restart counter with API

Your clock to counter is CPUclk/2 / VC1 / VC2 / VC3 = 12 Mhz / 16 / 16 / 256 =~ 183 hz =$ 5.5 mS.
That is the time value associated with each count of the counter, is that the T resolution increment
you want ? If not change the VC1/ VC2 / VC3 divide chain to get the time increment you need.

I do not see any of this code or the comparator or any analog in design ?

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire


Return to “%s” PSoC1 General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron