Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C++

ECG recording, storing, filtering and recognition

Rate me:
Please Sign up or sign in to vote.
4.72/5 (110 votes)
14 Apr 200411 min read 729.9K   38.4K   156  
Full open code project for making driver and application software for ECG medical measurements.
// MCP3002.cpp: implementation of the MCP3002 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MCP3002.h"
#include "MultimediaTimer.h"
#include "ADC3002.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//Delcare out timer function
//Function must be static
static	void TimerFunction(void* obj,UINT idEvent);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

MCP3002::MCP3002()
{

}

MCP3002::~MCP3002()
{

}

void TimerFunction(void* obj,UINT idEvent)
{
	//This is our timer actevated function
	//First get a pointer to class functions
	MCP3002* mcp = (MCP3002*) obj;
	//Activate class functions
	mcp->HandleTimer(idEvent);

}

void MCP3002::HandleTimer(UINT nIDEvant)
{
	//This function is activated from MM timer events
	//Because we need to make 5000 samples do them 
	if(i_mmcount<=5000)
	{
		//GetADC Samples
		Channel_0[i_mmcount] = ADC_Ch_0();
		Channel_1[i_mmcount] = ADC_Ch_1();
		//update counter
		i_mmcount++;
	}

	//After we have done all samples stop sampling and MM timer
	if(i_mmcount>5000)
	{
		MMT_Stop();//Stop MMTimer
		DoEndNotification();//Make a notification to the program
	}

}
void MCP3002::MMT_Stop()
{
	//This function stops the MM timer
	Sleep(10);
	TEnd = CTime::GetCurrentTime();
	//Stop timer
	MMTimer.StopTimer();
	Sleep(10);
}

void MCP3002::MMT_Start(unsigned short LPT)
{
	//This function sets the LPT type
	//Zero the counter and after this stop the timer
	//Now it can be restarted and do samples
	i_mmcount = 0;
	LPT_PORT = LPT;
	//If MMTimer alredy runs stop it now!
	MMT_Stop();
	//Before start timer get the time moment
	TStart = CTime::GetCurrentTime();
	//Do timer event any 2 msec = 500Hz +- 2Hz
	MMTimer.StartTimer(this,2,10,TimerFunction);

}

unsigned short MCP3002::ADC_Ch_0()
{
	return adc3002.GetChanne_0(LPT_PORT,10);

}

unsigned short MCP3002::ADC_Ch_1()
{
	return adc3002.GetChanne_1(LPT_PORT,10);

}

void MCP3002::SetEndSampleNotification(void *obj, EndSampleNotification endnotification)
{
	//Sets the end sample notification event
	//so it will be activated after sampling period
	object = obj;
	//See declaration of EndSampleNotification
	EndNotification = endnotification;

}

void MCP3002::DoEndNotification()
{
	//This function activates a function and pass a parameters
	//to in our class
	int len;
	len = 5000;
	//activates a function EndNotification see declaretion
	EndNotification(object,&Channel_0[0],&Channel_1[0],len,TStart,TEnd);

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
Bulgaria Bulgaria
PhD, Cum Laude in digital automation systems
M.S. in Telemommunication management
B.S. in Telecommunication systems engineering
Programming: CUDA, C/C++, VHDL
Software and Hardware development and consulting:
data acquisition, image processing, medical instrumentation

Comments and Discussions