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. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    I guess you didn't read the rest of the sentence.

    Mike.
     
  2. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    If you want me to send you a free Junebug PCB. Don't bother if you don't need it, just offering.
    4177-JuneBug.png

    PS your code shows, but your schematics / photos whatever don't.
     
  3. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    I think you nailed the crux of the problem.
     
  4. dave

    Dave New Member

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


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia

    Nope, the crux of the problem is elsewhere.

    Mike.
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    It hangs on the while loops he made.
    This
    Code (text):
    void I2C_start(void){
        SEN=1;
        while(SEN);
     
        }
    Should be this
     
    Code (text):
    void i2c_Start(void)
    {
        i2c_Wait();
        SEN=1;
    }
    And this
    Code (text):
    void I2cSTOP(void ){
    PEN=1;
    while(PEN);
    }
    Should be this
    Code (text):
    void i2c_Stop(void)
    {
        i2c_Wait();
        PEN=1;
    }
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    It hangs on the while loops he made.
    This
    Code (text):
    void I2C_start(void){
        SEN=1;
        while(SEN);
     
        }
    Should be this
     
    Code (text):
    void i2c_Start(void)
    {
        i2c_Wait();
        SEN=1;
    }
    And this
    Code (text):
    void I2cSTOP(void ){
    PEN=1;
    while(PEN);
    }
    Should be this
    Code (text):
    void i2c_Stop(void)
    {
        i2c_Wait();
        PEN=1;
    }
     
  8. Brian Griffin

    Brian Griffin Member

    Joined:
    May 23, 2013
    Messages:
    49
    Likes:
    8
    Location:
    Kuala Lumpur
    The problem is, the thread opener didn't read most of the posts we made. He only cared about the answers. He will keep posting again, and again, and again, this time it's a different problem but without a solution.

    It's hard to help people who refuse to help themselves. :)
     
    • Like Like x 1
  9. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Makes me think of this.
    what-dogs-hear-the-farside-gary-larson-153603564_7281ad0588.jpg
     
    • Like Like x 2
  10. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Where did you get the code you posted? I don't think that Ritesh even copy-pasted the i2c_Wait(); function from the source I linked.. I don't know why.. maybe he does not need it (sarcasm).
     
  11. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    I looked at the library that's in xc8 and there's a link on page 8
    That's doing it the same way.
    I don't do any more then hold the line high as is he has
    It coded it goes in the first loop and keeps the I2C line high.
     
    Last edited: Jul 4, 2013
  12. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    Amazing.

    Mike.
     
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Yep it is there a working sample code on page 8 if the op looked
    At it. There a library in XC8 which is in high tech to lol
    It doesn't have all them while loops which don't add up
    Your setting it to start overs and over agin
     
  14. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Is this fine now?

    Code (text):
    #include <htc.h>
    __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
    #define _XTAL_FREQ 20000000

    #define SDATA RC4
    #define SCLK RC3
    void I2C_init(),I2C_start(void),I2C_write(char x), I2cSTOP(void);  
    void i2c_Wait(void);
    void main(void){
       
        TRISC3=1; //direction to input have be changed
        TRISC4=1;
    TRISC0=0;
    TRISC1=0;
    TRISC2=0;
    RC0=0;
    RC1=0;
    RC2=0;
    __delay_ms(500);
        I2C_init();
    __delay_ms(50);
        I2C_start();
    RC0=1;
        I2C_write(0x12);//esc default addr
    RC1=1;
        I2C_write(100);//testing speed 0-255
    RC2=1;
       I2cSTOP();
    while(1){

    RC0=0;
    RC1=0;
    RC2=0;
    __delay_ms(500);
    RC0=1;
    RC1=1;
    RC2=1;
    __delay_ms(500);
    }
    }




    void I2C_init(void)
        {
      SSPCON = 0x38;      // set I2C master mode
     SSPCON2 = 0x00;
    SSPADD = 0x0C;  //400KHZ  20MHz xtal
    SSPSTAT|=0X80;
     PSPIF=0;      // clear SSPIF interrupt flag
     BCLIF=0;      // clear bus collision flag
    }



    void I2C_start(void)
    {
        i2c_Wait();
        SEN=1;
    }
       
     void I2C_write(char x){
        i2c_Wait();
    SSPBUF=x;
       

           
            }
               
    void i2c_Wait(void){
        while((SSPCON2 & 0X1F || (SSPSTAT & 0X04)));
    }

    void I2cSTOP(void)
    {
        i2c_Wait();
        PEN=1;
    }  
     
  15. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    Does it work?
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Lol it has a better chance now. But it would of made better
    Sense to have tried it and told if it works lol
     
  17. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    170
    Location:
    Toronto, Canada
    That would be what most people would do.

    I'm starting to believe RK is a possibly a bot.
     
    • Like Like x 1
  18. Brian Griffin

    Brian Griffin Member

    Joined:
    May 23, 2013
    Messages:
    49
    Likes:
    8
    Location:
    Kuala Lumpur

    I do believe so too.

    Looking at the Thread OP's webpage - he is in a senior year in EE.

    I'm thinking that a senior year should have covered at least a full course in C/C++ and one or two semesters in microcontroller programming. And even if it's not, hitting and missing around is something learned in all these lab-works too.

    Many years back I wasn't even studying in an EE environment. I was in Medical Technology Engineering, and I'm only halfway exposed to EE subjects. I struggled like mad in the earlier semesters, only barely passing all these subjects. On the semester breaks, I hit the books again and wildly experimented on op-amps, and some digital logic circuits, and lastly microcontrollers. Most of these are experimentation, and finally, they worked because I did it one at a time. As a person with a mild Asperger/autism, isolating problems do help a lot in understanding electronics.

    Just my two cents.
     
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Its not working man.............
     
  20. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Well there not much hope in helping you there not any way
    To see what's happening and even if your told things to do you supply
    No information about what's going on no sch.
    And don't you have a YouTube video showing it working.
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Without me reading through this thread again.... What H bridge controller are you using?...
     

Share This Page