PWM - generate a 60-2 signal.

I need to simulate a crank position sensor from an automotive system. It utilizes a "60-2" toothet wheel.
Generating a PWm signal with varying frequenzy is not hard at all, but I cannot quite see how to stop generating the signal for two periods. :frowning:

The signal looks something like this:

http://www.ital-performance.pl/temp/vems/trigger_falling.jpg

Can anybody help point me in the right direction?

generate a 60 pulse signal and AND this signal with one that is low for two pulses. This latter can be made by feeding the 60 pulse back to an Arduino IRQ line and the following pseudocode

irq()
{
  count++;
  if (count< 59) digitalWrite(pin. HIGH)
  else digitalWrite(pin, LOW)
  if (count == 60) count = 0;
}

does this help a bit?

Ahh yes it is very simple - once you see the light :slight_smile:

I decided nto to use interrupts as this is the only thing the Arduino has to do.

So I used this:

if (c > 60){
    digitalWrite(TDC, LOW);
    if ( c >= 62)
      c = 0;
  }
  else    
    digitalWrite(TDC, HIGH);


  delayMicroseconds(rpm_const/2); 
  digitalWrite(TDC, LOW);
  delayMicroseconds(rpm_const/2);

rpm_const will determine the frequency. This gives me a good 60-2 signal that I can use

"Everything should be made as simple as possible, but not simpler." Albert Einstein :wink:

"entia non sunt multiplicanda praeter necessitatem" William of Occam (Ockham)

If you are using interrupts why not use a timer interrupt to directly generate the signal? Then you only need one pin and no external and gate.