View previous topic :: View next topic |
Author |
Message |
yixzon
Joined: 14 Jun 2011 Posts: 5
|
how may i use CCP (pic 16f877) to get width wave? |
Posted: Tue Jun 14, 2011 6:19 pm |
|
|
Hi, I'm doing a radar project, and i need to get the wave frequency so first i should get the width wave, I've reading some examples and forums about CCP applications, but I didn't find out any good answer. I wanna understand as a principal thing how works CCP capture with timer1. If someone has a example for me please, or just a guide to take ideas from it. In fact all the project is about, how to build a radar. I'll appreciate all information.
thanks so much, and sorry for my english |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 15, 2011 1:15 pm |
|
|
Quote: | I'm doing a radar project, and i need to get the wave frequency |
Radar frequencies are normally much higher than the PIC can directly
measure with the CCP.
What is the expected frequency that you want to measure ? |
|
|
armondo58
Joined: 15 Jun 2011 Posts: 16
|
what time? |
Posted: Wed Jun 15, 2011 4:16 pm |
|
|
I assume you mean the time from transmission of pulse to return..Radar typically run at 3+ ghz. way to high for pic |
|
|
yixzon
Joined: 14 Jun 2011 Posts: 5
|
|
Posted: Wed Jun 15, 2011 7:22 pm |
|
|
Thanks for the answers, well, about the frequency i expect measure 20khz since i gonna work by ultrasound, but i want first the width wave to use it in a equation to finally get the time wave (period).
Before i start to build the project, i just want to do a simulation where i can plug in a RZ signal 0V-5V, then capture the width wave and show it on a LCD, every time i push a button, there is the problem how may i do to take this information from ccp1 without use both CCP (ccp1 and ccp2).
THANKS ;) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
yixzon
Joined: 14 Jun 2011 Posts: 5
|
|
Posted: Thu Jun 16, 2011 10:17 am |
|
|
Thanks PCM for the links, its aid me alot! I made this code but isn´t work on Proteus :(, I don't know what is the problem, i guess i could be the plug in signal which are in ccp_1 and ccp_2, please any suggestion will be great thanks!!
Code: |
#include<16f877.h>
#device adc=8
#use delay(clock=4000000)
#byte PORT_A=0x05
#byte PORT_B=0x06
#byte PORT_C=0x07
#byte PORT_D=0x08
#include <LCD.C>
#include <math.h>
int valor,O,C,D,U;
float Subida , Bajada, widthpulse;
#int_ccp1
captura()
{
Subida=CCP_1; //Take high value
Bajada=CCP_2; //Take low value
widthpulse= Bajada - Subida; //width pulse
valor=ceil(widthpulse); //Aprox
O= valor/1000;
C= (valor%1000)/100;
D= ((valor%1000)%100)/10;
U= ((valor%1000)%100)%10;
lcd_send_byte(0,0x84);
lcd_putc("Ancho de Pulso=");
lcd_putc(O+48);
lcd_putc(C+48);
lcd_putc(D+48);
lcd_putc(U+48);
}
void main ()
{
set_tris_C (0b11111111); // Configuration CCP1 c
set_tris_D (0b00000000); // Configuration LCD
setup_ccp1(CCP_CAPTURE_RE); // Configuration CCP1
setup_ccp2(CCP_CAPTURE_FE); // Configuration CCP2
setup_timer_1(T1_INTERNAL); // configuracton timer 1
enable_interrupts(global);
enable_interrupts(INT_CCP1);
lcd_init(); // Ini LCd
lcd_send_byte(0,0x84);
lcd_putc("hola");
delay_ms(500); |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
yixzon
Joined: 14 Jun 2011 Posts: 5
|
|
Posted: Fri Jun 17, 2011 10:18 am |
|
|
:o, You already made a code to measure the width wave. Ok i can use that code but i need you to explain me the code, i should understand before i use it.
I don´t understand some code lines, can you explain me the program?:
THANKS SO MUCH PCM!
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C2, INVERT)
int8 capture_rising_edge;
int8 got_pulse_width;
int16 ccp_delta;
#int_ccp1
void ccp1_isr(void)
{
static int16 t1_rising_edge; [b]
// 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;
}
}
//==================================
main()
{
int16 pulse_width_ms, local_ccp_delta;
got_pulse_width = FALSE;
capture_rising_edge = TRUE;
output_low(pin_C0);
setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8 );
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);
while(1)
{
output_high(pin_C0);
delay_ms(100);
output_low(pin_C0);
if(got_pulse_width)
{
disable_interrupts(GLOBAL);
local_ccp_delta = ccp_delta;
enable_interrupts(GLOBAL);
pulse_width_ms = local_ccp_delta / (125);
printf("%lu\n\r", pulse_width_ms);
got_pulse_width = FALSE;
}
delay_ms(500);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2011 12:39 pm |
|
|
Quote: | I don´t understand some code lines
|
What specific lines ? |
|
|
|