I applied various frequencies (PWM) and LCD outputs are as following ; 1kHz >> 11857 2kHz >> 5857 4kHz >> 2857 16kHz >> 607 Timer was expected to counts less in a higher frequency than a lower one. System responds logically somehow but lacks from precision. It can be a data conversion typo or etc. My current mental situation is not suitable to debug more. On Mon, Nov 28, 2011 at 5:49 PM, Yigit Turgut wrote: > Hi all, > > Recently I am trying to capture pulse duration using Capture module on > CCP1 port and print the frequency to lcd. Configuration, timer > settings, interrupt monitoring etc, everything works as expected > except one thing ; LCD shows ridiculous values for example it gives > '11869' value for a 1kHz PWM input. It is responsive to changes in the > frequency of the applied pwm but not accurate/consistent. This is the > crippled code not to pollute around ; I am currently using MPLAB C18 > with a target of 18f2550. I can post the entire code as well but the > mistake lies in this section I suppose ; > > void main(void) > { > unsigned char config1=3D0x00,timer_value =3D 0x00; > > TRISC =3D 0; //all c ports are output > TRISCbits.RC2 =3D 1; //ccp1 input > > SetTmrCCPSrc(T1_SOURCE_CCP); =A0 //Set Timer 1 as source for input captur= e module > > =A0 =A0 =A0 =A0 =A0config1 =3D CAP_EVERY_RISE_EDGE | CAPTURE_INT_OFF ; //= configure input > capture for capture on every rising edge and its interrupt off > =A0 =A0 =A0 =A0 =A0OpenCapture1(config1 ); > =A0 =A0 =A0 =A0 =A0OpenTimer1(0); //start the timer > > =A0while(!PIR1bits.CCP1IF); =A0// Wait for event > > =A0INCAPResult =3D (int)ReadCapture1(); // read result > > =A0display((int)INCAPResult); =A0 // print result on lcd > > =A0 =A0 =A0 =A0while(1); > CloseCapture1(); > } > > Connections and configurations are all triple checked and they work. > But as I mentioned LCD is not returning correct values. Went over the > code for lots of times without =A0no luck! > > Any ideas ? > > Have a nice day. > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .