Arduino function generator

Hi to y'all,

First let me say, i'm not an electronics wizkid :), so don't start shouting at me, lol.

I'm in need of a real analog blockwave generated with PWM, so simple turn 0-5V PWM to -2.5-2.5V.(or any similar voltages, i presume i can amplify it later.)
So my idea was to build this function generator :

All is fine except i do have an LM380 instead of a LM386 which i have not yet implemented, for now i'm just "scoping" the signal which normally would go into the LM386, all signals are fine except for the PWM generated blockwave, this will shifts his amplitude to zero with full PWM(254) or with zero PWM(0), so only with half PWM signal(127) it is a nice -2.5 to 2.5V signal.

I hope you understand what i mean, I have no cam here to screenshot the scope screen, sorry.

My question is, does the audio amplifier fix this problem ?
Or do i need a complete different approach for what i like to accomplish ? A true -2.5 to 2.5V analog block-wave. (or is it called square wave?) hmm wave is not square wave is a sort of oxymoron :slight_smile:

Well lets hope somebody can shade some light on this.

Thank you, greetings,
Alphons

P.S. I respected all part values up to the LM386.

You "low-pass filter" the PWM signal to get an analog voltage - even a simple RC filter will work.

For generating higher analog frequencies though you'll need to re-configure the Arduino timer(s)
to generate PWM a lot faster (they are running at 1kHz or 500Hz roughly, can be made to go at
60kHz or so on Uno or Mega). Two of the pins, 5 & 6 are attached to timer0 which also controls
mills() and delay() so you probably don't want to use them.

Hi, That was quick :slight_smile:

Low Pass filter ehh, *-+??..!@##$ hmmm.

Ok :), will start search for that then.

I know about the frequency things of the arduino, have already been playing with that in the Arduino/Speaker laser show and tone/noise experiments :slight_smile:

The Arduino Function generator also uses these arduino freq. timings to have the frequency knob working :slight_smile:

Greetings,
Alphons

Hi again,

Ok low-pass filter, it seems this will "smooth" the PWM signal.
I just had to place 1 capacitator in the circuit to do this, but this "destroys" the square signal and gives me an average voltage, this is NOT what i want, i want to square signal to stay as a square output signal, with the LP filter the "block" figures have disappeared and a constant line is now just showing an avarage voltage.

I think i'm getting a bit confused, a square signal is not a analog signal ? My scope does have a square wave generator on it, i can not however change the Pulse Width Modulation on the scope, but it gives me a nice square drawing on the screen of +0.1 to -0.1 V . So this means a square wave can be analog, hmmm, confusing .......

Ok back to the Arduino Function generator experiment, is it normal when changing the Pulse Width of the PWM signal that the output signal changes in amplitude ?

My thought is that the voltage amplitude should stay the same and only the pulse width should changed .
But again, i'm getting confused and start to see some implications in my way of thinking.
I will experiment and think a bit more.

Thanks,
Alphons

Digital is just a special case of analog where you've defined one state as "0", and another as "1".

I'm in need of a real analog blockwave generated with PWM, so simple turn 0-5V PWM to -2.5-2.5V.(or any similar voltages, i presume i can amplify it later.)

Are you saying that instead of a square wave that goes from 0 to +5V, you want a square wave that goes from -2.5 to +2.5V?

If it is a 50/50 square wave, then all you need is a capacitor in series with the output, with a resistor to ground on the side of the capacitor away from the Arduino output.

Hello all,

Are you saying that instead of a square wave that goes from 0 to +5V, you want a square wave that goes from -2.5 to +2.5V?

Yes, but i still want to be able to control the Pulse Width, so i want to split the voltage 50/50(+2.5to-2.5V), but i want to still be able to keep pulse width variable, without loosing the voltage.
And i don't want to change the frequency ( I am using 0x01 62500Hz on pin 5).

Greetings,
Alphons

Hi again,

I'm reading up on the different audio amplifier i have, i have the LM380, and quess what im reading here:

A unique input stage allows ground referenced input signals. The output automatically self-centers to one-half the supply voltage

I presume "self center" means to negative voltage ????

Hmm, seems i can plug in the PWM straight from the arduino and it will make sure signal output is nice one-half the supply voltage.

I have a lot to learn, i will go experiment again a bit.

I will report on my findings so we can call this topic "solved" :slight_smile:

Later,
Alphons

Allie:
I'm reading up on the different audio amplifier i have, i have the LM380, and quess what im reading here:

A unique input stage allows ground referenced input signals. The output automatically self-centers to one-half the supply voltage

I presume "self center" means to negative voltage ????

No, it self-centers to 1/2 the supply voltage, just as it says. The LM380 is a single supply amplifier, biased so inputs referenced to ground will still set the output at 1/2Vcc.

You need an Op Amp and a negative supply voltage of -5V. Then the Op Amp needs to be wired up for a DC offset, so it adds -2.5V, shifting the Arduino PWM 0V to -2.5V, and 5V to 2.5V.

For that, you can simply set it up as a differential amp with a gain of 1, then send the Arduino 0-5V PWM signal to the noninverting input and a +2.5V to the inverting input.

Or a simpler way to do it, if you don't mind inverting the PWM and making some changes in software, is to set it up as a simple summing inverting amplifier with a gain of -1. Then send the 0-5V to one input, and -2.5V into the other.

Av(V1 + V2) = Vout
-1(0V + -2.5V) = 2.5V when the PWM signal is at 0V
-1(5V + -2.5V) = -2.5V when the PWM signal is at 5V

So if we set all resistors equal, say 10k, then the gain from each input to the output is -1. However, the gain is affected by source impedance, so you can't just set up a voltage divider and send it into an input, as the equivalent resistance of the divider adds to the input resistance, reducing gain for that input.

So instead we use a trick: Use 10k for the PWM input and for the feedback resistor, so the gain there is -1. But then we add two more inputs, each with 20k resistance, so their gains are -0.5. One connects to -5V, the other to 0V. Both add together to result in the same as -2.5V with a gain of -1.

Remember, your oscilloscope input channel has a DC and AC setting... The AC setting eliminates the "DC component" of the input.

Good articles on oscilloscopes to help establish the proper vernacular.

Ray