High Voltage Forum

General electronics => Electronic circuits => Topic started by: kamelryttarn on February 28, 2018, 09:41:26 AM

Title: Closed loop control of DC motor
Post by: kamelryttarn on February 28, 2018, 09:41:26 AM
A while ago I started a build of a simple (or so I thought) magnetic stir plate. I ordered a cheap motor on ebay and a friend helped me to 3d-print a holder for the neodymium magnets. I use and arduino with a mosfet to get speed control by PWM.

The problem was that the magnets locked on to the screws I used to mount the motor in the plastic case so it took quite a bit of force to get it to start so I thought I could use a closed loop to control the speed of the motor. I bought a new motor with a built in magnetic encoder that sends pulses when the motor spins. I wrote a small program for my arduino and connected the pulse output from the motor to one of the hardware interrupt pins. When I tried it I got very erratic behavior that I believe may be caused by the inertia of the rotating axel . Would you agree and do you have any good ideas what I can do to remedy the problem?

To understand the pictures better I will try to explain the code I used. Every time I got a change (either rising or falling edge) from the encoder, the mosfet channel is turned off and the arduino resumes the regular loop that has a pause time (to regulate speed) and the turns the mosfet on again. In the pictures channel 0 is the encoder on the motor and channel 1 is the mosfet driver. The last screenshot is from a test I did where i let the motor spin for a few seconds and the turned the mosfet off to see how long after the power was cut to the motor it still turned.