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 support@ccsinfo.com

how may i use CCP (pic 16f877) to get width wave?

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



Joined: 14 Jun 2011
Posts: 5

View user's profile Send private message

how may i use CCP (pic 16f877) to get width wave?
PostPosted: Tue Jun 14, 2011 6:19 pm     Reply with quote

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. Wink

thanks so much, and sorry for my english Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 15, 2011 1:15 pm     Reply with quote

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

View user's profile Send private message

what time?
PostPosted: Wed Jun 15, 2011 4:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 15, 2011 7:22 pm     Reply with quote

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 ;) Laughing
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 15, 2011 7:29 pm     Reply with quote

Quote:
since i gonna work by ultrasound,

You are not using radar at all. You're probably using the Parallax Ping
or something similar of your own design:
http://www.parallax.com/tabid/768/ProductID/92/Default.aspx

Here are some previous threads about how to do this with CCS:
http://www.ccsinfo.com/forum/viewtopic.php?t=44985
http://www.ccsinfo.com/forum/viewtopic.php?t=23425
yixzon



Joined: 14 Jun 2011
Posts: 5

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 10:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 16, 2011 1:30 pm     Reply with quote

There are many examples of measuring a pulse with the CCP on the
forum. Here's one. Try using existing working code, instead of inventing
your own code.
http://www.ccsinfo.com/forum/viewtopic.php?t=45616&start=9
yixzon



Joined: 14 Jun 2011
Posts: 5

View user's profile Send private message

PostPosted: Fri Jun 17, 2011 10:18 am     Reply with quote

: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

View user's profile Send private message

PostPosted: Fri Jun 17, 2011 12:39 pm     Reply with quote

Quote:
I don´t understand some code lines

What specific lines ?
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