Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

duration of time between two front C code

Status
Not open for further replies.

MARWEN007

Junior Member level 2
Joined
Apr 16, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,481
Hey everyone, well I would calculate the time in seconds between my rising input signal is a square wave frequency of 50 Hz and amplitude 5V I found a good sample code in the index of peak I c compile knows not that solve my problem or is nn 't there any constraints or variables to modify the code if you like it give me your idea and your comment and your advice because I want the similer on isis and display whenever the time between the two fronts here's my code as you isis diagram on the board pinout please





#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>


long rise,fall,pulse_width;

#int_ccp2
void isr()
{
rise = CCP_1;
fall = CCP_2;



pulse_width = fall - rise; // CCP_1 is the time the pulse went high
} // CCP_2 is the time the pulse went low
// pulse_width/(clock/4) is the time

// In order for this to work the ISR
// overhead must be less than the
// low time. For this program the
// overhead is 45 instructions. The
// low time must then be at least
// 9 us.

void main()
{
printf("\n\rHigh time (sampled every second):\n\r");
setup_ccp1(CCP_CAPTURE_RE); // Configure CCP1 to capture rise
setup_ccp2(CCP_CAPTURE_FE); // Configure CCP2 to capture fall
setup_timer_1(T1_INTERNAL); // Start timer 1

enable_interrupts(INT_CCP2); // Setup interrupt on falling edge
enable_interrupts(GLOBAL);

while(TRUE) {
delay_ms(10);


printf("\r%lu us ", pulse_width/5 );
}
}
 

grieblm

Member level 4
Joined
May 7, 2011
Messages
75
Helped
18
Reputation
36
Reaction score
18
Trophy points
1,308
Location
Georgetown, Canada
Activity points
1,734
To capture the time between two rising edges you only need one CCP (enable interrupts on CCP1):

1) Set the interrupt to occur on each rising edge.
2) On the first rising edge record the CCP_1 value into 'rise' variable.
3) On each subsequent interrupt: calculate the period as CCP_1 - rise; store the current CCP_1 value in 'rise'.
4) Repeat (3) as necessary.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top