Pages: [1]   Go Down
Author Topic: Stuck with H-bridge, PWM and Direction control for DC motor.  (Read 1156 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: