CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Measure pulse with pic16f877

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kristian
Guest







Measure pulse with pic16f877
PostPosted: Mon Apr 07, 2003 7:02 pm     Reply with quote

I've got an analogue signal that I convert to a 10 bit Digital signal. From this signal I have to find the maximum signals so I can find the Bpm. I already have found the Max and min as u can see from the code below. But I need to find the time betveen each max signal. Does this require a exsternal clock?
How can I solve this , does anyone know?

Been working on this problem way to long!

Please help me!


for(i=0;i<=500;i++)
{
SET_ADC_CHANNEL(0);
output_high(PIN_C0);

delay_us(2000);
value = Read_ADC();

if(value < minir)
minir=value;
if(value > maxir)
maxir=value;
output_low(PIN_C0);

SET_ADC_CHANNEL(1);
output_high(PIN_C1);

delay_us(2000);

value = Read_ADC();

if(value < minr)
minr=value;
if(value > maxr)
maxr=value;

output_low(PIN_C1);


}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13475
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: Measure pulse with pic16f877
PostPosted: Mon Apr 07, 2003 8:41 pm     Reply with quote

:=I've got an analogue signal that I convert to a 10 bit Digital signal. From this signal I have to find the maximum signals so I can find the Bpm. I already have found the Max and min as u can see from the code below. But I need to find the time betveen each max signal. Does this require a exsternal clock?
:=How can I solve this , does anyone know?
:=
:=Been working on this problem way to long!
:=
:=Please help me!
:=
:=

Here's one approach to the problem:
I think you would be better off using a system tick (generate with timer overflow interrupt) rather than use delay_us(2000).
In the overflow isr a software counter could be incremented, then when the maximum occurs the current count taken and saved, and time between successive maximums calculated.
Regards
Kenny




:= for(i=0;i<=500;i++)
:= {
:= SET_ADC_CHANNEL(0);
:= output_high(PIN_C0);
:=
:= delay_us(2000);
:= value = Read_ADC();
:=
:= if(value < minir)
:= minir=value;
:= if(value > maxir)
:= maxir=value;
:= output_low(PIN_C0);
:=
:= SET_ADC_CHANNEL(1);
:= output_high(PIN_C1);
:=
:= delay_us(2000);
:=
:= value = Read_ADC();
:=
:= if(value < minr)
:= minr=value;
:= if(value > maxr)
:= maxr=value;
:=
:= output_low(PIN_C1);
:=
:=
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 13476
Kristian
Guest







Re: Thank you but.....
PostPosted: Mon Apr 07, 2003 9:52 pm     Reply with quote

This sounds just like what I need. Nut how do I do it, I've read about it now, but I still don't know how to write the code. Is there any possibility that you can help me?
Thank you so much!
___________________________
This message was ported from CCS's old forum
Original Post ID: 13479
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: Thank you but.....
PostPosted: Mon Apr 07, 2003 10:30 pm     Reply with quote

:=This sounds just like what I need. Nut how do I do it, I've read about it now, but I still don't know how to write the code. Is there any possibility that you can help me?
:=Thank you so much!

I don't have code for you, only the approach that I would try.
You need to be familiar with interrupt programming, setting flags, etc.

Here's how to setup a 1ms tick to get you started:

// The cycle time will be (1/clock)*4*t2div*(period+1)
// In this program clock=16,000,000 and period=249
// (1/16000000)*4*16*250=1000 us or 1kHz)

setup_timer_2(T2_DIV_BY_16,249,1);

// Timer2 overflow interrupt service routine
// Interrupts occur every millisecond.

#int_timer2
timer2_isr() {
//Increment software counter, set flag for main(), etc
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13480
Sherpa Doug
Guest







Re: Measure pulse with pic16f877
PostPosted: Tue Apr 08, 2003 2:39 pm     Reply with quote

:=I've got an analogue signal that I convert to a 10 bit Digital signal. From this signal I have to find the maximum signals so I can find the Bpm. I already have found the Max and min as u can see from the code below. But I need to find the time betveen each max signal. Does this require a exsternal clock?
:=How can I solve this , does anyone know?
:=
:=Been working on this problem way to long!
:=
:=Please help me!

If you want to accurately measure the period of your input and it is anywhere close to a sinusoid you are better off using zero crossings than maximums. In the presence of noise maximums are very fuzzy while zero crossings are much more precise.
To measure period set up a timer to run as long as your longest measurement. Wait for a + to - zero crossing and set the timer to zero. Wait some small dead time to block noise. On the next + to - zero crossing read the timer to get period in counts. Repeat the measurement a few times to get an average. Do a little math to turn this period into Bpm.

___________________________
This message was ported from CCS's old forum
Original Post ID: 13512
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group