Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum

Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt Kategorie: Programmierung C (von PepeV - 24.04.2012 14:40)
Als Antwort auf Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt von Torsten - 23.04.2012 19:54
Ich nutze:
C-Control Pro Mega128, Pro-Bot128
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


    Antwort schreiben


Antworten:

Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 24.04.2012 20:31)
    Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von PepeV - 25.04.2012 13:27)
        Re: Synchronisationsproblem mit Input-Capture und Timer-Overflow Interrupt (von Torsten - 27.04.2012 20:41)
            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)