Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Heart Rate Monitor Program using 68HC11

Status
Not open for further replies.

brightjoey

New Member
In our module, we are using a function generator to output a pulse to get the output. Now I forgot to print screen the actual 68hc11 board itself. Hopefully tomorrow I can get into the Uni lab and take some snapshots of it. What I can do is explain what's going on. The hardware is all already set. The chip is already implemented into the board itself, so all we have to do is get some test wires, plug it into the board, power supply,serial port etc.

This is the assignment paper itself.
https://docs.google.com/open?id=0B49Ztg2pB62SZDMwNzgyZDktN2MxMi00YmE4LThjMjktMTVhM2JhODQwNjVi

This is the entire module book for this semester. It's quite thick (436 pages) but half of it is the specs for the 6811.
https://docs.google.com/open?id=0B49Ztg2pB62SNzlkN2RhYjMtZTM4Yy00YTk4LWFhZmItYjJjOGFkYmFkNGJj

Page 113,198-199 explains how to upload the s.19 file into the compiler itself. Basically, I use a cross compiler call cram.exe and output out a s.19 file which I then use Hyperterm and download into the chip's system RAM.

Page 130-134 is the example's given to write the HRM.

According to my lecturer, we don't have to use ADC or Timer Output Compare. What he want us to use is 2 interrupt functions, timer and calculation. I use 1 Timer Input Capture to capture the "heartbeat" from the function generator. The x-compiler has produced a map.map file which shows the interrupt location in the address. I have assigned the vector address for the timer() and calc() from the .map file.

Here is my code I did so far. (it's woefully simple for now, but I was hoping with your help It can work.) It's actually based on the code from Page 133 and 134 combined.

Code:
Code :
// Some further examples of setting timer unit
// No. 4 - Minimum code to count pulses ina 5 second period and display
// I.T. - 25/10/04


#include <stdio.h>
/* Heart Rate Monitor - Assignment 1 2001 I.T. 25/10/01 */
 
 
void timer(void);
void calc(void);/* Function Prototype for ISR */
 
 
unsigned char calcnow,;                                    /* GLOBAL VARIABLES FOR RETURNING VALUES*/
unsigned int data,data1,secs,ticks,mins,hours,calcn,cycle,pulse,bpm,interval,rollovers,rollovers2,rollovers1;
float freq;
 
unsigned long int result ;
 
 
 
unsigned char *padr,*paddr,*tflg2,*pactl,*tmsk2,*tflg1,*tctl2,*tmsk1;
unsigned int *tcnt,*tic1;
 
void main()
{
    int log[2][100],avrate=0,eventno=0;
unsigned char selection=0,run=1;
calcnow=0;
padr=(unsigned char*)0x0;
paddr=(unsigned char*)0x1;
tctl2=(unsigned char*)0x21;
tflg1=(unsigned char*)0x23;
tmsk2=(unsigned char*)0x24;
tflg2=(unsigned char*)0x25;
pactl=(unsigned char*)0x26;
tcnt= (unsigned int*)0x0e;
tic1= (unsigned int*)0x10;
tmsk1=( unsigned char*)0x22;
 
*paddr=0x00;                                                    /*Port A all inputs*/
*pactl=0x03;                                                    /*Set prescaler to maximum*/
*tctl2=0xaa;                                                     /* One edge capture on all TICs*/
*tflg1=0x04;                                                    /* Clear TIC1 Flag*/
*tmsk2=0x40;                                                    /*Enable RTI interrupt*/
*tflg2=0x40;
*tmsk1=0x04;
for(;;)
    {
 
 
            result=((ticks2-ticks1)-1)*65536+interval ;            //calculation to get the time between each signal
            freq=2.0e6/(float)result;
            cycle=(rollovers1-rollovers2);
 
            bpm=freq*5 ;
            printf("Interval was %u Frequency is: %5.0f Cycle:%2i bpm=%3i\n\r ",interval,freq,cycle,bpm) ;
            printf("Data:%i Data1:%i ticks1:%i ticks:%i\n\n\r",data,data1,ticks1,ticks);
            rollovers=0;
 

 
    }
}
 
 
 
 
@interrupt void timer(void)                                            // real-time timer
{
 
ticks++;
rollovers++;
if (ticks==30)
{
    ticks=0;
    secs++;
    printf("%70Time: %2i:%2i:%2i\n",hours,mins,secs);
 
 
}
 
 
 
if (secs==60)
{
    secs=0;
    mins++;
}
if (mins==60)
{
    mins=0;
    hours++;
}
if (hours==24)
{
    hours=0;
}
 
*tflg2=0x40;                                                        
}
 
@interrupt void calc(void)
{
/* Copy tic1 to data and data1 */    
 
 
        data1=data;                                //copy the new tic1 into the old tic1
        data=*tic1;                                //copy the current tic1 into data
        interval=(data-data1);                    //get interval in between
 
 
 
        rollovers2=rollovers1;                    // this one is not working, it is suppose to count the number of times the tcnt rollovers each time a signal is input, but same concept the tic1 
        rollovers1=rollovers;
 
 
 
 
 
    *tflg1=0x04;
 
}

Again, I forgot to printscreen the output so when I get the chance I'll show you.

the problem is my rollover is always the same. if rollover2=16, then rollover1 also =16. Because of that, I can't get the time cycle between 1 signal and the other.
 
Status
Not open for further replies.

Latest threads

Back
Top