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

CCP

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



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

CCP
PostPosted: Thu Aug 08, 2013 6:18 am     Reply with quote

Hi all
I have trouble to use CCP mode with the picdem with 18f87j11.
I must do something wrong but I don't see it

find a example of what I'm doing, but it don't capture anything!!!
Code:

#include <18F87J11.h>

#fuses INTRC_IO       //Osc interne
#fuses noprotect
#fuses nowdt

#use delay(internal=4000000) // inclure procédure de délais (delay_ms() et delay_us())
#use rs232( baud=2400, parity=n, xmit=PIN_C6, rcv=PIN_C7)

#include "LCD16x2.c"

//-----------------------------------------------------------------------------
// PORT A
//-----------------------------------------------------------------------------
#define BUTTON2      PIN_A5   // PIN_A5  button 2, active low input
//-----------------------------------------------------------------------------
// PORT B
//-----------------------------------------------------------------------------
#define BUTTON1      PIN_B0  // PIN_B0  button 1, active low input

//-----------------------------------------------------------------------------
// PORT D
//-----------------------------------------------------------------------------
#define LLED   PIN_D2   //

#define VAL_TRIS_D 0b11111111
//////////////////////////////////////////////////////////////////////////
//    Calcul de la fréquence du signal
//////////////////////////////////////////////////////////////////////////
int16 isr_ccp_delta1;
int16 current_ccp_delta1;
int16 frequency1;
float valueF1;

#int_ccp4
void ccp4_isr(void)
{

//////////////////////////////////////////////////////////////////////////
//   Frequence
//////////////////////////////////////////////////////////////////////////   
   int16 current_ccp1;
   static int16 old_ccp1 = 0;
   current_ccp1 = CCP_4;  //
   isr_ccp_delta1 = current_ccp1 - old_ccp1;
   old_ccp1 = current_ccp1;
}
//#############################################################################
//#
//#     PROGRAMME
//#
//#############################################################################


void calculFrequence()
{
   disable_interrupts(GLOBAL);
    current_ccp_delta1 = isr_ccp_delta1;
    enable_interrupts(GLOBAL);
   frequency1 = (int16)((1000000L + (int32)(current_ccp_delta1 >> 1))/ current_ccp_delta1);

}   
//==============================================================
// initialization
//==============================================================
void PIC_init(void)
  {
   set_tris_D(VAL_TRIS_D);
 
   setup_ccp4(CCP_CAPTURE_RE); // Capture front montant
   setup_timer_1(T1_INTERNAL);

//---- PIC init ------------------------------------------------
     setup_oscillator(OSC_4MHZ|OSC_INTRC);
   clear_interrupt(INT_CCP4);
     enable_interrupts(INT_CCP4);
    enable_interrupts(GLOBAL);
  }

//*************************************************************************************************
//  M A I N   P R O G R A M
//*************************************************************************************************

void main(void)                                                 
{
      
   //Initialisation
   PIC_init();
   lcd_init();
   

  while(true)                                                     
   {
      calculFrequence();
       valueF1 = frequency1;
      
      lcd_gotoxy(1,1);
      lcd_putc("\fF");
      lcd_gotoxy(2,1);
      printf(lcd_putc, "%3.0f", valueF1); // affichage acii valeur int16.
   
        
   }


}


thanks in advance
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 08, 2013 2:54 pm     Reply with quote

Tell us:

1. What pin on the 18F87J11 is used to receive the input signal ?

2. Describe the input signal. What is the frequency ? What type of
signal is it (digital or analog) ? Is it a sine wave, square wave,
or other rectangular waveform ? Is it a simple periodic waveform or
is it complex ? What are the low and high voltage levels ?
What are the rise and fall times of the signal ? What device is providing
the signal ? In other words, tell us everything about the input signal.

3. If you are using an 18F87J11 development board that you bought,
post the manufacturer and part number or model number of the board.
And post a link to the web page for it.

4. Have you already tested the PIC and the board with a simple program
to prove that the LCD works ? Have you tested the board with an LED
blinking program to prove that the PIC is running at 4 MHz ?

5. What is the Vdd voltage of the PIC ?

6. What is your CCS compiler version ?

7. You said "it don't capture anything". Tell us what you see displayed
on the LCD. Is it nothing ? Or is it 0 Hz ? Tell us.
in_nursery



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

PostPosted: Thu Aug 08, 2013 3:08 pm     Reply with quote

1. What pin on the 18F87J11 is used to receive the input signal ?
pin RG3 => ccp4

2. Describe the input signal. What is the frequency ? What type of
signal is it (digital or analog) ? Is it a sine wave, square wave,
or other rectangular waveform ? Is it a simple periodic waveform or
is it complex ? What are the low and high voltage levels ?
What are the rise and fall times of the signal ? What device is providing
the signal ? In other words, tell us everything about the input signal.

It's 0-3V square wave signal.

3. If you are using an 18F87J11 development board that you bought,
post the manufacturer and part number or model number of the board.
And post a link to the web page for it.

yes it,s from microchip PICDEM PIC18
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en535770
with PIM 18F87J11

4. Have you already tested the PIC and the board with a simple program
to prove that the LCD works ? Have you tested the board with an LED
blinking program to prove that the PIC is running at 4 MHz ?

yes everything else is working fine it's the capture mode that don't work.

5. What is the Vdd voltage of the PIC ?
3.3V

6. What is your CCS compiler version ?

4.134

7. You said "it don't capture anything". Tell us what you see displayed
on the LCD. Is it nothing ? Or is it 0 Hz ? Tell us.

it shows 0Hz

the program is running it only the capture value who is always 0.

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 08, 2013 3:20 pm     Reply with quote

Quote:
It's 0-3V square wave signal.

Right, but what is the frequency of the input signal ? And what device
is providing the signal ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 2:41 am     Reply with quote

What compiler version?.

Try adding:

SETUP_PMP(PMP_DISABLED);

In your initialisation code.

It _should_ be disabled by default, but always when things don't work, start by making sure everything else on the pin that could conflict is turned off.

I'd suggest setting a flag in the interrupt to say it has been called, and only printing when this has happened. Otherwise you are repeatedly printing the same unchanged value.

Best Wishes
in_nursery



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 5:37 am     Reply with quote

Quote:
Right, but what is the frequency of the input signal ? And what device
is providing the signal ?


Frequency 80 Hz with a function generator
in_nursery



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 6:12 am     Reply with quote

Quote:
SETUP_PMP(PMP_DISABLED);

In your initialisation code.

It _should_ be disabled by default, but always when things don't work, start by making sure everything else on the pin that could conflict is turned off.

It's done

Quote:

I'd suggest setting a flag in the interrupt to say it has been called, and only printing when this has happened. Otherwise you are repeatedly printing the same unchanged value.

Code:

#int_ccp4
void ccp4_isr(void)
{
   int16 current_ccp1;
   static int16 old_ccp1 = 0;
   current_ccp1 = CCP_4;  //
   isr_ccp_delta1 = current_ccp1 - old_ccp1;
   old_ccp1 = current_ccp1;
   Flag_CCP=1;
}

Add Flag_CCP

Code:
while(true)                                                     
   {
      If(Flag_CCp==1){
      calculFrequence();
       valueF1 = frequency1;
      
      lcd_gotoxy(1,1);
      lcd_putc("\fF");
      lcd_gotoxy(2,1);
      printf(lcd_putc, "%3.0f", valueF1); // affichage acii valeur int16.
      delay_ms(500);
      Flag_ccp=0;
      } else {
      lcd_gotoxy(1,1);
      lcd_putc("\fNo CCP");
      delay_ms(500);
      }
        
   }

Always show No CCP never capture any value Evil or Very Mad
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 7:55 am     Reply with quote

Have you actually verified the signal is arriving at the pin on the processor?.
The signal source is grounded to the board?.
in_nursery



Joined: 25 Oct 2012
Posts: 51

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 8:45 am     Reply with quote

Ttelmah wrote:
Have you actually verified the signal is arriving at the pin on the processor?.
The signal source is grounded to the board?.


yes to the 2 questions

I really don't know whats happened
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