Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to measure interval time between two pulses!! I have MikroC code.

Status
Not open for further replies.

ennng

Junior Member level 2
Joined
Nov 1, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
I used sine wave with 3Hz, inserted to ADC and detect the maximum values. According to these max values I generated pulse sequences and I would like to measure the time between two pulses with the same pic not use anther one. I used pic16f877a.
pulses.jpg

Code:
int maximum=0;
void main()
{trisa=1;trisb=0;portb=0;
while(1)
         {
          while(adc_read(0)> maximum) maximum = adc_read(0);
          portb.f0=1;
          delay_ms(1);
          portb.f0=0;
          while(adc_read(0)< maximum && adc_read(0)>=0){}
          maximum=0;

         }

}
 

Configure ADCON0 and ADCON1 registers first.

Thank you for your reply, I used the ready library for ADC.
Why you want to use them !! is related to sampling or what?
could you please explain a bit. Thank you again.
 

I generated pulse sequences and I would like to measure the time between two pulses with the same pic not use anther one
You can fire a timer after delay_ms(1); and before you call that delay again, you can check the timer counter's value and according to the clock of the MCU, prescaler etc you can use the equations that hopefully provided in PIC's datasheet and calculate the value in ms.
 

Its used to configure adc, ie to select channels etc..
http://www.winpicprog.co.uk/pic_tutorial11.htm
This tutorial might help you.


Thank you for the nice link. Basically, the code in the first post use for ADC and detect the maximum values also generate pulse wave form. look at the picture in the first post. so
what I want is that how to measure the time between two wave form or between two peaks.

- - - Updated - - -

You can fire a timer after delay_ms(1); and before you call that delay again, you can check the timer counter's value and according to the clock of the MCU, prescaler etc you can use the equations that hopefully provided in PIC's datasheet and calculate the value in ms.


Hi alexxx; thank you for the interesting idea,

do you mean start timer after the delay_ms(1) and stop the timer before this delay and see timer counter's value. like the code.

Code:
int maximum=0;
void main()
{trisa=1;trisb=0;portb=0;
while(1)
         {
          while(adc_read(0)> maximum) maximum = adc_read(0);
          portb.f0=1;
           
          Stop Timer

          delay_ms(1);

          Start Timer

          portb.f0=0;
          while(adc_read(0)< maximum && adc_read(0)>=0){}
          maximum=0;

         }

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top