1

I am making a washing machine by controlling motor speed using H-Bridge . The signals to H-Bridge's MOSFETs are controlled by a micro controller PICAXE 14M2.

The Motor is coupled with a generator and a bucket that takes the load. Default duty cycle is 25% . At 50% motor stops and greater than 50% the rotation of motor changes.

Now, what I want to do is , When load is added to the bucket the motor should maintain its speed and in order to maintain the speed I want to control the duty cycle.

So, if load increases, resistance to motor increases, which means bucket should slow down, making generator to produce less voltage .

Now, I need to increase the duty cycle, so motor increases the speed to catch up with the default value.

Unfortunately, I am unable to perform the close loop function . Can anyone please help me out ....

PS. I am using two 12V DC motors. One acting as motor to rotate the bucket (which is also coupled with other motor) and other motor is acting as generator to get the feedback

Thanks.

I am using the following code:


setfreq M32   ' 100 kHz Frequency

main:
if pinB.5 = 1 then goto Closeloop
goto main 

***************************************************************************

Closeloop:          

    symbol duty = b2
    let duty = 79
    gosub closeloop1

closeloop1:

    for b11 = 1 to 100
    hpwm 1,0,0,79,duty
    readadc C.4, b22    ` Read generated voltage from pin C.4

    IF b22 > 204 then gosub stepdown    'if Generated voltage > 4 V , stepdown the duty cycle

    IF b22 < 153 then gosub stepup      'if V< 3 V, stepup the duty cycle

stepup: ` Increase the duty (So speed is increased) if gernerated voltage is less than 3V

    duty = duty - 5 
    goto closeloop1 

stepdown:  ` Decrease the duty (So speed is reduced) if gernerated voltage is more than 4V

    duty = duty + 5 
    goto closeloop1

next b11

nekomatic
  • 5,988
  • 1
  • 20
  • 27
Tarik
  • 19
  • 2
  • I'm not getting you: the second DC motor is to get the feedback: does it means you read out the back-EMF of that motor? If So use a transfer function to calculate the gain of your first motor command. – LPs May 27 '16 at 15:36
  • There are far too many things wrong. Ask a class mate to help you with this project, find one that knows Basic well enough. – Hans Passant May 27 '16 at 16:34

1 Answers1

0

Before we look at your control algorithm, there are some problems that need fixing with your PICAXE Basic code. You gosub to a label which is the next line of the program anyway; you're using goto to jump out of a for loop; and you use gosub to call a subroutine but then goto to jump somewhere else rather than return to return from the subroutine. These may not cause an error but they suggest you haven't clearly thought out what you want the flow of your program to be.

If your for loop isn't interrupted by those gotos it will execute 100 times and then finish, after which the pwm output will continue at the last duty you set it to but the program will no longer be doing anything. There's no pause or other time delay in the loop so that will happen in a matter of milliseconds. Why are you looping 100 times and what do you want to happen after the last time round the loop?

Finally you're either increasing or decreasing the duty factor to try and speed up or slow down the motor, but you're not checking that you haven't decreased it below 0 or above the maximum value you want it to take - if a byte variable is 0 and you decrease it by 1 it will wrap round to 255, and so on. If you look at the documentation for hpwm you'll see that the duty factor value actually ranges from 0 to 1023 so you'll want to use a word variable for this anyway, not a byte.

The way in which you're trying to stabilise the speed isn't the best approach in my opinion, but it should work after a fashion - if you put a suitable time delay in your loop - so try and get your code doing what it's supposed to be and then see how it works in practice and whether you could improve on it.

I assume this is an educational assignment so you're supposed to be developing it for yourself rather than getting a solution written for you on this site, but if you have further questions about the hardware or software for this project you'll probably get better answers on the PICAXE forum, or possibly on EE Stack Exchange. Be prepared to post a circuit diagram of your hardware though, and to explain specifically what you've tried and what happened.

nekomatic
  • 5,988
  • 1
  • 20
  • 27