Hi All,

I would like to drive a transformer with a fullbridge and a square wave from an arduino.

I’ll need 2 synchronized pins for that to generate the top and lower half of the square wave.

Also we will need to modify the drive signal frequency “> 50hz” and duty cycle “< 50%” on the fly.

finally that is part of the whole project so the code should not delay the running main program so no delays I suppose.

and just FYI I’m not trying to reach high voltage just 60v maximum.

I really hope someone could help me or already got the code for that.

Sounds like you just need a standard H-bridge (aka motor driver) and a PWM output. See ATmega328p data sheet for the exact settings of the PWM output - you can quite easily adjust the frequency with some register settings. Use timer1 or timer2 as timer0 is in use by a.o. the millis() counter.

Thank alot for your reply Wvmarle,

Unfortunately I have Minimum experience in arduino programing and that seems to need a specific knowledge and i'm kinda of sure i'll ran into much hussle and frustration, so if some one could point a library or provide a piece of code that could be used, that would be magnificent.

You seem to want something different from a simple square wave to drive the transformer? That's a very ambitious electronic project, much more complicated than the digital signal generation. Do you have a circuit diagram already?

Otherwise have a look at the TimerOne library, for square wave generation using timer 1.

No library that I’m aware of; if you want to use PWM and adjustable frequency (the best solution as all is done in hardware) you probably have to do it the hard way. It should be possible to keep two pins in perfect sync this way as well.

The second option is bitbanging. Look at the blink without delay example on how to do this; your 50 Hz signal is of course just a very fast blink. Should work quite well up to about 1 kHz depending on what else the Arduino has to do. Keeping two pins in perfect sync is going to be hard, as the timing is not as precise.

Neither way is easy for a beginner, and it feels rather non-trivial for an experienced programmer.

Sorry, I don't understand why an H-Bridge for the power and TimerOne library for the frequency should not do the trick with a sqare wave?

Thanks alot for your reply DrDiettrich,

Unfortunately Everything is still in it's infancy, all is just an idea now and I thought I'd secure that most crucial part first.

I saw the library and understood it generates a one pwm signal with a fixed relatively high frequency and changing duty cycle as the program tells it.

So I might be able to invert the signal using a transistor and a pull down resistor, however still the changing frequency on the fly issue, Also I really hope those 2 things could be resolved in the code.

Ok now I understand it is beyond my abilities to achieve that and it seems no one needed such a thing before so if we were to continue will have to find a simple way to actually pull it off.

I’ll look at both the blink without delay and the timer one library maybe I’d be able to write the needed code, but i consider that a bad luck already :slight_smile: .

An H-bridge allows to reverse the output polarity (direction), no need for a reversed signal.

If you want gaps between polarity changes, a timer allows the generation of complementary signals of any duty cycle as well. But some logic circuitry may be required before the H-bridge inputs.

Beyond the PWM output of the Arduino I don't really get what you're after exactly.

I think you should draw a chart of the intended signals or (better) the intended H-bridge output. That'll be very helpful in understanding what it is you actually want to achieve.