# How to change the range of voltage?

I am doing a project to use dsPIC as controller to output PWM signal to control motors. I can use driver IC (I used L293D actually) to simply let motors to rotate, but I cannot control the voltage range to control the motor to rotate with all range of speed.

The output of dsPIC PWM pins is in the range of 0V~5V, but for motors, the input range is different.

Assume the range is -10V~10V, I want to change the 0~5V output to -10V~10V (0V->-10V, 5V->10V). Is there a good way to achieve this?

## 2 Answers

Assumptions:

• The circuit has +10V and -10V supply rails available
• Isolation of the dsPIC from the motor power / ground rails is desirable, to prevent back-EMF from frying the dsPIC

The following arrangement would provide arbitrary voltage switching, isolated from the controller side of the circuit:

simulate this circuit – Schematic created using CircuitLab

This will provide an inverted PWM signal to power the motor.

• The PWM signal switches the optocoupler's internal LED on and off.
• This turns the output phototransistor of the optocoupler on and off correspondingly.
• When the PWM signal is high, the opto's transistor conducts, pulling the MOSFET gate low, and thus it behaves as an open switch.
• When the PWM signal is low, the opto's transistor does not conduct, so the MOSFET's gate is pulled high, it behaves as a closed switch, allowing current through.
• The diode across the motor prevents back-EMF from frying the MOSFET.
• Thanks for the clear explanation: ) I am a beginner, I want to ask that is this the standard way to drive motor?(is the current of the circuit in your answer big enough? sorry I don't know how to simulate in circuitLab) May 29, 2013 at 11:24
• @Ricky Since the question does not state any current requirement, there is no way to say whether "current is big enough". However, search Digikey for N-MOSFETs that meet your requirement parameters, and see their datasheets, to find something that suits your design specifications. May 29, 2013 at 12:14
• Sorry for that question, I understand now.And thanks a lot~ May 29, 2013 at 12:42

You have not mentioned any way of driving current into the motors. Boosting the voltage out of the micro pin is not the problem, the problem is the micro pin can only source a tiny bit of current (5mA maybe) whereas even a small motor may draw an amp or more.

By the sound of it you are using a DC motor (not a stepper motor), so the usual way of driving this is with an H-Bridge.

Google will throw up hundreds of motor driver chips, circuits, etc.

• Sorry for not stating clear in my question, I used driver IC to drive DC motor(so the current is large enough). But still I cannot change the driver IC output to the range I want. May 29, 2013 at 11:24
• So, does the chip accept a variable-voltage input or is it a logic-level on/off fwd/reverse affair? May 29, 2013 at 11:31
• The L293D driver IC chip is a logic-level on/off fwd/reverse affair~ (I used proteus to simulate, and I found only this driver IC) May 29, 2013 at 11:56
• @Ricky small dc motors can be speed controlled by connecting a pwm output to the enable input of the L293D. May 29, 2013 at 12:23
• @Ricky the relationship isn't linear, and will depend on the load, the motor's KV (rpm per volt) and inertial effects ( different motors behave differently to being pwm'd rather than having a constant voltage applied ). If you need accurate speed control, you'd have to add feedback, or you can calibrate the system for rough control ( which is good enough for model railways - for each engine, I record the pwm duty for just overcoming friction enough to crawl, slow, medium and fast, then smoothly ramp between it). It depends on your application what you need. May 29, 2013 at 15:04