incPID Routine - Help Needed


Closed Thread
Results 1 to 40 of 64

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Barry,
    I'm still not convinced....
    If the PIC is toggling the output at 100Hz the measured frequency will be 50Hz because it turns the output ON 50 times per second and OFF 50 times per second. Replace the TOGGLE LED1 with LED1 = 1 : PAUSEUS 100 : LED1 = 0 and see if that convinces you it actually IS interrupting at 100Hz.

    /Henrik.

  2. #2
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Henrik,

    Yes, you were right on both instances.

    I now have a nice, stable 100Hz time base and most importantly - I understand why

    Next step is to incorporate the timer/counter setup with the PWM motor drive to count encoder steps.
    From there it is a matter of getting it all to work with the PID routine.

    Once more I am indebted to you, Henrik, and the other forum members for the invaluable assistance. Thank you.

    Cheers
    Barry
    VK2XBP

  3. #3
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi All,

    I am pleased to report that I now have the PID system operating with a timer/counter configuration (100Hz time base) AND a 4 x 20 serial LCD being driven via the 18F2431's EUSART and HSEROUT commands.
    My original design only allowed single direction motor drive but the new design has the motor driven by a MOSFET H-Bridge allowing for forward and reverse direction.

    Henrik, you suggested to limit the pid_Out result to allow only positive drive outcomes for my original design. Now that I have forward and reverse direction capability, should I re-introduce positive and negative pid_Out drive conditions or do you think switching the motor/H-Bridge between forward and reverse state will cause undue stress on the motor?

    Cheers
    Barry
    VK2XBP

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Barry,
    I'm delighted to hear you've got it going, nice work!
    Can we see some photos of the thing or perhaps even a video?

    It depends on the motor, the H-bridge and if you have any sort of current limiting built into the circuit or not. When the motor is turning CW and you apply a voltage to make it turn CCW the EMF of the motor will end up in series with the supply voltage from the bridge.

    IF the motor is doing full speed in one direction and the operator decides it should go full speed in the other direction there will basically be twice the supply voltage across the motor when it starts to decelerate (if you don't apply a ramp on the control signal), if you do have current limiting this shouldn't be too much of any issue but if you're operating this without a current limit there is a chance that you'll damage the H-bridge and possibly the motor (depending on it's peak current rating etc etc). (It might even throw the chuck of the spindle....)

    How do you drive the H-bridge? Are you using the PCPWM module in full bridge mode?

    If you are controlling position then I'd say you need 4 quadrants but if you're "only" controlling velocity, though both CW and CCW, then I think you'll be fine limiting the output to only positive (or only negative, depending on direction). The motor will still be able to "brake" and regenerate, you just can't generate torque in one direction while it's turning in the other.

    /Henrik.
    Last edited by HenrikOlsson; - 25th September 2013 at 11:44.

  5. #5
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Henrik,

    The whole system is rather messy at the moment as a result of the changes made during prototype development. I am happy to send some photos once I have it back in some resemblance of order
    The power drive for the 1500W motor will ultimately be fed from rectified 240V mains and three large filter caps for a supply rail of around 360Vdc. Right now I am merely driving a 200W 24 volt scooter motor of a 3A bench power supply.
    I have overcurrent protection built in to the design by sniffing voltage across a low resistance between the bottom of the H-Bridge and ground. This circuit is designed to trip under overcurrent situation (eg motor stall) but that is the extent of it.

    The H-Bridge consists of four APT5010LVR MOSFETS fed by a pair of NCP5181P half-bridge drivers. The 18F2431 feeds the MOSFET drivers from the PCPWM module in full bridge mode. For added safety I have the control circuitry optically isolated from the power circuitry.

    I am a little confused by the statement in your last sentence - If I limit the output to only positive (or only negative, depending on direction) how is the motor "still able to brake and regenerate? Do you mean that with pid_Out = 0 the two bottom "legs" of the H-Bridge effectively provide a short circuit across the motor terminals thus providing a brake force via back EMF? Please explain.

    Cheers
    Barry
    VK2XBP

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Barry,
    It depends on how you are driving the bridge.
    If I understand correctly you're feeding the MOSFETs (thru their drivers) from two of the PWM generators - both in complementary mode, ie four outputs from the PIC. PWM0 & PWM1 are feeding the left leg while PWM2 & PWM3 are feeding the right leg of the bridge (or the other way around). Is that correct so far?

    Now, what do you do when you want the motor to turn clockwise (or counter clockwise)?
    Do you set one of the PWM generators to 0% (effectively turning on the LOW side switch of that leg) and then apply the output of the PID-filter to the other PWM generator? If you ARE doing this then the motor IS shorted thru the lower two switches during the off-period of the PWM cycle (and, obviously, when the dutycycle of both generators are 0). This will brake the motor but won't regenerate (I think), ie it won't feed energy back to the powersupply. Instead, the energy will be absorbed by the armature resistance of the motor, the rds-on of the MOSFET, wiring, connectors and so on. If this IS what you're doing please note that the braking current this generates does not flow thru your current sense resistor. If the motor is spinning, generating 200V of EMF and you suddenly set both dutycycle registers to 0% the motor will be shorted thru the bottom two switches, how much current will that result in?

    The other option is to run the bridge in what's called locked antiphase mode. In this mode you typically use a single PWM generator and drive one diagonal pair of switches with the "true" output and the other diagonal pair with the inverted output.
    In this mode the bridge switches between the two diagonal pairs during the PWM cycle. When the dutycycle is 50% each diagonal pairs are "on" for 50% of the PWM cycle resulting in a net current of zero thru the motor. When "forward torque" is to be generated the "balance" is shifted so that one diagonal pair is "on" for a larger amount of time during the PWM cycle resulting in "actual" current thru the motor. In this case the motor will brake AND regenerate when the voltage produced by the bridge is LESS than the motor produced by the EMF of the motor. The motor will never be shorted out.

    Phew, I hope I got that right....don't quote me though!

    /Henrik.

  7. #7
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: incPID Routine - Help Needed

    Hi Henrik,

    Thank you for the detailed response.
    Yes, I am using two of the PWM generators - both in complementary mode.

    I have configured my PWM drive per your first description; I am NOT running it in locked antiphase mode.
    I plan do code my program such that the operator (ie me) cannot reverse the motor direction instantly. If the motor is spinning clockwise and the operator flicks the switch to make it spin anti-clockwise, the program will not reverse the direction until the pulse train frequency from the encoder wheel reaches zero - the motor stops spinning. I could also add a short time delay between motor stop and reverse direction.

    When the operator goes from one motor direction to "off" I plan to allow the motor to free spin rather than shorting the motor terminals via the two lower MOSFETS. This should negate any major issues with high current cycles being generated from the back EMF of the motor. If the "spin-down" time is too excessive I will look to ramp down the PWM duty cycle for a more controlled response.

    The circuit will also have an "Emergency Stop" function. In this case the PWM signal is set to zero, the bottom two MOSFETS are turned on and maximum braking is applied to the motor. I should be able to arrange the circuit such that this condition does not fry any part of the H-Bridge but I figure if I really need to hit the Emergency Stop button (worse case scenario for personal safety) then I can live with having to re-build electronics rather than losing a limb, or worse.

    Cheers
    Barry
    VK2XBP

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts