Motor speed control mosfet

dc motormosfetmotor controllerraspberry pi

I have a Raspberry Pi and I want it to control DC motor speed. I make the pi output 3×3,3V for controlling the speed. I need circuit that works like this; when one output gives 3,3V motor have 6V, when two output pins gives 3,3V motor have 9V and when all output pins gives 3,3V motor have 12V. Can this be archieved with one mosfet and some resistors or do I need to buy three transistors and 6V and 9V regulators. Input voltage is 12V. I hope you guys get what I'm trying to achieve.

Ihave this mosfet now, I can use it for on/off switch to my motor when outputting 3,3V from one GPIO pin to the Gate. If I use three of these, one with 6V regulator, one with 9V regulator and one without any will it work? My motor is Lego XL motor so it does'nt draw so much current.

Best Answer

For a single MOSFET solution you should feed the motor from a +12V supply. Then have the microcontroller generate a PWM signal with varying duty cycles to generate an effective drive to the motor to correspond to the desired 6V, 9V and 12V drive levels.

Clearly for the 12V to the motor the PWM would be at or close to 100% duty cycle. For the 6V equivalent drive to the motor the duty cycle of the PWM signal would be likely to be in the 45 to 60% duty cycle range. For the 9V drive the PWM would be set to some duty cycle in between the 6V and 12V settings.