Hello. I have been trying to find a solution for a couple of years on this but have had no success. I am trying to find a code for my arduino nano 328 that will let me provide dc pulses to 2 coils (in one) alternating between the coils. for example, I would like coil A's input to receive a pulse of dc for 100 ms then turn off. Then, I would like coil B's input to receive a pulse of dc for 100 ms and then turn off. The cycle would then need to repeat indefinitely. I'm hoping for a 50% duty cycle. I have 31 kHz coming out of both D9 and D5. My problem is how to code it so that the pulses don't overlap. extra information: The coil is wound one turn with flat wire in one direction and the other in the opposite direction. Ferite core. Any help on this would be greatly appreciated. Thank you.
Unless I misunderstand that seems like a simple requirement - like this pseudo code
digitalWrite(coil1pin, HIGH); wait digitalWrite(coil1pin, LOW); digitalWrite(coil2pin, HIGH); wait; digitalWrite(coil2pin, LOW); repeat
The demo Several Things at a Time shows how to manage timing using millis(). The same technique will work with micros()
You have to program the timers directly to select antiphase outputs from the pins connected to a timer.
On the Uno and other ATmega328 based arduinos the pins 9,10 are driven from timer1 and can be
set to work in antiphase. Similarly 5,6 for timer0 and 11,3 for timer2.
Look at the documentation in the chip’s datasheet for TCCR1A, TCCR1B etc.