Hi Eric,
To make a 180 degree out of phase on the pulses,
you can configure as follows: I am not familiar with the Arduino way
of doing it.
This assumes 16Mhz clock, no divider (ie CPU runs
at 16Mhz), PB1 (OC1A) and PB2 (OC1B) is 180 degrees or opposite
polarity.
TCCR1A = (2 << COM1A0) | (3 << COM1B0)
| (2 << WGM10); // OC1A = high then low, OC1B = low then
high
TCCR1B = (3 << WGM12) | (1 <<
CS10);
// The timer mode uses
ICR1 to control the frequency, in this case 40khz
OCR1A =
199; //
50% duty cycle
OCR1B =
199; //
50% duty cycle
ICR1 = 399;
// (16Mhz / 1 / 40000) - 1
As for generating the 20 pulses every 550msec, I
would recommend to use another timer, ie timer 0 or timer 2 (with it's
prescaler), then let it interrupt you both at COMPA and OVF, one to turn on
the TCCR1A as above, and the other to turn off by setting it to 0.
This would make the timings very
accurate.
If you are using this for distance measurement, I
would recommend to actually use timer 0 for the ultrasonic pulses, time 2 for
the pulse timing and then use the timer 1 capture mode (PB0 ICP1 pin) to
actually time the reflected ultrasonic pulse. This minimizes any CPU
load.
Take some time to understand the TIMER0, 1, and 2
section of the Atmel datasheet as it gives you a lot of options. It also
helps to have a logic analyzer or a scope to verify signals and
timing.
Alex