I'm trying to develop a PID controller with Simulink as shown in the image PID. I'm using a PID controller to control a motor via an Arduino Uno and motor driver.

I have the PID output connected to an if statement.

  • If u1 is larger than 0 then output 1 for digital output pin 2 and output 0 for digital output pin 4.
  • If u1 is smaller than 0 then output 0 for digital output pin 2 and output 1 for digital output pin 4.

This changes the direction of the motor so that if the PID overshoots it will change direction. And so on for u1 is smaller than 0.

I also have the PWM signal for the speed of the actuator from 0 being the slowest and 255 as the fastest[]. I forgot to fix the label for it.

I keep getting an error when I try to run it. The error says that I can't run it because of having multiple digital output blocks with the same pin as shown in this image Error in Simulink.

Is there a solution for this?

  • 1
    Why are you even trying to use the same pin for direction as you're using for speed?!?! – Majenko Oct 9 at 13:26
  • I'm not using the same pin for direction and speed. For direction I'm using pins 2 & 4. Speed is using pin 3 using a PWM signal. – Allan Oct 10 at 0:21
  • Then your problem is with using simulink, whatever that is. Ask on a simulink forum, or show us some actual code. – Majenko Oct 10 at 0:32
  • The image shows the code. It uses a graphical programming approach. – Allan Oct 10 at 4:38

You cannot try and have two things controlling one output in two different ways. It just makes no sense. Like trying to have two people steer a car and have one go left and the other right.

I don't quite know what you're trying to do, but under normal usage using a motor driver requires 3 pins (for example the common L239D). Two define the direction and a third (the EN pin on the L239D) controls the speed with PWM.

  • I'm trying to develop a PID controller so that if the output of the controller is higher than 0, the motor moves in say positive direction. Or if the output of the controller is lower than 0, the motor moves in negative direction. And I do have 3 pins, PWM which controls the speed, and the two digital output pins 2 & 4 for direction. – Allan Oct 10 at 0:20

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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