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.

7-segment with ECG

Status
Not open for further replies.
ok then why we do not then try the rest in the post #14 means we follow the post #19

at that time we will have the circuit, and the PIC connected to section B

at this stage we are able to fix the circuit and program the PIC

so any problem we had ??? i am sorry if i keep asking


thanx
 
ok then why we do not then try the rest in the post #14 means we follow the post #19

I'm sorry but I don't understand this question.


at that time we will have the circuit, and the PIC connected to section B

But which pin on the PIC will you connect to section B? Which pins will connect to the 7 segment displays? etc? I can make the C-code you have work with MPLab but then you have to build a circuit to work with the program. The circuit in post#14 will not work with the program you provided. The program if for a different circuit. Do you have this circuit or can create it?

I will make the modifications necessary for the code to compile in MPLab, but you will need a circuit different than the one is post#14 for it to work.
 
ok thanx for the help and advice but i want to know is it the source code capable to calculate the heart beat ??? surely after figure out the circuit that can work with it

Regard's
 
Yes, the code is capable of doing what you need. Afterwards, you'll have to build a circuit that works with the code, (not the circuit in post #14). I am working to modify the code now.
 
the PIC i am willing to use is one of theses three ( pic16f84a,pic16f876,pic16f690) but still confusing which one is better to work with my application, as much as it can be function well i am k with it.

Do you have to use one of these three PICs (pic16f84a,pic16f876,pic16f690)? It would be easier for both of us if you use any 18 series PIC so we can use the Microchip C18 compiler. Otherwise, we'll have to use a 3rd party compiler. If you want, I can recommend a suitable 18 series PIC.
 
Last edited:
the problem sir is i didn't use at all 18f and most of my work was 16f, that's why i do not have time to go through the 18f now, even i do not know how to compile any source code, but if you have any guide i will try and we can work together to make it function well, but i hope can do these things using 16f.......can you please tell me what do you mean by 3rd party compiler, i already had MPLAB IDE V8.43 and its work nicely???

thanx for all the help yo are providing i really appreciated
 
the problem sir is i didn't use at all 18f and most of my work was 16f, that's why i do not have time to go through the 18f now, even i do not know how to compile any source code, but if you have any guide i will try and we can work together to make it function well, but i hope can do these things using 16f.......can you please tell me what do you mean by 3rd party compiler, i already had MPLAB IDE V8.43 and its work nicely???

thanx for all the help yo are providing i really appreciated


Programming and using the 18F PICs is almost exactly the same as the 16F PICs. If you know how to use 16F, then you can use 18F.

By 3rd party compiler I mean a compiler that is made by a different company other than Microchip. Microchip has a free C compiler for 18F PICs but not for 16F. For 16F we need to use a compiler from a different company which will have restrictions.

What compiler are you using with MPLAB IDE V8.43 right now?
 
i can burn the source code in the PIC using PICKIT 2, and i can compile the source code using the MPLAB using HI-TECH C which is also free and i am using it normally.

compile as far as i know means the software that will convert to HEX file, so the PC and the PIC will understand it as (0) and (1)........

i work with the PIC before and i am using MPLAB and PICKIT2,no other software....

and i still hope we can go through the 16f plzzzz

thanx
 
Last edited:
i can burn the source code in the PIC using PICKIT 2, and i can compile the source code using the MPLAB using HI-TECH C which is also free and i am using it normally.

OK, now that I know which C compiler you are using, I can make sure I use the same one.

compile as far as i know means the software that will convert to HEX file, so the PC and the PIC will understand it as (0) and (1)........

Correct!

and i still hope we can go through the 16f plzzzz

OK, I will modify the code for use with the HI-TECH C compiler and a 16F PIC.
 
OK, I modified the code. It compiles with the HI-TECH C compiler. I used the PIC 16F876 in the project. Of course I didn't test anything because I didn't want to have to build the circuit. It should be equivalent to the C code you posted so if that code worked, this should too. If you PM me your email adress, I'll send you the MPLab project files. Here is the modified code:

Code:
#include<htc.h>

#define _XTAL_FREQ 4000000

char beat_rate=0,med,time=0;
char num[10]={126,12,182,158,204,218,250,14,254,222};

static void interrupt
intrpt(void){

if(INTF==1){
	beat_rate++;
	INTF=0;
}

if(T0IF==1){
	time++;
	if(time==60){
     time=0;T0CS=1;INTCON=0;
   }
}

}//end interrupt

void show()
{
     med=beat_rate/100;
     PORTB=num[med];
     RA2=0;__delay_ms(10);
     RA2=1;

     med=(beat_rate%100)/10;
     PORTB=num[med];
     RA1=0;__delay_ms(10);
     RA1=1;

     med=beat_rate%10;
     PORTB=num[med];
     RA0=0;__delay_ms(10);
     RA0=1;
}

void main ( ){

TRISA=0b11111000;
TRISB=0b00000001;
PORTA=0b00000111;
TMR0=0;
OPTION=0b11100100;
INTCON=0;

//main program loop
while(1){

start:

    while(RA3==1){
      show();
    }

    beat_rate=0;
    T0CS=0;
    INTCON=0b10110000;

    while(T0IE==1){
      show();
    }

    INTCON=0;

    while(beat_rate!=0){
      show();
      if(RA3==0){
		__delay_ms(125);
		__delay_ms(125);
		TMR0=0; 
		beat_rate=0;
		goto start;
	  }
    }

}//END while (1)

}//End main

//___________END_PROGRAM___________
 
Last edited:
Thanx in all the help sir, but plzzz can we try together to find the circuit that can fit my PIC, and how do you know its can not been function well.....??
by the way the program i did not understand it fully hope if you do not mind can support me to understand....

thanx
 
I didn't pay much attention to how the program works. All I did was modify the syntax so it would compile with the compiler you are using. I can go through the code and comment the different statements to help you understand the flow. Where did you find the source code you supplied? What PIC was it written for?
 
thanx for your reply
i used the same PIC in post #14 coz it was my first idea, i got the source code from the same website the french one

hope you can help me to understand the program, and what is the best circuit i must use while sure i must test it 1st then can confirm more about it....

thanx
 
I don't need to know what PIC you decided to use, I need to know the PIC that the program "beat_rate.c" was written for. I went to the translated page of the website you linked. I didn't see beat_rate.c. I only saw .asm and .hex files. beat_rate.c will not work with the circuit in post#14. To help you understand how the program works and to help you design a circuit for it, I need to know what PIC the program was written for.
 
no, i email the guy who did this circuit in post#14 and i send my circuit in post #17 and i asked him to help me with the c-language and after 1 day, the source code was in my email, but he never mentions about his source code will work or not so he asked me to test it 1st then reply him back if its function or not,the PIC i asked him to use was PIC16F84A, and he said the program will calculate each 1minut after that you have to press a button then will start calculating again which is connected to RA3 , while RA0 will connected to the section B in the circuit #14( which u already inform me it will not work)and he asked me about the final circuit i will use which is already posted in #19, then he said k it will work......

so what your advice to me...??

Regad's
 
OK, this makes much more sense now. I couldn't figure out why the main loop was checking on the state of RA3 but now that you told me there is a button connected to it, I understand. Notice that there is no button connected to RA3 in the circuit from post #14. That is a good initial indication that the source code you were emailed, was not written to work with the circuit in post #14. Another way I knew the source code wouldn't work was because of the show() function. The show() function drives each 7 segment directly from PORTB and multiplexes the 3 digits. The circuit from post#14 is designed for a porgram that will simultaneosy output each digit as a BCD value to be fed into the 74LS47 BCD to 7 segment decoder ICs. The 74LS47 ICs then drive the 7 segment displays, not the PIC.

The circuit you show in post#19 should work but the output that you refer to as section B will feed into RB0 of the PIC, not RA0.

I still don't understand all parts of the program. From what I think I understand so far, it looks like the PIC displays the total number of heart beats and not the heart rate. I'll have to spend a little more time looking it over before I can offer advice.
 
Last edited:
ok, here is more details
the PIC will calculate the heart beat and keep waiting until 1min finish then it will show the average of the total. As far as i know its will calculate HOW MANY BEATS PER SECOND, means will find out the total beat then divided by 60sec. the crystal used is 32768HZ to make the calculation faster.after 1min if there are no output so the result will stay 0,and the result will keep appear in the 7-segment until i press the button again.

the functions of this array as what he said it will replace anther circuit so insted of we have more circuits we can add this array only and its used to display the numbers from 0-9.
char num[10]={126,12,182,158,204,218,250,14,254,222}

i send an email to him and i told him his source code its not working, so he keep asking me did u tested in real ?? coz he was waiting for me to confirm him he said i think that there is something wrong with it.

thats all i know about it, plzzzz take your time to have a look


thanx
 
the PIC will calculate the heart beat and keep waiting until 1min finish then it will show the average of the total. As far as i know its will calculate HOW MANY BEATS PER SECOND, means will find out the total beat then divided by 60sec.

I'm not sure about this. I don't see where the number of heart beats gets divided by 60. From what I can tell it displays the number of heart beats it has counted over a minute and not the beats per second.

the functions of this array as what he said it will replace anther circuit so insted of we have more circuits we can add this array only and its used to display the numbers from 0-9.
char num[10]={126,12,182,158,204,218,250,14,254,222}

The function of this array is to output the different digits to the 7 segment display. This method makes the 74LS47 ICs shown in the circuit from post#14 unnecessary. I understand this part of the program and it is one of the ways I knew that the program was not written for the circuit in post#14.


i send an email to him and i told him his source code its not working, so he keep asking me did u tested in real ?? coz he was waiting for me to confirm him he said i think that there is something wrong with it.

The only thing I know for sure right now is that the source code will not work with the circuit in post#14. The source code may work just fine with a different circuit. I will post a circuit soon that I think the program was written for. The circuit I post will be consistent with the program but I'm still not sure if the program will work based on how the interrupts are used.

Here is the code that I commented so far. I'm still working on it but this should get you started trying to understand what is going on.

Code:
#include<htc.h>					

#define _XTAL_FREQ 32768		//Specifies oscillator frequency of 32.768 Khz

char beat_rate=0,med,time=0;	//Variable declaration and intialization

//This array defines the decimal equivalents for setting the output pins in driving the 7 segment displays.
char num[10]={126,				//0
			  12,				//1
			  182,				//2
			  158,				//3
			  204,				//4
			  218,				//5
			  250,				//6
			  14,				//7
			  254,				//8
			  222				//9
			  };

//This function is called every time an interrupt occurs
void interrupt intrpt(void){	
	
if(INTF==1){					//This is true if the interrupt was caused by a rising edge on RB0
	beat_rate++;				//Increment the pulse count
	INTF=0;						//Reset the external interrupt flag
}//end if(INTF==1)

if(T0IF==1){					//This is true if the interrupt was caused by a TMR0 overflow
	time++;						//Increment the interrupt counter
	if(time==60){				//This is true every 60th TMR0 overflow (once per minute)
     time=0;					//Reset interrupt counter
     T0CS=1;					//Sets the T0CKI as the external clock source for TMR0
     INTCON=0;	 				//Disables all interrupts
   }//end if(time==60)
}//end if(T0IF==1)

}//end intrpt()

//This function is called to drive the 7 segment displays
void show(){
	
     med=beat_rate/100;			//calculates the 100's digit
     PORTB=num[med];			//Assigns result to PORTB
     RA2=0;__delay_ms(10);		//Enable digit 3; delay long enough for digit to be seen
     RA2=1;						//Disable digit 3

     med=(beat_rate%100)/10;	//Calculates the 10's digit
     PORTB=num[med];			//Assigns result to PORTB
     RA1=0;__delay_ms(10);		//Enable digit 2; delay long enough for digit to be seen
     RA1=1;						//Disable digit 2
    
     med=beat_rate%10;			//Calulcates the 1's digit
     PORTB=num[med];			//Assigns result to PORTB
     RA0=0;__delay_ms(10);		//Enable digit 1; delay long enough for digit to be seen
     RA0=1;						//Disable digit 1

}//end show()

void main ( ){

TRISA=0b11111000;				//Set bits 0-2 as output and bits 3-7 as input
TRISB=0b00000001;				//Set bit 0 and input and bits 1-7 as output
PORTA=0b00000111;				//Sets bits 0-2 and clears bits 3-7
TMR0=0;							//Clears the TMR0 register
OPTION=0b11100100;				//Sets TMR0 options and pre-scaler				
INTCON=0;						//Clears the INTCON register

//main program loop
while(1){

start:

    while(RA3==1){				//If pushbutton is pressed
      show();
    }

    beat_rate=0;
    T0CS=0;						//Set the internal instruction clock as the clock source for TMR0
    INTCON=0b10110000;			//Globally enables interrupts, TMR0 interrupt, and RB0 external interrupt

    while(T0IE==1){				//If TMR0 interrupt is enabled
      show();					
    }

    INTCON=0;					//Disables all interrupts

    while(beat_rate!=0){
      show();
      if(RA3==0){				//If pushbutton is not pressed
		__delay_ms(125);		//Delays for 125 ms
		__delay_ms(125);		//Delays for 125 ms
		TMR0=0; 				//Clears the TMR0 register
		beat_rate=0;
		goto start;
	  }
    }

}//END while (1)

}//End main

//___________END_PROGRAM___________
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top