Controlling 0-10v with Arduino

A few years back Grumpy Mike showed a circuit to control 0-10v with the following circuit.

But when I look at this circuit it appears that it would run opposite of the PWM. So if the PWM is set to 255 the output is 0v but if the PWM is set to 0 then the output is 12v. But I would prefer if the analog output ran the same as the PWM. So I was wondering if you could give me your opinion if this would work....

Or you could try to change the NPN transistor to a PNP with a pull down resistor to the base.

No, that won't work. You're not switching (modulating) the 10V with that.
You could place an inverter between the Arduino output and the G_M circuit.

Or you could make the correction in software.

byte PWMval;

analogWrite (pin, (255-PWMval));

Or before you issue a analogWrite() function, you could just use a map() function to convert PWM duty cycle values from 0 to 255 to 255 to 0.

Lefty

I suppose an inverter would work. I need both Analog 0-10v and PWM to be in synch because I am running 8 devices (4 analog and 4 PWM) and I only have 4 PWM lines after setting up the lcd.

But I am curious why the NPN won't work in the pic I posted. Can you please explain?

Thanks,
Robert

Because it wont output exactly 0-10V it will output somewhere around +- 4.3 V.

if you want you can use Grumpy Mike's schematic but you would need another NPN to invert the NPN being used to power 0 - 10V

so basically your adding an inverter before the amplifier.

I am sorry but I am kind of a newb here. Can you explain why the voltage would drop like that? I checked the data sheet for the transistor and it doesn't have a voltage drop like that.

But I would prefer if the analog output ran the same as the PWM.

Why on earth?
Suppose you have a variable called out and you would normally do:-

analogWrite(pin,out);

You simple do:-

analogWrite(pin,255-out);

Your alternate circuit will not work because, for a start, there is no current path from the emitter.

That voltage is comming from the 5 volts in from the arduino, minus the diode inside the transistor, (0.7V), so 5V - 0.7V = 4.3V.
There is also the Vce to take into consideration, the voltage between Vc and Ve, which is calculated by VCC - Ve = Vce. But there is a little more to it than that though. Saturation, resistor values, the Beta value of the transistor, stuff like that.

But for your project, use Grumpy Mike's schematic, and like I said, add another NPN to the NPN controlling the 0 - 10V output.

So in a nut shell.

(5V) (10V)
| Z
Z Z
Z | / -----------------O
| /---------VVV------|< |
---|< | \ ---
| \ v ,---,
v | |
| Z (GND)
Z Z
Z |
| (GND)
(GND)

Please excuse the terribly made schematic

Thanks for the fast reply Mike! But wouldn't there be a path to ground when connected to the device?

So...Like this then?

When transistor U4 turns on, it shorts out the supply. So if you want to do that put a resistor between the collector ans the 5V.

ModAquatics:
I am sorry but I am kind of a newb here. Can you explain why the voltage would drop like that? I checked the data sheet for the transistor and it doesn't have a voltage drop like that.

  1. Why bother, except perhaps as an exercise in electronics? Software is free (almost), hardware costs money, space and power. Use this:
void analogWriteReverse(uint8_t pin, int value)
{
  analogWrite(pin, 255 - value);
}

Then use analogWriteReverse(pin, value) instead of analogWrite(pin, value).

  1. Alternatively, you can program the chip to generate reverse pwm instead of normal pwm.

  2. Alternatively again, connect the RC network to the Arduino PWM pin, then use an op amp in the non-inverting configuration to amplify the voltage by a factor of 2. This has the advantage that it is less sensitive to the load you put on the output. Also you can use a smaller capacitor.

But I would prefer if the analog output ran the same as the PWM.

Then use analogWrite(pin, -dc); rather than analogWrite(pin, dc);

dc42:
3. Alternatively again, connect the RC network to the Arduino PWM pin, then use an op amp in the non-inverting configuration to amplify the voltage by a factor of 2. This has the advantage that it is less sensitive to the load you put on the output. Also you can use a smaller capacitor.

This is the way I would go, simple op-amp voltage doubler like this one http://arduino.cc/forum/index.php/topic,10456.0.html

This is the way I would go, simple op-amp voltage doubler

It is not a voltage doubler it is a times two amplifier. You need to be able to drive the load direct from the amplifier's output. Not a very good idea I would have thought.

Thanks Everybody. This was my first post on this forum. I am very happy to see so many responses (and quick!). It is refreshing to be on a forum with an active community of folks helping each other.

Mike, what if I used your original design but switched the NPN with a PNP transistor? Wouldn't that work? Hazardsmind suggested that earlier but I didn't realize that PNP's are not switched on unless the base is brought to 0v.

Robert

No dont change the NPN to PNP, either change the code or add the other NPN.

dhenry:
Then use analogWrite(pin, -dc); rather than analogWrite(pin, dc);

What do you think analogWrite() will do with a negative value?

Any value used for the AnalogWrite function thta is outside the range will be rolled over. So 256 becomes 0 and -2 becomes 254. The only values (without modification) can be 0-255.