I am using linear potentiometer to control the speed of a DC motor. I am using the following schematic.

An ATmega328P receives the value from linear potentiometer via analog read. This ATmega328P transmits the value via CAN. Other ATmega328P receives it and analog writes the values via optocoupler (4N35) to the motor controller (Kelly's KDH14601E). The motor controller uses this value to control a 110V DC motor (lynch LEM 200 D135 RAGS). The High voltage and low voltage sides are completely isolated in the motor controller.

When the motor is disconnected or is in no load condition, everything works fine. But when there is load on the motor, both the microcontrollers stop responding. They basically freeze and the motor rotates at a constant speed. Sometimes the value fed to motor controller is corresponding to the last read value and sometimes a value which is not possible according to the code of microcontroller. I made some changes in the setup and have achieved following results-

  1. Initially I was not using the optocoupler and the microcontrollers were hanging in no load condition also.

  2. If I use a different LV (Low Voltage) supply for motor controller and optocoupler, everything works fine but I cannot do this in my final setup (I must use only 1 LV battery). In this case, both low voltage sources are completely isolated.

  3. If I use a different LV (Low Voltage) supply for motor controller and optocoupler and connect the ground of both Low Voltage batteries, everything works almost fine. Sometimes the microcontroller reads a value which is not practically possible, but there is no hanging of microcontrollers.

  4. I put a diode in the path which connects optocoupler output to motor controller, but observed no change.


Please help me out with this.

I am adding further details about connections around ATMEGA 328P in the new attachment

P.S.: The motor controller manual states that a potentiometer should be used to feed the controllers, but I cannot directly feed the value of linear potentiometer as I have to make certain modifications to the values.


  • 2
    \$\begingroup\$ Show the circuit you built around the ATMEGA 328P. That's most likely where the problem lies. That in combination with powering the 328 from the same source as the motor. \$\endgroup\$
    – JRE
    Nov 7, 2018 at 18:16
  • 1
    \$\begingroup\$ This may not be related to your current problem, but supplying a PWM signal to a device designed for an analog voltage may not work correctly. Unless the controller is designed to support a PWM input, you may be better off using a low-pass filter on the PWM or using a DAC to supply a DC voltage. \$\endgroup\$
    – ajb
    Nov 7, 2018 at 18:41
  • \$\begingroup\$ @JRE I have added new details about connections around ATMEGA 328P as well as the power suppies to both controllers. Thank You \$\endgroup\$ Nov 8, 2018 at 13:37
  • \$\begingroup\$ @ajb I will try installing a DAC. I was trying to avoid it because when I was using different power supplies the motor controller was working fine with PWM also. Thank You \$\endgroup\$ Nov 8, 2018 at 13:37
  • \$\begingroup\$ There's your problem. No decoupling capacitor for the 328. No time to write up a goid answer. Maybe some one else will explain it in detail. \$\endgroup\$
    – JRE
    Nov 8, 2018 at 14:24

1 Answer 1


If your sketch is to be trusted, you haven't included a decoupling capacitor for the ATmega328P.

That's most likely the cause of your problems - especially since you mention it working correctly if you power the ATmega328P and the motor driver from seperate power supplies.

There are tons of questions and answers on this site about what decoupling capacitors are and how to use them.

You probably need at least a 100nF capacitor from ground to each Vcc pin on the ATmega328P.

Since you show two Vcc pins, you will need two capacitors. Place each capacitor as close as possible to the Vcc pin it serves.

You may also need a single, larger capacitor on the board with the ATmega328P. Say, like, 1 to 10uF.

Try that out, and read up on decoupling capacitors. You will encounter them often in pretty much all kinds of circuits.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.