|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 05, 2015 1:15 pm |
|
|
Before we look at your code, describe the pulse. Post the voltage levels,
rise time, shape, positive or negative-going, pulse duration, and repetition rate.
Also describe the connections between your pulse generator and the PIC.
Post the Vdd voltage of your PIC.
And post your CCS compiler version. |
|
|
Aragon
Joined: 19 Mar 2014 Posts: 20
|
|
Posted: Thu Mar 05, 2015 3:56 pm |
|
|
-The Pulse is a square wave (High = 2.643mS & Low = 7.033mS). duration = 9.676ms
-its a positive raising edge, I am getting a 5VD going in the CCp1 and CCP2, Instead of the pulse signal. The signal generator is controlled by the RB0 pin on the PIC18 to output the signal. The signal is there for the first 3 seconds and then turns off. RB0 is 0.5vdc instead of being 5 vdc.
-The pulse generator is on the same circuit board as PIC18F2620. The Pulse generator is PIC12F675. The output pulse from the PIC12 goes to CCP1 on the PIC18.
-the VDD voltage of the PIC is 4.91V
-The CCS Compiler is V8.70 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 05, 2015 6:16 pm |
|
|
Your program doesn't work because you took a bunch of code from
various programs and dumped it all into one program without thinking
about how the CCP works in capture mode. I've written a program
that shows how to do it. I hope you can understand it.
Using a test setup similar to yours, with a 2nd PIC board providing the
test signal, I get the following output on TeraTerm from the CCP capture
board. The pulse duration is a little low, probably because the internal
oscillator is used on the capture board, and it's not precisely 4.000 MHz.
Quote: |
2.633 ms
2.633 ms
2.633 ms
2.632 ms
2.632 ms
2.632 ms
2.633 ms
2.633 ms
2.632 ms
|
Test program:
Code: |
#include <18F4520.h>
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
int8 capture_rising_edge;
int8 got_pulse_width;
int16 ccp_delta;
#int_ccp1
void ccp1_isr(void)
{
static int16 t1_rising_edge;
// If current interrupt is for rising edge.
if(capture_rising_edge)
{
setup_ccp1(CCP_CAPTURE_FE);
capture_rising_edge = FALSE;
t1_rising_edge = CCP_1;
}
else
{
setup_ccp1(CCP_CAPTURE_RE);
capture_rising_edge = TRUE;
ccp_delta = CCP_1 - t1_rising_edge;
got_pulse_width = TRUE;
}
}
//====================================
void main()
{
float pulse_width_ms;
int16 local_ccp_delta;
got_pulse_width = FALSE;
capture_rising_edge = TRUE;
setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
set_timer1(0);
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);
while(TRUE)
{
// Check if we captured the pulse width.
// If so, display the pulse duration.
if(got_pulse_width)
{
disable_interrupts(GLOBAL);
local_ccp_delta = ccp_delta;
enable_interrupts(GLOBAL);
pulse_width_ms = local_ccp_delta / 1000.0;
printf("%7.3f ms \n\r", pulse_width_ms);
got_pulse_width = FALSE;
}
delay_ms(500); // Slow down update rate on TeraTerm
}
} |
Notice how short this program is, compared to your program. More code
does not equal success. A short program that is completely understood,
equals success. |
|
|
|
|
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
|