How to generate a designated Square Wave?

i have a driver board of which the input wave is a 0.7V~4.3V square wave. The frequency is accepted from 10~100 Hz. I want to generate this waveform from my Arduino mega 2560 but I can only adjust the waveform frequency. Is it possible to generate it? Or, is it possible if I add other external modules?

Thank you!

It's not that I don't believe you, but there may be other conditions. Please provide a link to your driver board.

Why do you think you have to adjust more than the frequency?

What is wrong with the format generated by tone() ?

Isn't that all you need to adjust, according to your description of the driver? So what is your complete problem?

It is not possible to generate tones lower than 31Hz

Too bad. :wink:

Blink without delay generates square waves, maybe based on micros.

Multiple questions are unanswered.

You can see the Unipolar output equation. When power supply is 5V, the input signal ranges from 0.7V~4.3V to get a 0~100V square wave output.

I have no problems on adjusting the frequency. The problem is the amplitude.

The problem is I need exactly 0.7V~4.3V sqaure wave output. A little offset may be accepted.

Because this range is the largest input range of the driver board. You can read the link I replied to Paul_KD7HB

Make an op amp circuit, then you can even make it easily adjustable.

Op amps with 100V reference voltage are expensive. Also, I don't have any other deivces to generate 100V reference voltage.

Some op amp circuits can incorporate voltages in excess of the input maximum, for example using a voltage divider. However weren't we talking about the approximate range inside 0-5V? Op amps can certainly operate there. So you can condition a digital Arduino output with an op amp limiter. In fact, I think a simple amp with a gain of about 0.8 and a reference of 1/2 Vcc would qualify. Or it's possible you could make a simple one using diodes to obtain the approximate 1.8V amplitude difference.

Actual gain should be (Vcc - 0.7 - 0.7) / Vcc

It has to be in the inverting configuration because the non inverting configuration can't have less than unity gain.

It's conceivable that a resistor network could do it, but I'm much too tired to take that on right now. But it could look like a voltage divider, with a series resistor from the output junction to the Arduino output pin, also connected to the input of the board you are using. So three resistors.

Use a DAC. Either an external DAC or one of the Arduinos that have a physical DAC built in. 100Hz is trivial to generate.

1 Like

You can try to use my AVR_Slow_PWM library to see if OK for you.

This library enables you to use ISR-based PWM channels on AVR-based boards, such as Mega-2560, UNO,Nano, Leonardo, etc., using AVR core to create and output PWM any GPIO pin. Because this library doesn't use the powerful purely hardware-controlled PWM with many limitations, the maximum PWM frequency is currently limited at 500Hz , which is still suitable for many real-life applications. Now you can also modify PWM settings on-the-fly.

The output of the driver is a square wave with a max amplitude of 100V.
If you connect the MEGA directly it will give an input of (0 + a little bit) to (5V - a little bit)
you can connect that directly to the driver board and it will be fine, because the oiutput voltage is limited.

If you NEED to CONTROL the size of the output signal then

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.