Go Down

Topic: Stuck with H-bridge, PWM and Direction control for DC motor. (Read 1 time) previous topic - next topic

njakts

Hi there!

here is what I have:
Internal combustion engine

what I need:
keep rpm's constant

what I have done:
wrote code that reads rpms by duration between HIGH pulses, works great
duration is Setpoint for PID
PID controller puts out pwm signal trying to keep Input same as Setpoint

where I am stuck:
throttle control...
I have a hobby servo, but thats a little too weak, so I came up with an idea to use windshield wiper motor like this one:

as throttle control motor where the motor output arm is connected to throttle body varying throttle opening.

I know I have to use H-bridge to control the motor, but I dont understand the software part...
I understand I need two outputs from arduino, each for one motor direction...

How to make PID output so it controls the motor ir both directions varying motor speed.
this is the part where I am really stuck:
when pid 1 is rising, pin 2 should stay 0
instead of pin 1 dropping its value, it should immediately stay 0 and pin 2 should rise instead, in that way both pins wont be ''HOT'' in the same time...

do i need to monitor pid's value and make an ''if'' statement, where prewious value is monitored, and if it is lower turn it to 0?
or is there an easier way? like, when PID is rising pin1 is rising and when PID is dropping pin2 is rising?

thanks ;)

dc42


do i need to monitor pid's value and make an ''if'' statement, where prewious value is monitored, and if it is lower turn it to 0?
or is there an easier way? like, when PID is rising pin1 is rising and when PID is dropping pin2 is rising?


Assuming that the PID software produces a value that can be positive or negative, you use an if-statement that tests the sign of the output. If it is positive, then pass it to the first PWM pin and set the second PWM pin to zero. If it is negative, pass its negation to the second PWM pin and hold the first at zero. In either case, limit the the value you write to 255.

You will probably need to set the I term to zero for stability, because the motor already behaves like an integrator.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

MarkT

You probably would do well to add some sort of an encoder to that motor - otherwise you'll not be able to judge its position programatically - so you'll have an unwanted unknown to deal with.  I think it will be beefy enough ;)
[ I won't respond to messages, use the forum please ]

Go Up