1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

PICMICRO 16F887 --18f2550 USB virtual Comm--

Discussion in 'SimTools compatible interfaces' started by kubing, Oct 20, 2010.

  1. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    hi expert,

    i'm in progress working on MICROCHIP microcontroller to make my own version of Thanos style controller..but im want to ask if i need to STOP (breaking) the motor everytime they need to change direction. btw i use Dual VNH3SP30 Motor Driver Carrier MD03A. your advice will help me repair/improve my programming code before tested on POLULU :blush:
  2. dhweizel

    dhweizel New Member

    Joined:
    Mar 16, 2010
    Messages:
    27
    Location:
    Buenos Aires, Argentina
    Balance:
    339Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    I think that the only proper way to make a motor controller is implement a PID loop, at least a PD loop for a slow motor like a wiper motor
    you can look at

    http://ww1.microchip.com/downloads/en/AppNotes/00937a.pdf
    http://ww1.microchip.com/downloads/en/AppNotes/00964A.pdf

    Most of the available motor are reversible, so you must apply a proportional current to overcome the weight and maintain the position or the motor turns but at position change you must apply a reverse voltage and here is the heavy load in the h bridge.

    You can :
    Reverse the voltage proportionally and hope that the bridge can handle the load for best performance
    Reverse the voltage proportionally and limit the current using pwm
    Short the motor terminal at the bridge so you apply a electrical brake before reverse the voltage
    Let the motor run free to stop and the reverse the voltage


    Regards
  3. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    thanks you 4 detail explanation. I wonder if someone can tell me how thanos controller handle this situation.. I dont have a chance to xperiment. Since i only have microchip dev. Board.
  4. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    The AMC doesn't take this into consideration as far as I know.

    I don't recommend reversing the direction suddenly. This will be equal to connecting two power supplies in series, with a very low resistance load.

    Those IC's have a brake input, so everything is done for you in internally. If you set up the PID gains properly, you won't have any overshoot, therefore you don't have to worry about reversing suddenly. If you want to increase the speed and decrease the reaction time of the positioning, higher gains will mean more overshoot. This is when sudden changes will make your life a lot harder.

    An easy way to brake the motor is to brake it when it comes close enough to the desired setpoint. This impact the positioning accuracy, but it will decrease the overshoot.
  5. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    What do you mean PID gain? my controller read uart-->compare with the current Pot reading--> move the wiper to position. :) can you explain more. I never see PID setting in Xsim profiler.
  6. dhweizel

    dhweizel New Member

    Joined:
    Mar 16, 2010
    Messages:
    27
    Location:
    Buenos Aires, Argentina
    Balance:
    339Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    The PID gain values that Frakk is talking about are the values used to set how hard the controller accelerate and brake the motor to try to stay at the set position, but those are parameters of the controller firmware and are variable for each motor, and static load.

    As i understand your controller is an on-off control loop , If i remember right the AMC is a proportional control loop (the P in the P.I.D. Loop)

    I encourage you to read and understand the wiki article about control systems http://en.wikipedia.org/wiki/Control_system and the good article about PID here in the x-simulator site http://www.x-simulator.de/wiki/Implementing_PID_control_in_Microcontroller as start, then check the microchip App notes that i already posted to fully appreciate the AMC work.

    Regards
  7. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    thank you for information dhweizel..historical memory PID ...10 years since leaving my university never talk about that...here is my progress btw. I think I get it.
    http://www.youtube.com/watch?v=bDmQ5S08w_4
  8. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    is it ok to implement kp only in my case?... or any suggestion :hi: . it quite hard to implement all P+I+D loop. I really meant it.
  9. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    Why wouldn't it be ok?

    The reaction time will be slower, OR, you will have what is called overshoot if the P gain is too high.
  10. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    my pseudo code for 8bit resolution pwm_duty cycle (real one can be up to 10bit with this chip)

    Kp = 5
    error = (uart_in) - (adc_read)

    duty = error x kp

    if duty > 255 then
    duty = 255

    pwm(duty)


    can anybody gimme an advice if i were wrong. :)

    kubing
    Kelantan, Malaysia
  11. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    The logic is right.

    Make sure you take care of signs and direction. If the error is negative, your duty will be negative. You cannot have negative PWM.
  12. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    thank you frakk, the full code i wrote have someting like this, psudo: if duty < 0 then duty * (-1), so i think my duty will always +ve integer by adding this code.
  13. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    testing at 30Khz ...is it posible to run wiper motor at this freq?
  14. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    Yes it is possible.
  15. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    i can say this freq make motor super silent....but i worry high freq gonna kill motor winding.. anyway thanks frakk... more experiment to go..quite busy rite now..want to know if anybody experiment with freq limits before?
  16. dhweizel

    dhweizel New Member

    Joined:
    Mar 16, 2010
    Messages:
    27
    Location:
    Buenos Aires, Argentina
    Balance:
    339Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    The higher the switching frequency the better, the limit is the switching losses at your h-bridge (more frequency , more heat). At example my pid motor controller works fine in the range of 20-25 khz (i don´t remember exactly right now)
  17. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    I found 18kHz to be the border between audible and something you cannot hear. Some people can hear above 20kHz, some people cannot hear 17kHz.


    That is not true.

    A DC motor is an inductor. It takes time for the current to build up and produce torque. Larger motors have greater inductance and the current takes more time to build.
    Increasing frequency after a certain point will reduce the effective torque of the motor.

    Higher frequency also means increased electrical and magnetic noise and harmonics and as dhweizel said: increased switching losses in the driver.
  18. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    its okey since its adjustable freq by using external pot. LCD display will show what freq i use in operation. the thing i dont know is what parameter to be use to calculate the efficient freq should we aplly without losing motor torque and silent to our ear. :D
  19. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    Re: PICMICRO 16F887

    my pwm out...respond at 19800Hz
    http://www.youtube.com/watch?v=4E01N8IKnfo
  20. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Re: PICMICRO 16F887

    So far so good!