Martin Valencia
Published

TI Hercules RM57 Cardiac Monitor

filtering the cardiac signal digitally, using MATLAB and TI DSP libraries.

IntermediateWork in progress1,370
TI Hercules RM57 Cardiac Monitor

Things used in this project

Hardware components

MCP6022
×2
Hercules RM57
×1
resistances
×10

Software apps and online services

MATLAB
MATLAB

Hand tools and fabrication machines

Code Composer Studio

Story

Read more

Custom parts and enclosures

Amplifier circuit board

Schematics

Amplifier circuit

Code

HL_sys_mpu.asm

Plain text
/** @file HL_sys_main.c 
 *   @brief Application main file
 *   @date 03.Apr.2015
 *   @version 04.04.00
 *
 *   This file contains an empty main function,
 *   which can be used for the application.
 */

/* 
 * Copyright (C) 2009-2015 Texas Instruments Incorporated - www.ti.com
 *
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_adc.h"
#include "arm_math.h"
#include "type_defs.h"
/* USER CODE END */

/** @fn void main(void)
 *   @brief Application main function
 *   @note This function is empty by default.
 *
 *   This function is called after startup.
 *   The user can use this function to implement the application.
 */

/* USER CODE BEGIN (2) */
/* -------------------------------------------------------------------
 * External Input and Output buffer Declarations for FFT Bin Example
 * ------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
 ** Macro Defines
 ** ------------------------------------------------------------------- */

uint32 ch_count = 0;
uint32 id = 0;
uint32 value = 0;
adcData_t adc_data[3];
uint32 rticont0 = 0;
uint8 enable_main = 0;

#define TEST_LENGTH_SAMPLES 512
#define BLOCK_SIZE			16
#define NUM_TAPS			91

/* -------------------------------------------------------------------
 * The input signal and reference output (computed with MATLAB)
 * are defined externally in arm_fir_lpf_data.c.
 * ------------------------------------------------------------------- */

float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES];
//extern float32_t refOutput[TEST_LENGTH_SAMPLES];

/* -------------------------------------------------------------------
 * Declare Test output buffer
 * ------------------------------------------------------------------- */

static float32_t testOutput[TEST_LENGTH_SAMPLES];

/* -------------------------------------------------------------------
 * Declare State buffer of size (numTaps + blockSize - 1)
 * ------------------------------------------------------------------- */

static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1];

/* ----------------------------------------------------------------------
 ** FIR Coefficients buffer generated using fir1() MATLAB function.
 ** fir1(28, 6/24)
 ** ------------------------------------------------------------------- */
/*Filtro para una frecuencia de 1kHz*/
const float32_t firCoeffs32[NUM_TAPS] = { -0.0006169597f, -0.0005871033f,
		0.0002029630f, 0.0011655789f, 0.0012391641f, -0.0000000000f,
		-0.0015950227f, -0.0019147530f, -0.0004185451f, 0.0014847759f,
		0.0018603273f, 0.0005736256f, -0.0004857236f, -0.0000000000f,
		0.0006296724f, -0.0009637983f, -0.0040489887f, -0.0041816678f,
		0.0015223219f, 0.0089638249f, 0.0095591563f, -0.0000000000f,
		-0.0118316580f, -0.0137401414f, -0.0028931297f, 0.0098698999f,
		0.0118958688f, 0.0035346931f, -0.0028924558f, -0.0000000000f,
		0.0035435663f, -0.0053112976f, -0.0219757435f, -0.0224982435f,
		0.0081794156f, 0.0485117720f, 0.0526392190f, -0.0000000000f,
		-0.0702023067f, -0.0870004554f, -0.0200890917f, 0.0781929629f,
		0.1145171135f, 0.0464266302f, -0.0689531611f, 0.8753753895f,
		-0.0689531611f, 0.0464266302f, 0.1145171135f, 0.0781929629f,
		-0.0200890917f, -0.0870004554f, -0.0702023067f, -0.0000000000f,
		0.0526392190f, 0.0485117720f, 0.0081794156f, -0.0224982435f,
		-0.0219757435f, -0.0053112976f, 0.0035435663f, -0.0000000000f,
		-0.0028924558f, 0.0035346931f, 0.0118958688f, 0.0098698999f,
		-0.0028931297f, -0.0137401414f, -0.0118316580f, -0.0000000000f,
		0.0095591563f, 0.0089638249f, 0.0015223219f, -0.0041816678f,
		-0.0040489887f, -0.0009637983f, 0.0006296724f, -0.0000000000f,
		-0.0004857236f, 0.0005736256f, 0.0018603273f, 0.0014847759f,
		-0.0004185451f, -0.0019147530f, -0.0015950227f, -0.0000000000f,
		0.0012391641f, 0.0011655789f, 0.0002029630f, -0.0005871033f,
		-0.0006169597f };

/* ------------------------------------------------------------------
 * Global variables for FIR LPF Example
 * ------------------------------------------------------------------- */

uint32_t blockSize = BLOCK_SIZE;
uint32_t numBlocks = TEST_LENGTH_SAMPLES / BLOCK_SIZE;

float32_t snr;

/* Reference index at which max energy of bin ocuurs */
void capturaadc();
void delay_seg(float delay);

/* USER CODE END */

void main(void) {
	/* USER CODE BEGIN (3) */

	adcInit();
	uint32_t i;
	arm_fir_instance_f32 S;
	float32_t *inputF32, *outputF32;

	/* Initialize input and output buffer pointers */
	inputF32 = &testInput_f32_1kHz_15kHz[0];
	outputF32 = &testOutput[0];

	/* Call FIR init function to initialize the instance structure. */
	arm_fir_init_f32(&S, NUM_TAPS, (float32_t *) &firCoeffs32[0],
			&firStateF32[0], blockSize);

	int ii = 0;

	while (1) {

		for (ii = 0; ii < TEST_LENGTH_SAMPLES; ii++) { //samples =2**N N128,256,1024,512

			capturaadc();
			testInput_f32_1kHz_15kHz[ii] = (float32_t) (adc_data[0].value
					- adc_data[1].value);

			delay_seg(2.5e-3);		// tiempo de muestreo

		}

		/*Es necesario Detener la RTI para que no interfiera con el tiempo que consume FFT*/
		/* ----------------------------------------------------------------------
		 ** Call the FIR process function for every blockSize samples
		 ** ------------------------------------------------------------------- */
		int a = 0;
		for (i = 0; i < numBlocks; i++) {
			arm_fir_f32(&S, inputF32 + (i * blockSize),
					outputF32 + (i * blockSize), blockSize);
		}
		int b = 0;

	}
	/* USER CODE END */
}

/* USER CODE BEGIN (4) */
void capturaadc() {
	adcStartConversion(adcREG1, adcGROUP1); 			//Start ADC conversio
	while (!adcIsConversionComplete(adcREG1, adcGROUP1))
		;				// ConfigutaR halcogen el trigger por sofware

	ch_count = adcGetData(adcREG1, adcGROUP1, &adc_data[0]);
	ch_count = ch_count;
}
void delay_seg(float delay) {
	int long K_temp = (int long) (1.36e7 * delay);
//	delay_debug=K_temp;
	int long ii;
	for (ii = 0; ii <= 2 * K_temp; ii++) //10000 algoritmos que se desarrollan en 734us
			{
	}
}
/* USER CODE END */

Credits

Martin Valencia

Martin Valencia

3 projects • 3 followers
Hola, soy ingeniero electrónico de profesión y lo tengo como pasión y pasatiempo!
Thanks to Jan Cumps.

Comments