Welcome to Our Community

Unlock hidden features. Sign Up for Free Today!

TinyG (v8) and PWM ESC Control

Discussion in 'Controller Boards' started by Lee Saferite, Jun 25, 2014.

  1. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
  2. dddman

    dddman Master
    Builder

    Joined:
    Mar 2, 2014
    Messages:
    433
    Likes Received:
    152
    Don't forget that you'll have to arm your esc to be able to drive your motor.
     
  3. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Dang. Good point. Likely I'll have to send them a pull request for that feature (luckily I'm a programmer with embedded experience). Seems like an oversight in the code.
     
  4. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Actually, thinking about it, I can just send an M3 with the max RPM followed by an M5 right? As the ESC init only happens during power up, it'll be like the homing sequence and only done once on startup.
     
  5. dddman

    dddman Master
    Builder

    Joined:
    Mar 2, 2014
    Messages:
    433
    Likes Received:
    152
    It depends on what you ESC wants... I don't know if they all want the same thing... Here is the code I use for my arduino to arm it (found on youtube actually):

    here is the link to download the code: https://www.sendspace.com/file/jrtfu0

    void initialize_motor()
    {
    Serial.print("Arming the motor! \n");
    delay(3000);
    Serial.print("Setting low speed! \n");
    myMotorBR.write(5);
    delay(4000);

    Serial.print("Setting high speed! \n");
    myMotorBR.write(180);
    delay(4000);


    myMotorBR.write(10);
    Serial.print("MOTOR IS READY! \n");
    delay(2000);
     
  6. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Every ESC I've ever used has the same power on calibration sequence. The quad copter board I use can calibrate all of my ESCs at once knowing this. So, I think I can write some Gcode to calibrate the ESC. I'll hopefully let you guys know after the weekend.

    Thanks for the reminder in any case. :)
     
  7. Tweakie

    Tweakie OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Jan 18, 2014
    Messages:
    787
    Likes Received:
    290
    I don't know if this is of any help to you http://openbuilds.com/builds/software-speed-control-of-a-brushless-dc-bldc-motor-from-mach3.762/

    Tweakie.
     
  8. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Yeah, I saw that build, but the TinyG has the ability to control the PWM output pulse size/duration with enough control to run a servo/ESC directly. The only issue I see is the one mentioned above about calibrating the low/high range for the ESC on startup.

    The TinyG phase low/high controls the min/max pulse width. That is used in conjunction with the speed low/high and the M3 value to set the pulse width. So, unlike a 0-100% PWM signal, this is able to generate the exact pulses needed. Or so it seems. :)

    I do like your board in that you can manually control the speed though.
     
    Ed Betlinski likes this.
  9. Tweakie

    Tweakie OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Jan 18, 2014
    Messages:
    787
    Likes Received:
    290
    Ideally, you need to produce a PWM with a duty cycle which has a pulse width of between 1mS and 2mS repeated at 50Hz (that is to say at a 20mS interval).

    I have found that servo’s are far more tolerant to variation in the PRF (which can be raised to 200Hz or perhaps even higher) without any ill effects but ESC’s are a bit more demanding and the ones that I have tried do prefer the industry standard 50Hz.

    From my tests as long as an ESC is powered up at a 1mS pulse width then followed by a suitable delay (for the beeps) it does not enter programming mode and then performs exactly as it was initially set-up.


    You should be able to program all the required calculations, start delay and timing into your TinyG but the resultant, modified, PWM has to be run as a background task in order to allow the TinyG to get on with all it’s other work.


    It is quite a challenge but I am sure you will get there. :thumbsup:


    Tweakie.
     
  10. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Most of the cheap ESCs I've dealt with will do 100Hz and some of the slightly better will do 200Hz. We use the higher refresh rate with quadcopters for the stability.

    I was planning to use 50Hz for this though as the refresh rate isn't as critical in this application.

    50Hz also works nicely in the math area as well

    Freq: 50
    Low Phase: 0.05 (5%)
    High Phase: 0.10 (10%)

    And with my motor
    Low RPM: 1000
    High RPM: 21000

    Those are the initial numbers I plan to use.

    I'm going to try this G-code to initialize the ESC

    M3 21000
    G4 1
    M3 1000
    G4 1

    Or something similar as I have no idea if the dwell will affect the M3 as they are in different modal groups. I just wish I could specify a motor startup sequence. Looking at the code it wouldn't be hard to implement. My reasoning is that I'd like to use the Spindle On/Off GPIO pin to cut power to the ESC via an SSR. But if I do that, I have to initialize the motor each time. I guess a planner could insert the correct motor spinup sequence each time, but that would be a pain.
     
  11. Tweakie

    Tweakie OpenBuilds Team
    Staff Member Moderator Builder

    Joined:
    Jan 18, 2014
    Messages:
    787
    Likes Received:
    290
    I am looking forward to following your progress. :thumbsup:

    Tweakie.
     
  12. Lee Saferite

    Lee Saferite Journeyman
    Builder

    Joined:
    Apr 29, 2014
    Messages:
    32
    Likes Received:
    5
    Quick note: I finally got some free time this past weekend to test things out and I cannot get the ESC to even recognize the PWM signal from the TinyG board. I guess I need to break out the Digital Oscope and see what's actually being sent. :(
     

Share This Page

  • About Us

    The OpenBuilds Team is dedicated helping you to Dream it - Build it - Share it! Collaborate on our forums and be sure to visit the Part Store for all your Building needs!
  • Like us on Facebook

  • Support Open Source FairShare Program!

    OpenBuilds FairShare Give Back Program provide resources to Open Source projects, developers and schools around the world. Invest in your future by helping others develop theirs!

    Donate to FairShare!