Kommentar: Einfügen von HTML im Kommentar: Link einfügen: <a href="LINKURL" target="_blank">LINKTITEL</a> Bild einfügen: <img src="BILDURL"> Text formatieren: <b>fetter Text</b> <i>kursiver Text</i> <u>unterstrichener Text</u> Kombinationen sind auch möglich z.B.: <b><i>fetter & kursiver Text</i></b> C Quellcode formatieren: <code>Quellcode</code> BASIC Quellcode formatieren: <basic>Quellcode</basic> (Innerhalb eines Quellcodeabschnitts ist kein html möglich.) Wichtig: Bitte mache Zeilenumbrüche, bevor Du am rechten Rand des Eingabefeldes ankommst ! -> I > Hi Torsten, > > The principle is as follows. > Program a 1 ms counter and make sure it is set to zero it at the end of your function > ICT3IrqCapture. When ICT3IrqCapture is called again, this ms counter would then give an > approximate value of the period time (in ms). One could then use this value to calculate the > number of overflows of the Input Capture Timer. > > Example. > Suppose the difference between the current and the previous value of the Input Capture Register > is 65289. Then the period time could be 4.427 ms or 8.870 ms or 13.314 ms etc. > If the value of the ms counter is 8, I would know that 8,870 ms is the correct value. And even if > the ms counter is one short (7) or one in excess (9), I still would know that 8,870 ms is the > correct value. > > Outline of the program. > Set up and run a millisecond timer and assign to it an IRQ function that increases a variable > MST_Ticks every 1 ms. E.g. Timer_T0Time(230, PS0_64) would give ticks of 0,9983 ms. > > Define some time quantities (in ns): > #define ICT_Tick_ns 6.782e1 // the length of a tick of the Input Capture Timer > #define ICT_Range_ns 4.444e6 // the range of the Input Capture Timer (= 2^16 * ICT_Tick_ns) > #define MST_Tick_ns 9.983e5 // the length of a tick of the millisecond timer > > Adapt your ICT3IrqCapture: > ICT_Ticks = New_ICR_Value - Old_ICR_Value; > ICT_Overflows = round((MST_Ticks*MST_Tick_ns - ICT_Ticks*ICT_Tick_ns) / ICT_Range_ns); > PeriodTime = ICT_Overflows*ICT_Range_ns + ICT_Ticks*ICT_Tick_ns; > MST_Ticks = 0; > > This should do the trick. Only in the case of very long period times (order of seconds) errors > would arise caused by limited accuracy of real variables. In that case some optimization > could probably be achieved by doing the calculations in ICT ticks instead of ns and using > dwords instead of reals where possible. Also, when the program would cause delays that > prevent handling the interrupts of the ms timer or the Input Capture Timer for more than 1 ms, > errors would arise. > > If any questions remain, let me know. > I could not test this program so I would be curious to know the results. > > Regards, > Pepe