On 28 Nov 2011 at 17:55, Yigit Turgut wrote: > I applied various frequencies (PWM) and LCD outputs are as following ; >=20 > 1kHz >> 11857 > 2kHz >> 5857 > 4kHz >> 2857 > 16kHz >> 607 >=20 > Timer was expected to counts less in a higher frequency than a lower > one. That is correct, and the results above confirm that. While not precise the = results are=20 definitely in the ball park.. as frequency is doubled the period count seem= s to=20 approximately halve. Without knowing the units it would seem the only probl= em you=20 need to address is to fine tune the accuracy/jitter in the results. > 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. We have been all been there before, some very regularly :-)=20 =20 > 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 capt= ure 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. > > Would be useful to see code for ReadCapture1(), as that would seem to be wh= at=20 captures the timer value. Incidentally you don't need to put (int) in front= of it each=20 time you call it if the prototype for this function implicitly states that = it returns an int. --=20 Brent Brown, Electronic Design Solutions 16 English Street, St Andrews, Hamilton 3200, New Zealand Ph: +64 7 849 0069 Fax: +64 7 849 0071 Cell: +64 27 433 4069 eMail: brent.brown@clear.net.nz --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .