Jump to content
Sign in to follow this  
Prefekt

Frequency Meassuring

Recommended Posts

Hi,

I want to meassuring the high pulse of an frequency. The high puls could be between 0,5 and 2ms and I need the excacly worth of the high pulse time. Has anybody an Idea how to meassure frequency and/or the hight pulse time?

 

thanks

 

Volker

Share this post


Link to post
Share on other sites
Hi,

I want to meassuring the high pulse of an frequency. The high puls could be between 0,5 and 2ms and I need the excacly worth of the high pulse time. Has anybody an Idea how to meassure frequency and/or the hight pulse time?

 

thanks

 

Volker

 

if you,ve measured the time, you can derived the frequency from it. In my module that measure heart rate, i used timer0 of PIC16f877a. what is your target microcontroller anyway?

Share this post


Link to post
Share on other sites
Hi,

I use the PIC12F675 or PIC 12F629 for this. Do you have an sample code with the timer?

 

regards,

Volker

 

well i can't give you my exact code in my heart module but here is a simple algorithm that i develop.

 

void interrupt(){
if(tmr0 interrupt occured)
{
	counter++;
	if(counter==49){   //already 0.05 second
		realtime++;
		counter = 0;
	}
	clear interrupts of timer0;
}
}

void main()
{
/*
	put the initializing stuff
	here for ADC and timer0
*/

while(1){
	ADC() //do the ADC here

	/*	do the parameter comparison here	*/
	if(if the signal digitized is null)
		goto ADC again;

	if(first pulse is detected){
		start timer0;
		goto ADC again;
	}

	if(second pulse is detected){
		end timer0;
	}

}
}

 

my clock is 4Mhz, WDT is off. im using internal clock for timer0 clk with prescalar of 1:4. it was said in my datasheet that an execution of an instruction is 4/Fosc. therefore 4/4Mhz is 1us. it means that an increment in timer0 is 1us. since timer0 is an 8 bit register, when an interrupt has occured there were 256us*4. i multiply 4 because of the prescalar. to make it short here is the equation:

 

Y = A*X*Z

where:

Y - desired time

A - 4/Fosc*2^n (n is number of bits of the timer)

X - prescalar reciprocal

Z - integer of a corresponding time

 

looking from the algo, i got the integer 49 from this equation that corresponds to 0.05 seconds rounded up. the calculation of real time and frequency is up to you. take note that if your timer requires postscalar, just set it to 1:1 in order to use this kind of approach. i hope this helps you.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...