1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

BLDC motor speed control...

Discussion in 'Microcontrollers' started by koolguy, Jun 23, 2013.

  1. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi,

    I am using BLDC motor with ESC i want to know can we use anything else than i2c to control speed of it like PWM...?
    b'coz i have never used i2c.
     
  2. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,257
    Likes:
    1,218
    Location:
    Cardiff, Wales
    Yes. The ESC is also said to have "Simple connectivity with an RC receiver PPM signal".
     
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I am using PIC16F877a using PWM will be fine?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,257
    Likes:
    1,218
    Location:
    Cardiff, Wales

    PWM is not the same as PPM. Unclear how that particular ESC would respond to PWM. Check its datasheet.
     
  6. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    OK, i will try code for I2C ...
     
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    Attached Files:

    • I2C.C
      File size:
      797 bytes
      Views:
      142
  8. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    There is so much wrong in that code that I would just start all over.

    1) Check that all the connections are correct.
    2) Make sure you have (10k) pull-up resistors on the SDA and SCL wires.
    3) Read this: http://www.8051projects.net/i2c-twi-tutorial/pic-i2c-implementation.php
    4) Use these I2C functions: http://www.8051projects.net/i2c-twi-tutorial/pic-i2c-code-example.php
    5) Keep your test project as simple as possible. Forget the for loop. Try this to test your i2c:

    Code (C):

    void main(void)
        // small delay here could be needed
        I2CInit();
        // small delay here could be needed

            // Try to send speed command to motor ESC
        I2CStart();    // Start condition
        I2CSend(0x12); // Address
        I2CSend(100);  // Speed value 0 to 255
        I2CStop()      // Stop condition

            // Motor should start spinning. Go into loop.. do nothing.
        while(1){
        }
    }
     
    EDIT: The examples are for 4Mhz clock. You may need to modify the I2CInit()-function if you use 20Mhz clock.
     
    Last edited: Jun 26, 2013
  9. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,899
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE
    @Post#4

    I read through the datasheet that was provided. In fact, as alec_t notes, that datasheet states "PPM," but I think what it means is the PWM that is used for model servos.

    The datasheet goes on to state, "The PPM output of most RC receivers is compatible." I am not aware of any common receiver, much less most that output a PPM signal to servos. I think the author of that datasheet has confused the PPM modulation (PCM being another common mode) from the transmitter that the receiver receives with the decoded output from the receiver.

    In short, connect a typical PWM servo tester to the esc, and I will bet it works. Most important, there are many examples of code in C for driving such servos. I believe that is worth a try for your project.

    John
     
  10. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    I was thinking the same, but didn't want to say anything because I don't know in detail how RC systems actually work.. It just sounded weird that it would take in PPM. How would you choose the channel? The specs didn't mention any fixed channel.
     
    Last edited: Jun 26, 2013
  11. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,899
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE
    That question can't be answered without knowing the details (i.e., brand and model) of the transmitter and receiver.

    If he is using a typical, Asian-made TX and RX, then I would recommend plugging the esc into the receiver pinout labeled, "throttle." Any pinout will work, but throttle will often have a friction drag and not be self-centering on the transmitter control stick.

    In reality, since he is using the 16F877, the term "channel" is meaningless. All of the channels look the same on the signal wire to each one. That is a result of the decoding I mentioned. All he needs to do is put the PWM signal on one pin. The PIC can provide sufficient signal to drive the servo directly.

    John
     
  12. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    I meant that If the signal (that you feed directly to the esc) is really proper PPM, then which channel does the esc use? That's what was suspicious to me, because none of that was in the specs.
     
  13. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,899
    Likes:
    502
    Location:
    Cleveland, OH, USA
    ONLINE
    That is the whole point of it. The signal to the esc or servo is NOT PPM. I have never seen one that was. Many years ago (60+ years) some of the controls were pulse coded, but that was before servos became universally used for control. All of what I have said is relative to model servos. Industrial servos may very likely use different control signals.

    John
     
  14. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Yes, yes. I agree. I was just trying to explain (to myself) why it can't be PPM.
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    The scl and sda will be set to 0 or 1?
    For taking output it should be 0 in master mode but in link he isvusing input why?
     
  16. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Because I2C works differently than normal IO. You are not allowed to drive the signals. You are only allowed to pull the signal low, you are not allowed to drive it high. That is why you need the pull-up resistors. The resistors pull the signal high when needed.
     
  17. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,022
    Likes:
    317
    Location:
    Brisbane Australia
    ONLINE
    RC systems do use Pulse Proportion Modulation (PPM). See this document for a good explanation of servo control.

    Whilst the PWM module is used to generate servo signals it is not in PWM mode. In this example I use the PWM module in Special Event Trigger mode to generate the signals.

    Mike.
     
  18. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    That was not the point. We were not discussing how RC systems work in general. We were discussing about the ESC Ritesh is using.. the documentation says that it can take PPM signal in to control the speed, but that is not possible. There must be a mistake in the documentation. It must be PWM that the ESC takes in.
     
  19. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Ok.. yeah. I'm reading every post too quickly today. We are mixing three different things here.

    Pulse Position Modulation (PPM)
    Pulse Proportion Modulation (PPM)
    Pulse Width Modulation (PWM)

    You can't control the device (ESC) with Pulse Position Modulation.
    But you can control it with Pulse Proportion Modulation.. which in PICs is generated exactly the same way as PWM.
     
  20. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I am talking about tris setting to 1or0?
     
  21. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Use the settings that was used in the example code I posted.

    TRISC3 = 1; /* SDA and SCL as input pin */
    TRISC4 = 1; /* these pins can be configured either i/p or o/p */
     

Share This Page