Shop OBEX P1 Docs P2 Docs Learn Events
Problem with "Small Motor Control Made Easy" program — Parallax Forums

Problem with "Small Motor Control Made Easy" program

LevLev Posts: 182
edited 2012-02-06 10:33 in Propeller 1
If you haven't already seen it, the latest Spin Zone article explains how to drive up to two DC motors at 20 kHz using Spin. Very cool, no assembly is required, which makes it easy to understand and modify. Despite that, I have have a problem I can't figure out.

The program (attached) defines constants for the direction and pwm pins for each of up to two motors. If only 1 motor is used, the unused motor is assigned a pin numbers of -1. I tested the program and it works great for any one motor, using either of my motor drivers (so I think the drivers are good). If I assign valid pins (not -1) for both motors, both motors run in the same direction at the same constant speed, alternating on for about 30 seconds, off for about 30 seconds, indefinitely. The program does not allow me to control speed by changing the "speed" variable value.

I tried isolating the control power from the motor power, thinking it might be a brownout/reset issue, but the same thing happened.

Any suggestions?

I am thinking this is a program issue and belongs in this forum. If it belongs in Robotics, my apologies.

Comments

  • RonPRonP Posts: 384
    edited 2011-07-12 12:50
    Lev

    Your Attachment jm_dualmotor_ez_demo.spin says its an invalid link. EDIT: It works fine now.

    This code couldn't have come at a better time for me. Thanks JonnyMac.

    -Ron
  • LevLev Posts: 182
    edited 2011-07-12 13:17
    Hmm...try the link again. It works for me. I might have been editing it when you tried opening it.

    The article came at a perfect time for me too. I was rebuilding my Stingray after watching magic smoke come up from the MSR1. The rebuilding has been a "Flight of the Phoenix" sort of experience. I decided to use JonnyMacs Propeller board (from Gadget Gangster) for the controller, and a motor driver from Pololu. That led me to figuring out how to PWM the motors, then JonnyMacs article arrived in the mail. How cool was that?!
  • LevLev Posts: 182
    edited 2011-07-12 14:44
    Update - The program works just fine now, after I turned the counter generated PWM frequency down to 15 kHz. Apparently 20 kHz is too high, 18 kHz was too high too. This may have something to do with the driver I am using, although the specs say the driver is good at up to 20 kHz.

    Thanks for the great program JonnyMac. Do you plan on submitting it to the OBEX?
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-07-12 14:50
    What motor controller are you using? This one, TB6612FNG, requires two direction pins. It shouldn't be too hard to modify Jonny Mac's code to set the second direction pin to have opposite value of the other.

    John Abshier
  • LevLev Posts: 182
    edited 2011-07-12 15:10
    @John

    I am using the Pololu breakout board that includes dual MC33926's. I set up the drivers for 2 pin per motor control. After tons of testing, it seems to work fine with a single motor at 20 kHz, using either driver. But, there seems to be an issue with controlling 2 motors at 20 kHz. I am not sure if the problem is with the Propeller counter hardware, with Spin execution time, or something with running the 2 motor drivers in parallel.
  • lfreezelfreeze Posts: 174
    edited 2012-02-05 09:15
    I am having fits trying to understand the data sheet for mc33926. Does a pdf version of the Jon Williams article exist. Based on the posts in
    this thread it would be very helpful.
    Thanks

    Larry
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-05 09:42
    I've done tests with a 'scope and it will work up to 25kHz; that said, your motor may not respond to that frequency due to its construction; this is why the motor PWM frequency can be set with a constant change. I use this code in a couple commercial products and it has never given me trouble. The key is to have the PWM frequency above the point at which the motor will make noise. One of my projects is a commercial pan/tilt unit for movie cameras and the last thing we need on set is a "whining" motor -- there are enough whining actors! ;)

    It's been a while since I wrote that so I will have to review and possibly clean-up before posting in ObEx. It is my opinion that too many coders put junk code into ObEx and I don't want to be guilty of that myself.

    Lev wrote: »
    Update - The program works just fine now, after I turned the counter generated PWM frequency down to 15 kHz. Apparently 20 kHz is too high, 18 kHz was too high too. This may have something to do with the driver I am using, although the specs say the driver is good at up to 20 kHz.

    Thanks for the great program JonnyMac. Do you plan on submitting it to the OBEX?
  • lfreezelfreeze Posts: 174
    edited 2012-02-05 13:34
    Thanks for the quick response. I looked at the Nuts and Volts web site. I found your article but it is not offered as digital download I'll buy the paper copy of the July issue, but i was hoping to avoid the
    delivery delay.

    Larry
  • RaymanRayman Posts: 14,845
    edited 2012-02-05 13:46
    This is an intersting idea... Using counter module to control motor...

    I'm currently trying to directly control the motor in a servo that has the electronics ripped out and modified for continuous rotation.
    Using a motor controller, so need two prop pins to control it. Suppose can keep one pin held down or up and use the PWM on the other pin...
    I was going to write an assembly driver to do it, but this might be a simpler way...
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-05 17:55
    For many motors, Ray, you'll find that it works great. One of my wishes for the Propeller II is a set-and-forget PWM mode so that you can get fixed-frequency, variable duty-cycle PWM without the need for a code loop. The SX had it; I used it in a motor controller -- this code replaces it in the Propeller version of that product.
  • RaymanRayman Posts: 14,845
    edited 2012-02-06 10:17
    I think I'll give this a try.
    Suppose the downside is that a cog could only work 2 motors, where an assembly driver could to several.
    But, I think the simplicity and readablility of this approach is much better.
    Plus, this is for driving the 2 wheels of a robot, so 2 is all I need...
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-02-06 10:33
    Exactly. In my case I have a pan/tilt head so it works perfectly. That said, we're going to be adding a trolley motor to a new version of the project so I have to weigh writing PASM driver for three motors versus using two copies of the Spin version.
Sign In or Register to comment.