Arduino Forum

Using Arduino => General Electronics => Topic started by: Gadgeroonie on Aug 02, 2020, 03:19 pm

Title: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 02, 2020, 03:19 pm
Hi guys,

I have a signal to drive a servo motor

The signal is a pwm and a direction pin (0 or 3.3v)

The servo driver I have is not compatible and requires a negative voltage to turn counter clockwise and a positive voltage to turn clock wise

If there a way to flip the voltage to negative when the direction pin is enabled ?

Perhaps I could use a simple h bridge and use that to flip the signal ?
Title: Re: Reverse a pwm signal to negative ?
Post by: MarkT on Aug 02, 2020, 03:26 pm
Link to servo driver datasheet?
Title: Re: Reverse a pwm signal to negative ?
Post by: JCA34F on Aug 02, 2020, 03:27 pm
Arduino cannot produce negative voltages, post a link to that controller.
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 02, 2020, 04:08 pm
The servo driver is a d200s

Uses the same manual as the d100s

https://www.manualslib.com/manual/1640073/Dvs-Ds100s-Series.html
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 02, 2020, 04:09 pm
It appears it works with negative voltages when in torque mode
Title: Re: Reverse a pwm signal to negative ?
Post by: Paul_KD7HB on Aug 02, 2020, 07:49 pm
It appears it works with negative voltages when in torque mode
The schematic shows all input signals are opt-isolated, you statement makes no sense. Are you sure you are using what you linked to?

Paul
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 02, 2020, 09:11 pm
The schematic shows all input signals are opt-isolated, you statement makes no sense. Are you sure you are using what you linked to?

Paul
Er yes

4 inputs are optoisolated the rest are not

Regardless, i am asking how to reverse a signal voltage

Do u have any suggestions ?
Title: Re: Reverse a pwm signal to negative ?
Post by: Paul_KD7HB on Aug 02, 2020, 09:19 pm
Er yes

4 inputs are optoisolated the rest are not

Regardless, i am asking how to reverse a signal voltage

Do u have any suggestions ?
I see the following inputs:

1. servo enable
2. Pulse signal
3. Direction signal

No fourth input on the document.

But to answer your question about reversing a signal voltage, a single transistor will invert the digital signal.

Paul
Title: Re: Reverse a pwm signal to negative ?
Post by: AJLElectronics on Aug 02, 2020, 09:19 pm
Regardless, i am asking how to reverse a signal voltage

Do u have any suggestions ?
Ignoring all the other sensible advice you have been given, a simple inverter will turn a digital signal "upside down".

The other piece of advice I can give you is to check your keyboard, as the Y and O keys appear to be intermittent.
Title: Re: Reverse a pwm signal to negative ?
Post by: Wawa on Aug 03, 2020, 12:43 am
Didn't read the document, but an opto could be normally off when connected between pin and ground, and normally on (inverted) when connected between pin and VCC.
Leo..
Title: Re: Reverse a pwm signal to negative ?
Post by: MarkT on Aug 03, 2020, 01:15 am
Hi guys,

I have a signal to drive a servo motor

The signal is a pwm and a direction pin (0 or 3.3v)

The servo driver I have is not compatible and requires a negative voltage to turn counter clockwise and a positive voltage to turn clock wise
Well that's not the case is it - the position mode wiring diagram on page 4 clearly shows a standard
step/direction opto-isolated interface....
Title: Re: Reverse a pwm signal to negative ?
Post by: TomGeorge on Aug 03, 2020, 04:38 am
Hi,
Have you tried a connection where the direction terminals are either connected to 5V or left open.

-5V is not the case, it is a simple logic HIGH/LOW to give you the two directions.
The terminals are polarised to make sure you activate the opto.
The wires are shown zig-zagged because they represent twist pairs.

It will be interesting to see if 3.3V will be enough.

So forget about -5V needed.

Tom.... :)
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 03, 2020, 09:33 am
The diagram in the manual is for position mode

Torque mode uses different pins

Pin 5 is for the torque voltage

‐‐-------------------

What i want to do is flip a 'analogue' voltage to negative

Ie 0.15 volts becomes -0.15 volts when the direction pin is enabled
Title: Re: Reverse a pwm signal to negative ?
Post by: AJLElectronics on Aug 03, 2020, 09:54 am
What i want to do is flip a 'analogue' voltage to negative

Ie 0.15 volts becomes -0.15 volts when the direction pin is enabled
Except that the concept of 0.15V is nonsense in this case. PWM is a digital signal. It stands for Pulse Width Modulation. It moves between logic 0 and logic 1 only.
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 03, 2020, 11:57 am
Except that isnt the case

The voltage is cleaned from a pwm to a smooth analogue voltage using a DAC
Title: Re: Reverse a pwm signal to negative ?
Post by: skyvan on Aug 03, 2020, 05:48 pm
Except that isnt the case

The voltage is cleaned from a pwm to a smooth analogue voltage using a DAC
Where is this DAC ?

I see nothing in the documentation about needing negative drive voltages. The motor is driven by A/C so it makes no sense to drive anything with a negative value.  All the input signals go through opto isolators and will only work with positive signals. I don't understand where pwm comes into this. Please elighten me .

A circuit connection diagram would help.
Title: Re: Reverse a pwm signal to negative ?
Post by: Paul_KD7HB on Aug 03, 2020, 06:31 pm
Where is this DAC ?

I see nothing in the documentation about needing negative drive voltages. The motor is driven by A/C so it makes no sense to drive anything with a negative value.  All the input signals go through opto isolators and will only work with positive signals. I don't understand where pwm comes into this. Please elighten me .

A circuit connection diagram would help.
Good luck on getting a straight answer. I give up.

Paul
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 03, 2020, 10:39 pm
The manufacturer has told me it needs a positve and negative voltage to drive cw and ccw

A dac cleans the signal and makes the operation smooth

‐---------------------------------

My question is how to flip a voltage to negative nothing about the servo driver(posting the manual has just confused the issue, its a rubbish manual tbf)

Title: Re: Reverse a pwm signal to negative ?
Post by: skyvan on Aug 04, 2020, 12:18 am
The manufacturer has told me it needs a positve and negative voltage to drive cw and ccw

A dac cleans the signal and makes the operation smooth

‐---------------------------------

My question is how to flip a voltage to negative nothing about the servo driver(posting the manual has just confused the issue, its a rubbish manual tbf)


If you really are using a DS100S as you indicated and linked to earlier then nothing you have said about the design makes any sense at all ! Nothing at all. You talk of cw and cww but I can't find them at all. You talk of using a DAC but I can't see where it fits into your system especially if you say it needs to provide negative and positive drive.

For anyone to help you you need to provide a scematic of how you think you are going to connect it all together.

Bye
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 04, 2020, 12:32 am
I dont want any help regarding the DS200s

(The servo will work without a DAC but you get a less smooth motion)

Why does everybody want to focus on the servo drive

I asked for suggestions on how to turn a positive analogue signal to negative
Title: Re: Reverse a pwm signal to negative ?
Post by: skyvan on Aug 04, 2020, 12:39 am
I dont want any help regarding the DS200s

(The servo will work without a DAC but you get a less smooth motion)

Why does everybody want to focus on the servo drive

I asked for suggestions on how to turn a positive analogue signal to negative

OK - I will ignore the DS200 but I now have no idea how you connected your Arduino to your DAC or your DAC to your controller or your controller to your  motor. Also, you don't say which DAC or which controller needs the negative input signal or which motor you are driving.  It still sounds nonsense to me; maybe a block diagram and a list of hardware parts would help.

And, since you are using a DAC,  where does PWM fit into all of this.
Title: Re: Reverse a pwm signal to negative ?
Post by: MAS3 on Aug 04, 2020, 01:15 am
You can't do what you are asking.
It's also very unlikely that what you are asking really is what the module needs.

Assuming the module has all inputs isolated, including isolation between each input pair, you may approximate what you are asking.
You would need 2 Arduino PWM pins per input.
Connect one to the +terminal, and the other to the -terminal.
Now, keep output 1 to PWM 0 or LOW, and send out any value through output 2.
Sending your values to output 1 while keeping output 2 LOW, will measure as a reversed voltage when using a multimeter.
But that isn't actually a negative voltage.

Also, remember that a reversed PWM signal as mentioned in posts above this one will not result in a negative voltage, because that's not possible at all with PWM.
If you're expecting this, you might need to read up on what PWM is and how it works.

Having said this;
Dissclaimer:
Any and all risks are for you.
Me nor any participant of this forum, nor the Arduino company can be held accountable for any damages which may occur to any part of your installation when trying this
.

You will probably be using the hardware outside of it's design parameters which might lead to destruction of the lot.

Also, none of the answers given in this thread until now and including this one, are condescending or an insult toward you.
They are all attempts to either get some more detailed information about what you've got and what you really want to do, or just a plain answer to the questions asked (the answer may not be what you hoped it to be).
Title: Re: Reverse a pwm signal to negative ?
Post by: TomGeorge on Aug 04, 2020, 02:17 am
The diagram in the manual is for position mode

Torque mode uses different pins

Pin 5 is for the torque voltage

‐‐-------------------

What i want to do is flip a 'analogue' voltage to negative

Ie 0.15 volts becomes -0.15 volts when the direction pin is enabled
This is the OPs problem.
I understand that using this controller in Servo Torque Control mode, it uses Pin 5.
As with many industrial servo controllers the torque control is an analog signal that usually goes from -10V to +10V.
In torque control, Accelerate AND Decelerate are one continuous variable, to enable positive and negative torque to rapidly speed up and slow down a servo.
So the Arduino, if you choose to use one, needs to via a buffer/converter circuit, produce a DC voltage from -10V to +10V or what ever this controller needs to do torque control.
(Speed control is a totally different animal which we are mostly familiar with.)
These days most control is by mobus or some manufacturer unique comms bus.

To do torque control do you have a am External Brake resistor or is it an Internal one?
Tom... :)
PS I hope I got that right, the manual really is lacking in info on control, lucky you could talk to a "sales engineer."
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 04, 2020, 11:34 am
This is the OPs problem.
I understand that using this controller in Servo Torque Control mode, it uses Pin 5.
As with many industrial servo controllers the torque control is an analog signal that usually goes from -10V to +10V.
In torque control, Accelerate AND Decelerate are one continuous variable, to enable positive and negative torque to rapidly speed up and slow down a servo.
So the Arduino, if you choose to use one, needs to via a buffer/converter circuit, produce a DC voltage from -10V to +10V or what ever this controller needs to do torque control.
(Speed control is a totally different animal which we are mostly familiar with.)
These days most control is by mobus or some manufacturer unique comms bus.

To do torque control do you have a am External Brake resistor or is it an Internal one?
Tom... :)
PS I hope I got that right, the manual really is lacking in info on control, lucky you could talk to a "sales engineer."
Thank you Tom - you undersrand the problem. (Sadly lots of posters have been rude and obnoxious. I guess some people are engineers because of the lack of interpersonal skills)

The manual really sucks, i only got this far by getting technical support.

Yes it has a maximum of -10 and +10 volts range

(There are options for gain so you can make 3.3v full range)

It appears I can use a simple H bridge and control the voltage - effectively treating the signal as a brushed dc motor !  It will flip the polarity and control the voltage

The DAC i have may have to be dropped unless it can smooth a negative voltage

There are other ways to clean the signal like with a filter and the servo driver has a built in smoothing function.

The servo does indeed have an internal braking resistor and it can be swapped for an external one also.

I reckon I could control the device using the rs485 port but there is no data at all on the protocol

Thank you for your support and understanding
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 05:07 am
You need an external power supply to provide a negative voltage source, these are available as small switcher power supplies and can be followed by a linear regulator if really clean DC voltage is required. A simple transistor level shifter circuit can then be used to drive an analog switch to generate the negative PWM signal. The simplest circuit is a PNP transistor with the base connected to ground through a suitable resistor. The Arduino output then drives the emitter of the transistor and the collector goes down to the negative part of the circuit.
Because the current is probably quite low, a 2N3906 with a 3.9k resistor to ground is probably suitable. The collector will also require a load resistor and two clamp diodes. If the negative voltage is -5 volts, a 470 Ohm resistor should be suitable. Both diodes will have their anodes connected to the collector. One diode will have its cathode grounded while the second diode will connect to the load resistor. The other end of the resistor will then go to the negative supply. The PWM signal will be taken from the top of the resistor. This will give a 0 to the negative supply voltage output. This may cause some minor distortion of the PWM signal although the 2N3906 is quite fast and if good quality signal diodes like 1N4148s are used there should be no problem with them.
Title: Re: Reverse a pwm signal to negative ?
Post by: TomGeorge on Aug 09, 2020, 10:23 am
Hi;

@azeemanhow about a schematic, a picture is worth a thousand posts.

@Gadgeroony have you got the hardware?
Have you connected anything up to see if you have some sort of control?

Tom.. :)
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 09, 2020, 12:54 pm
Thanks for the suggestions guys

I am going to try the h bridge next week and then consider building a powersupply withba negative rail

I will keep you posted
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 01:35 pm
The clamp diodes are a mistake, just a voltage divider on the collector is required, a schematic is attached as well as the specification for an isolated 5v supply to generate the required negative voltage. All parts should be readily available from DigiKey.
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 05:10 pm
I've looked at the manual and now understand what you are trying to do. The analog torque input is supposed to go across a current sense resistor or an output from a torque sensor such as a load cell with amplifier. The input voltage doesn't go negative and instead is an analog voltage that will vary over a range that is not specified in the manual, but I assume is a 0-5V range which is typical for this type of control. The controller uses this in a feedback loop to control the servo drive current.
An example would be a screw gun where the both torque and rotation are being measured. Rotation is measured by the encoder while torque is measured by a load cell with an analog voltage output to the drive.
Another use is a tachometer which is essentially a generator with the DC output voltage proportional to the rotation speed which is also used in control loops where an encoder signal is not available or more precise servo control such as in CNC applications is required.
Putting in a negative voltage might destroy the drive input and is definitely not recommended.
I'll prepare a new schematic and post it later to demonstrate how to generate a precision low level analog signal from a PWM output.
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 09, 2020, 05:44 pm
The torque control is -10v to +10v

Using pins 5 and 15

Negative is ccw
Positive is cw
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 06:19 pm
That's possible if the input is intended to go to a tachometer with a very wide range output. What matters then is the acceptable common mode range. Each input could go from 0 to 10 volts giving a differential range of +/- 10 volts. The common mode voltage would be 5 volts in that case.
Another possibility is each input goes from -10 to +10 with a differential range of +/- 20 volts and a common mode voltage of 0.
Regardless, the inputs have to be differential with a high common mode voltage tolerance to withstand industrial conditions where ground voltages are completely unpredictable and twisted pair cabling with differential signalling is common. I also suspect that the input can tolerate a wide range of input voltages and using a single 10 or even 20 volt supply as the PWM source with a differential PWM signal would be acceptable to the drive. It's also possible that even 5 volt signal levels with a 2.5 volt common mode signal is adequate. The Arduino can't drive the higher signals directly but it can drive two sets of switches to generate the two PWM signals. As long as the PWM outputs are complements of each other, the drive should be happy.
The outputs of the PWMs will need to be filtered and the easiest way to do this is by using an RC filter. For better filtering, multiple stages can be used, but this increases the source resistance. Do you know what is the input resistance of the controller? Assuming that it is DC coupled, a simple test is to put 10 volts in through a 10k resistor and measure the voltage drop across the resistor. I suspect there will be some kind of voltage divider on the input followed by an instrumentation amplifier to give good common mode rejection. This should give an input impedance in the 100k or higher region.
Regardless of how the filtering is done, the input impedance needs to be known to properly specify the filtering.
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 07:09 pm
I've been working on a somewhat related project requiring a differential PWM signal and did a fair amount of research. I found that the simplest PWM filter is a four stage RC network with all resistor and capacitor values the same. I wrote a simple Python program along with Numpy to calculate the required circuit values scaled to a 1 Hz PWM. For example, if your PWM frequency is 10 kHz, the RC time constant would simply be divided by 10k. The R and C values are then dependent on the source impedance restrictions.
I calculate RC should be 0.59 for an 8 bit resolution PWM. If the PWM frequency is 10k, then the RC value would be 59 uS.  If the resistors are 1k each then the capacitors would be 59us/1,000 = 59 nF.
If the resolution is increased to 16 bits, then greater filtering is required to reduce ripple and the PWM frequency will generally be lower.
The required RC is 2.54. If the PWM frequency is 500 Hz and the resistors 1k, then the capacitors would need to be 2.54/(500*1,000) = 5.1 uF. Tiny 10 uF ceramic capacitors are readily available which means even smaller resistance can be  used to give the same RC constant.
I've also attached an Arduino program to demonstrate the PWM in action. Hopefully this is helpful. I haven't been able to thoroughly test everything since a lot of it is quite theoretical and this is part of a larger project, but it's good to put it out in the wild and hopefully others can improve on it.
Title: Re: Reverse a pwm signal to negative ?
Post by: Gadgeroonie on Aug 09, 2020, 08:32 pm
Interesting stuff ! What is your project ?

The pwm in this instance is 16.4 khz iirc
Title: Re: Reverse a pwm signal to negative ?
Post by: azeeman on Aug 09, 2020, 11:52 pm
The PWM frequency is the PWM waveform frequency, not the higher clock frequency. This determines the fundamental harmonic of the PWM waveform regardless of the duty cycle. As the duty cycle changes, the energy in each harmonic will change with more energy going into the higher harmonics. Regardless, the worst case scenario is when the duty cycle is 50% as this will give the greatest ripple.
For an Arduino using a 16 Mhz clock and 16 bit resolution, the maximum PWM frequency is 122 Hz if I remember correctly. The maximum PWM frequency doubles with every bit decrease in resolution. There is a formula in the ATMega documentation for calculating this for the different PWM setups and counters.
My project is to create a nullmeter for measuring low level voltages. By using a chopper and AC amplifier it should be possible to measure in the microvolt range.
The PWM signal will be filtered and then divided down to the millivolt range, chopped into an AC signal and fed into one input of an AC differential amplifier. The input signal will also be chopped and fed into the other input of the amplifier. The difference will be measured by the A/D and used to control the PWM. In theory, it should be possible to measure over a 10 mV range with 16 bit resolution.
It sounds simple, but at 10 mV, the LSB is around 135 nV and fairly substantial amplification is required. Also, fairly substantial filtering to make sure the ripple doesn't make the PWM signal too noisy. I found that a single RC stage with sufficient ripple attenuation would have a very poor frequency response. By increasing the number of stages I could increase the attenuation while still keeping a workable frequency response. I also wanted to avoid using a lot of op-amps as they add a lot more complexity and increase errors.
Hopefully you don't need super high resolution because the frequency response becomes quite low when substantial filtering is used, with a response down in the 1 Hz range. You might have to experiment with the filtering to finesse it to where the controller can accept the ripple while keeping a reasonable frequency response.