• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877a Capture mode not working

Status
Not open for further replies.

kirangowle

New Member
Hello all,

I am new to this forum.
I have a requirement where i need to read the specific pattern of pulse.
Please refer the attached screenshot contains the specific pattern of data s inform Pulse.

Googling i found that i need to use Capture mode to read the pulse width and compare against the duration of it.

To start off with, First i am trying to capture the interrupt. but unfortunately its not working.

My code looks like below
void interrupt ISR()
{
/*if(TMR1IF)
{
TMR1IF = 0;
RD2 ^=1;
}*/
if(CCP1IF)
{
CCP1IF = 0;
RD2 ^=1;
}
}
// Main Function
void main(void)
{
unsigned char ch;

RD2 = 0;
TRISD2=0;

TRISC2 = 1;
//RC2=1;

TMR1H = 19;
TMR1L = 19;
T1CON = 0x31;
/* configure capture unit */
CCPR1H=0x00;
CCPR1L=0x00;
CCP1CON = 0x05;


CCP1IE = 1;
CCP1IF = 0;
/* configure interrupts */
TMR1IE = 1;
PEIE = 1;
PIR1 = 1;
INTCON=0xC0;

while(1)
{

}
}

FYI. i am attaching project files along with proteus simulator design.

Thanks in advance
Kiran
 

Attachments

Pommie

Well-Known Member
Most Helpful Member
Try indenting your code and reposting. Even the ones in the zip file aren't indented. Many a time indenting will show you where your error lies.

Mike.

Edit, a quick look shows you're enabling timer1 interrupt but don't handle it so it will be stuck in an infinite interrupt routine.
 

kirangowle

New Member
Hi Mike,

Thanks for your suggestion.

Please find below code with indenting and i even removed the TIMER 1 interrupt.
C:
void interrupt ISR()
   {
   if(CCP1IF)  // Capture Interrupt Flag
       {
       RD2 ^=1;  // Toggling the bit
       CCP1IF = 0;
       }
   }
// Main Function

void main(void)
   {
   unsigned char ch;

   RD2 = 0;  // As Output for checking the toggling
   TRISD2=0;

   TRISC2 = 1;  // As CCP1 to capture the input
   //RC2=1;

   TMR1H = 19;  // Timer value
   TMR1L = 19;
   T1CON = 0x31;  // TMR1 ON
   /* configure capture unit */
   CCPR1H=0x00;
   CCPR1L=0x00;
   CCP1CON = 0x05; // Capture at Every rising edge


   CCP1IE = 1;  //Capture interrupt enable
   CCP1IF = 0;
   /* configure interrupts */
   PEIE = 1;
   PIR1 = 1;
   INTCON=0xC0;  // Interrupt enable

   while(1)
       {

       }
   }
 
Last edited by a moderator:

Pommie

Well-Known Member
Most Helpful Member
What does "isn't working" mean? Have you tried flashing an LED to show that power, oscillator etc are all correct.

BTW, that is still not indented correctly.

Mike
 

kirangowle

New Member
Hi Mike,

Sorry for that. I couldnt get how to intended that.

I mean its not working in Proteus simulator. I didnt tested it on real Hardware.

FYI.
I am refering this youtube video.

Thanks
Kiran
 

kirangowle

New Member
Hi Mike,

I wanted to update you on this.
With Hardware built circuit its working..

But the same code its not working in proteus. So that means something wrong in proteus.
Is proteus doesnt support CCP working

I am using Proteus 7.5 version

Thanks
Kiran
 

kirangowle

New Member
Thanks

the same code is working fine in Proteus 8 version.

As you mentioned the issue was with proteus 7.6 which doesnt support CCP.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top