Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt Kategorie: Programmierung C (von Torsten - 27.04.2012 20:41) | ||
Als Antwort auf Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt von PepeV - 25.04.2012 13:27 | ||
| ||
> > > 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 > > > > > > Hi Pepe, > > > > estimate the overflows will make the same problem. > > Between the input-capture event and the call of the > > interrupt function passes by too much time. > > The second timer will keep on running. > > But is the second timer near the overrun border, > > he is counting one too much. > > This is supplying a wrong value occasionally. > > It would be nice, we have more information about > > the interrupt handling of the byte-code interpreter. > > Unfortunately it seems to be a secret of the C-Control developer. > > This turns the C-Control into a miracle bag. > > > > Regards Torsten > > > > Hi Torsten, > > It's not exactly the same because the solution I suggest is much less sensitive to delays between > input-capture event and the call of the interrupt function. It can withstand delays up to 1 ms > whilst the solution with the overflow counter can withstand only delays up to 6.78 ns. > I would say: try it! > > Regards, > Pepe Hi Pepe, thanks for your advice. The false measurement is not so often, but is still there. The code-example will show you. Regards Torsten InputCaptureT3-0.02.zip | ||
Antwort schreiben Antworten: Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 28.04.2012 16:05) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 1.05.2012 8:18) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 1.05.2012 21:48) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 2.05.2012 21:02) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 4.05.2012 15:15) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 5.05.2012 6:26) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 5.05.2012 14:45) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 6.05.2012 8:34) Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 7.05.2012 20:33) |
Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum