arisu1love
Newbie level 5
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:
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?
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?