Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with input capture with PIC18F4550

Status
Not open for further replies.

arisu1love

Newbie level 5
Joined
Nov 15, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
Hi everyone,

I wrote a program on the PIC to fire a pulse at each rising edge of an input square waveform. The code is as detailed below:


#include <stdio.h>
#include <p18F4550.h>
#include <delays.h>
void main(void)
{
int i;
TRISCbits.TRISC2=1; /*configure this as input,pin RC2, special for capture*/
TRISCbits.TRISC0=0; /* as led output, pin RC0 */
T3CON = 0X81; /*0B1000 0001*/
PIE1bits.CCP1IE=0;
PIR1bits.CCP1IF=0; /*clear the capture flag*/
T1CON = 0X81; /*0B1000 0001*/
CCP1CON = 0X05; /*0B1000 0110* eVERY RISING EDGE*/


while (1)
{
if(!(PIR1bits.CCP1IF))
{
PIR1bits.CCP1IF=0;
PORTC = 0X01; /*light the led*/
Delay10TCYx(10);
PORTC = 0X00; /*off the led*/

}
}

But when I test the output of my microcontroller with an oscilloscope, I find that the pulse is not a smooth square pulse at every rising edge as expected. The LED connected to the output also flickers. Can someone tell me what I am doing wrong?
 

if(!(PIR1bits.CCP1IF)) ?

Shouldnt this be

if(PIR1bits.CCP1IF == 1)
 

condition chng as suggested by btbass mite work..

do try using a pull up or edge triggering.
 

Thanks for the suggestion, I will try to solve using the suggested methods and get back to you all on the result... :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top