tk2000
Posts: 2
Joined: Thu Sep 09, 2021 7:50 am

How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 6:59 am

Hello
I think it's possible to connect this module (https://www.aliexpress.com/item/1005002277925998.html) to the PWM pin of the Rasberry Pi and get a 0 to 10V analog output.
However, what I really need is a +/-5V analog output to control the motor.
Therefore, if the GND output of the above module is 5V, I think I can get the +/-5V analog output, but I don't know how to do this.

Is it possible to bring 5V GND from gpio 2(5V output)?
Thanks a lot.

User avatar
B.Goode
Posts: 12973
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 11:39 am

tk2000 wrote:
Thu Sep 16, 2021 6:59 am
Hello
I think it's possible to connect this module (https://www.aliexpress.com/item/1005002277925998.html) to the PWM pin of the Rasberry Pi and get a 0 to 10V analog output.
However, what I really need is a +/-5V analog output to control the motor.
Therefore, if the GND output of the above module is 5V, I think I can get the +/-5V analog output, but I don't know how to do this.

Is it possible to bring 5V GND from gpio 2(5V output)?
Thanks a lot.

See https://pinout.xyz/


GPIO 02 on Physical Pin #03 only provides 3.3 volts when On/High, just the same as all the other GPIO pins on the 2x20-way header.

The 5 volt Power available from Physical Pins #2 and #4 is not program-controllable.

All the GPIO pins on the 2x20-way header are Digital [ High/Low, On/Off ]: none are analogue.
Last edited by B.Goode on Thu Sep 16, 2021 11:41 am, edited 1 time in total.

scotty101
Posts: 4292
Joined: Fri Jun 08, 2012 6:03 pm

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 11:40 am

Can you describe a bit more about your project and its end goal.

Given that you mention driving a motor, I'm guessing you want it to spin both directions at a variable speed. Why not use one of the many motor controllers for the Raspberry Pi that support PWM to vary to speed of the motor?

The specifics of which motor driver to use will depend on the power requirements of your motor (what voltage and current it requires)
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 12:31 pm

tk2000 wrote:
Thu Sep 16, 2021 6:59 am
Is it possible to bring 5V GND from gpio 2(5V output)?
Thanks a lot.
It's possible, but it's a bad idea. If you ever end up with an earth loop, there is potential for short circuits that can do a lot of damage.
It's better to keep 0V as GND, and design an op-amp circuit to change signal voltages to the required range.
But again, it may be possible to re-think your project so that standard parts will do the job.
Location: 345th cell on the right of the 210th row of L2 cache

tk2000
Posts: 2
Joined: Thu Sep 09, 2021 7:50 am

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 12:58 pm

Thanks a lot for the reply.
My goal is to operate the Galvo Scanner control board from the program by PWM on the Raspberry Pi, as shown below.
It is a board that can specify the X and Y motor angles at 20Khz by +/- 5V respectively.

https://www.aliexpress.com/i/33034843560.html

The Galvo Scanner is a motor like the one below.
Image

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 5:18 pm

I'm utterly confused. The somewhat brief specification for that board does not mention +/- 5V control, it mentions DMX. DMX uses the electrical characteristics specified by RS-485. That requires a 5V swing between mark and space, with a wide range of common mode voltage.

The signal timing of DMX is not PWM. While PWM can be used to provide a crude variable voltage, it will not generate the serial stream required by DMX. The Pi can easily generate serial signals at 3V3, you would still need an adaptor or interface circuit for 5V operation.

If your controller does have a +/-5V analogue input, as I said before, you cannot directly generate that from a Pi.
Location: 345th cell on the right of the 210th row of L2 cache

danjperron
Posts: 3870
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 5:37 pm

I agree with Davidcoton.

A simple RS-485 driver chip will do the trick.
A SN65LBC179D could be power by 5V and the input pin D is 3.3V compatible.

Check page 3
https://www.chauvetlighting.com/downloa ... ev6_WO.pdf

ame
Posts: 3724
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 10:08 pm

davidcoton wrote:
Thu Sep 16, 2021 5:18 pm
I'm utterly confused. The somewhat brief specification for that board does not mention +/- 5V control, it mentions DMX. DMX uses the electrical characteristics specified by RS-485. That requires a 5V swing between mark and space, with a wide range of common mode voltage.

The signal timing of DMX is not PWM. While PWM can be used to provide a crude variable voltage, it will not generate the serial stream required by DMX. The Pi can easily generate serial signals at 3V3, you would still need an adaptor or interface circuit for 5V operation.

If your controller does have a +/-5V analogue input, as I said before, you cannot directly generate that from a Pi.
Are you looking at the same thing?

https://www.aliexpress.com/i/33034843560.html

This board has no mention of DMX.
Laser Galvo Scanner X Y Driver Board Scanning Speed 15Kpss Max 20Kpps Servo Amplifier For ILDA Laser Light Show
Driver board for laser galvo scanner X Y scanning motor servo amplifier

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 10:36 pm

ame wrote:
Thu Sep 16, 2021 10:08 pm
Are you looking at the same thing?

https://www.aliexpress.com/i/33034843560.html
Yes:
"Product Description: Style:DMX Stage Light"

That may be marketspeak referring to the overall application rather than the module alone.

What it doesn't mention is +/- 5V.
Location: 345th cell on the right of the 210th row of L2 cache

ame
Posts: 3724
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to get a +/-5V analog output from the PWM

Thu Sep 16, 2021 11:09 pm

davidcoton wrote:
Thu Sep 16, 2021 10:36 pm
ame wrote:
Thu Sep 16, 2021 10:08 pm
Are you looking at the same thing?

https://www.aliexpress.com/i/33034843560.html
Yes:
"Product Description: Style:DMX Stage Light"

That may be marketspeak referring to the overall application rather than the module alone.

What it doesn't mention is +/- 5V.
Ah, I see it. It's not easy to find on the mobile version of the site, but I tend to ignore that section anyway because it's often misleading. As it is in this case.

If you look at the galvo itself you can see the +/-5V requirement.

https://m.aliexpress.com/item/32869192972.html

Obviously you need an amplifier to drive the galvanometer, since there are probably high currents required to move the galvanometers at the speed required.

Then you need a controller that gives you a higher-level interface, maybe X,Y coordinates. That's probably driven by DMX. Then at the other end some kind of animation software that produces the X,Y coordinates for the beam from the desired image.

My guess is that OP wants to do all of that in the Pi, and output the +/-5V signals for the galvos directly.

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 9:07 am

ame wrote:
Thu Sep 16, 2021 11:09 pm
If you look at the galvo itself you can see the +/-5V requirement.

https://m.aliexpress.com/item/32869192972.html

My guess is that OP wants to do all of that in the Pi, and output the +/-5V signals for the galvos directly.
Okay, with the right product link it's a bit clearer. The unit requires +/-5V analogue, presumably two channels, with the voltage stepped at up to 18k levels per second.

As before, I don't think PWM is the way to go, you need a DAC with bipolar output, possibly running from then Pi's I2C bus. Without a fuller spec, it is impossible to know whether there is a DAC that will drive the head directly, or if a high current amplifier is required (I would guess the latter). You will also need a +/- something power supply so that you get the full +/-5V output swing.

EDIT: Back to the original module. It does look as if it will convert PWM to 0-10V analogue. No idea of the sample rate, no idea of the drive current, no idea of the output quality, and as in my first reply not really suitable for shifting to +/-5V without further electronics and multi-rail power supplies. Even if you try to create a mid-rail pseudo-ground (that is, 5V), the output will be a current source relative to true 0V, whereas you would need to sink current in the lower half range output. Better to design an output stage with true +/-5V and the required current source/sink, whatever that is. Then, why introduce 10V signals and the extra supply voltage that needs?

EDIT2: Corrected A2D to DAC :oops:
Last edited by davidcoton on Fri Sep 17, 2021 9:27 am, edited 3 times in total.
Location: 345th cell on the right of the 210th row of L2 cache

ame
Posts: 3724
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 9:20 am

davidcoton wrote:
Fri Sep 17, 2021 9:07 am
ame wrote:
Thu Sep 16, 2021 11:09 pm
If you look at the galvo itself you can see the +/-5V requirement.

https://m.aliexpress.com/item/32869192972.html

My guess is that OP wants to do all of that in the Pi, and output the +/-5V signals for the galvos directly.
Okay, with the right product link it's a bit clearer. The unit requires +/-5V analogue, presumably two channels, with the voltage stepped at up to 18k levels per second.

As before, I don't think PWM is the way to go, you need an A2D with bipolar output, possibly running from then Pi's I2C bus. Without a fuller spec, it is impossible to know whether there is an A2D that will drive the head directly, or if a high current amplifier is required (I would guess the latter). You will also need a +/- something power supply so that you get the full +/-5V output swing.

EDIT: Back to the original module. It does look as if it will convert PWM to 0-10V analogue. No idea of the sample rate, no idea of the drive current, no idea of the output quality, and as in my first reply not really suitable for shifting to +/-5V without further electronics and multi-rail power supplies.
I think you mean DAC. And PWM is a perfectly good way of doing that.

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 9:24 am

I do mean DAC. Will edit post. PWM conversion may be okay, but what about its speed? The difficulty is converting 0-10V to +/-5V and providing the necessary (but unspecified) drive.
Location: 345th cell on the right of the 210th row of L2 cache

ame
Posts: 3724
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 9:35 am

davidcoton wrote:
Fri Sep 17, 2021 9:24 am
I do mean DAC. Will edit post. PWM conversion may be okay, but what about its speed? The difficulty is converting 0-10V to +/-5V and providing the necessary (but unspecified) drive.
Well, 0-10V is the same as +/-5V, in terms of range.

Most likely that's what the driver board is for.

Or a simple op-amp circuit. The classic textbook design would work, but there are a lot of examples:

https://www.electronicspoint.com/forums ... tial.7947/

And what do you mean by speed? The basic frequency of the PWM waveform will be dictated by the hardware, then its duty cycle generates the desired output.

User avatar
davidcoton
Posts: 6543
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 9:56 am

ame wrote:
Fri Sep 17, 2021 9:35 am
Well, 0-10V is the same as +/-5V, in terms of range.
Yes, but I've already explained why you can't just introduce a pseudo-ground at the 5V level.
Most likely that's what the driver board is for.
Which driver board? Where is its spec? Without it, this is guesswork and speculation, which is not a good design engineering method.
Or a simple op-amp circuit. The classic textbook design would work, but there are a lot of examples:

https://www.electronicspoint.com/forums ... tial.7947/
Yes, but that is my point -- an extra level of electronics is required. And why introduce 10V with an extra supply voltage when you want +/-5V? It would be better to use a PWM - 0-5V module with the op-amp circuit adjusted accordingly. (BTW, I find the text-based circuit diagrams in that link utterly unreadable.)
And what do you mean by speed? The basic frequency of the PWM waveform will be dictated by the hardware, then its duty cycle generates the desired output.
Speed: how quickly can you output PWM samples from the Pi (hardware and software), and how quickly will the analogue output from the module settle? The servos can take up to 18k levels per second, but I think the requirement will be enough levels per second to get a flicker-free image (assuming the intended application of drawing images). Get this wrong, and you risk triggering epilepsy in susceptible individuals.
Location: 345th cell on the right of the 210th row of L2 cache

ame
Posts: 3724
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to get a +/-5V analog output from the PWM

Fri Sep 17, 2021 10:33 am


Return to “Beginners”