+2  A: 

The overall signal, i.e. the signal that you get when you add the red and the blue, has a phase length of 16 times the blue and 9 times the red signal. You could measure the time difference between every 16th blue and every 9th red rising flank.

I guess that what you want to measure is the wear on the gears. I think that this measurement might be influenced (introducing noise) by the gears' tolerance, if there is no uniform traction.

Svante
You may be right about the quality of the signal. I'm not sure the electronics will be sensitive enough to detect such small differences, but I'm curious about the algorithm either way. +1 for the suggestion to match up specific edges. I'll give it a shot!
e.James
A: 

I think the best thing to do would be to create an X-Y diagram of all teeth pair timings. You'd arbitrarily pick one tooth on each cog as T=0..

MSalters
That sounds promising, would make a pretty picture if nothing else :)
Tom
+1  A: 

Hi, I think it is even simpler than that.

Every 16*9 samplings(of the big cog) the wheels are in the exact same spot they started.

So what you do is the following:

  • pick any point in time with a sampling on the big cog. Measure the amount of time before you sample the small cog too. Remember this value.

  • every 16*9 samplings of the big cog (why does this sound dubious?) do the same measurement again and compare it to your base value. When the timing begins to shift, you have a problem.

R

Toad
With the caveats of my comments to the OP question, I think it is not enough to do a measurement every cycle: if one of the involved gears loses a tooth which is not working at the time of measurement, you would never notice. I think you need some comparison between the **whole** signals, which is not altered by local scalings, i.e. you don't want that instantaneous speed variations of the drive shaft give you a false alarm. I would experiment with something along the lines of the cross-correlation between the input and output, which is probably unfeasible with the storage constraints...
Jaime
+1  A: 

I am having some trouble visualizing your hardware setup. And the behavior you are trying to detect. A shaft slipping? Teeth wearing?

In any case, I would write a simulation of the situation so that I can get some, perhaps exaggerated, results with no noise to test algorithms against.

The algorithms I would test would be variations of the following:

Assign signal with lowest frequency to A

Time A’s rising edge. =>  Ta1

Time the next B rising edge . =>  Tb1

Calculate time Tb1 – Ta1    =>  dT1

Time next A’s rising edge. => Ta2

Time the next B rising edge. =>  Tb2

Calculate time Tb2 – Ta2    =>  dT2

Calculate second order difference  dT2 – dT1  => d2T1

Repeat precious steps to get another second order difference  => d2T2

If sign of d2T1 and d2T2 are different, 

repeat previous steps

else sign of d2T1 and d2T1 are same

    calculate third order difference  d2T2 – d2T2  =>  d3T1

Repeat previous steps to get another 3rd order difference  =>  d3T2

If d3T2 – d3T1 > max noise

    Raise alarm
ravenspoint
This deserves an upvote, but I've hit the limit for today. I will upvote in 5 hours or so.
e.James
...and there it is. +1
e.James
+2  A: 

Since we are talking about "phase", then it seems reasonable to measure the "beat" which occurs when the two waveforms reinforce each other.

Something like this, perhaps:

void cog_phase_monitor2( int cog, int t )
{
    static int last_a, last_b, last_beat, last_beat_delta = 0;;
    int beat = 0;
    if( cog == 1 ) {
     if( t - last_b < 1 )
      beat = 1;
     last_a = t;
    }
    if( cog == 2 ) {
     if( t - last_a < 1 )
      beat = 1;
     last_b = t;
    }
    if( beat ) {
     printf("**** delta beat %d \n",t-last_beat);
     if( last_beat_delta ) {
      if( last_beat_delta != t-last_beat ) {
       printf("!!!Warning beat just changed !!!\n");
       last_beat_delta = 0;
      }
     } else {
      last_beat_delta = t-last_beat;
     }
     last_beat = t;
    }

}

Now if we plug this into a simulation of two cogs, one of 9 teeth and one of 16 teeth, both turning at 10 revs per second

B at 6 msecs
A at 11 msecs
B at 12 msecs
B at 18 msecs
A at 22 msecs
B at 24 msecs
B at 30 msecs
A at 33 msecs
B at 36 msecs
B at 42 msecs
A at 44 msecs
B at 48 msecs
B at 54 msecs
A at 55 msecs
B at 60 msecs
A at 66 msecs
B at 66 msecs
**** delta beat 66
B at 72 msecs
A at 77 msecs
B at 78 msecs
B at 84 msecs
A at 88 msecs
B at 90 msecs
B at 96 msecs
A at 99 msecs
B at 102 msecs
B at 108 msecs
A at 110 msecs
B at 114 msecs
B at 120 msecs
A at 121 msecs
B at 126 msecs
A at 132 msecs
B at 132 msecs
**** delta beat 66
B at 138 msecs
A at 143 msecs
B at 144 msecs
B at 150 msecs
A at 154 msecs
B at 156 msecs
B at 162 msecs
A at 165 msecs
B at 168 msecs
B at 174 msecs
A at 176 msecs
B at 180 msecs
B at 186 msecs
A at 187 msecs
B at 192 msecs
A at 198 msecs
B at 198 msecs
**** delta beat 66

And now if we add a delay of 1 msec to one of the cogs:

B at 6 msecs
A at 11 msecs
B at 12 msecs
B at 18 msecs
A at 22 msecs
B at 24 msecs
B at 30 msecs
A at 33 msecs
B at 36 msecs
B at 42 msecs
A at 44 msecs
B at 48 msecs
B at 54 msecs
A at 55 msecs
B at 60 msecs
A at 66 msecs
B at 66 msecs
**** delta beat 66
B at 72 msecs
A at 77 msecs
B at 78 msecs
B at 84 msecs
A at 88 msecs
B at 90 msecs
B at 96 msecs
A at 99 msecs
B delayed at 102 msecs
B at 103 msecs
B at 109 msecs
A at 110 msecs
B at 115 msecs
A at 121 msecs
B at 121 msecs
**** delta beat 55
!!!Warning beat just changed !!!
B at 127 msecs
A at 132 msecs
B at 133 msecs
B at 139 msecs
A at 143 msecs
B at 145 msecs
B at 151 msecs
A at 154 msecs
B at 157 msecs
B at 163 msecs
A at 165 msecs
B at 169 msecs
B at 175 msecs
A at 176 msecs
B at 181 msecs
A at 187 msecs
B at 187 msecs
**** delta beat 66
B at 193 msecs
A at 198 msecs
B at 199 msecs
B at 205 msecs

This seems like a hopeful beginning :-)

ravenspoint