This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using encoder interface in DRV8312 kit

Other Parts Discussed in Thread: DRV8312, CONTROLSUITE, INSTASPIN-BLDC, LM3S818

Hi,

I want to drive a 2-phase BLDC motor with optical shaft encoder with the DRV8312 kit.

Can anybody provide the sample code for this

What are the changes to be made in the sensor less control code algorithm(that came with the kit)  to use it for the encoder control

Please help me..

  • Soumya,

    There are currently 2 kits for the DRV8312 with different MCUs.  Which kit do you have?  DK-LM3S-DRV8312 or DRV8312-C2-Kit?

  • The PM_Sensorless projects use an external encoder during the incremental build process to tune the observer. The code needed for using a similar encoder (for speed feedback) and the Piccolo QEP peripheral is included. There is a position project being worked on, but nothing released since this old one

    C:\ti\controlSUITE\development_kits\DRV8312-C2-KIT_v124\PM_Sensorless

     

  • Thanks for your reply.

    I am using DK-LM3S-DRV8312 kit  with Code Composer Studio V4

  • sorry, nothing ready to go out of the box, but you can follow along with the Piccolo version and re-use that code. That's how we did the sensorless techniques for Stellaris.

    There will be another Stellaris kit - hopefully released in March - that will add to the motor capabilities of this kit which just shows the sensorless InstaSPIN-BLDC technique.

  • Thanks for reply..

    Where will i get the Piccolo version of the code for using Encoder Interface with the kit..

  • install controlSUITE or download and extract the controlSUITE .zip

    and then use

    C:\ti\controlSUITE\development_kits\DRV8312-C2-KIT_v124\PM_Sensorless

     

  • When iam trying to download ControlSUITE,  Its giving the following error.

    Sorry! We couldn't find your page.

    The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

    Please check the address bar to make sure the link is typed correctly, use the links below to locate the information you want, or search the site for another destination.

    If you are certain that this URL is valid, please send us feedback about the broken link.

    Can you please provide the active link from where i can download. Time is very less for me to do this work, Can you please tell me what to do

  • I just tried and didn't have any problems with www.ti.com/controlsuite , www.ti.com/tool/controlsuite or the controsuite.exe download

    there are sometimes issues with corporate firewalls. this is why we have the full controlsuite.zip available from the /tool link

    here it is directly (438 MB)

    http://www.ti.com/lit/zip/sprca85

    unzip this so that final path is C:\ti\controlSUITE\

     

  • Hi,

    I tried to download the .zip file as well as the software installation so many times but they are getting stopped in between and giving an error "server problem".

    I just want the code for the encoder interface using the kit.

    Is there any way to download only that?

    While installing also i selected piccolo and the kit i want, but still its giving problem in installing.

    Please send me the file which i am looking for.

    I don't have any other option.

    Please help me.

  • While installing, its not progressing after C:\TI\ControlSUITE\device-support\..\ti_c2000support_setup_1.0.0.2.exe

    Please look in to this and give me solution

    PLease

  • Thank you..

    Finally i could download .zip file and install.

    Will look into the code... .

    Thanks for your help Chris..

  • Hi Chris..

    I want to drive the motor (that came with the kit) using hall sensor outputs.

    I was looking into the code in control suite for sensored approach. There are 5 wires coming out from the motor for sensor approach and in the hall_gpio MACRO they are using 3 inputs and reading into GPIO ports and doing it.

    How can i approach for the kit i have (DK-LM3S-DRV8312 and LM3S818 MCU) ?

    I have to add a hall_drv module in the feedback loop? Is that correct?

    How about the connections and the modifications in the code?

    I am new to this area that is why asking small doubts also.

    Initially i wanted to start with our motor using encoder interface but first i want to try with the sensored approach using the motor given with the kit.

    Please give me details how to proceed and all

    Thanks for your help

  • Hi,

    I connected the motor and imported InstaSPIN build levels in CCS and the motor started running

    But i observed one problem with level7. In this level, motor is running for some time and stops after some time and LED near fault pin is glowing in RED instead of green

    What could be the problem?

    I didn't change anything in the code also.

    Please help me

  • Can you please explain me about the commutation technique used in sensored approach in DRV8312-C2 kit.

     **hall_gpio_BLDC.h file is confusing me.

    Can please explain me with an example how the edge sensing is happening and how to give commutation pulses according to sensor outputs?

    PLEASE help me

  • Q: How can i approach for the kit i have (DK-LM3S-DRV8312 and LM3S818 MCU) ?

    A: follow DRV8312-C2-KIT controlSUITE C:\ti\controlSUITE\development_kits\DRV8312-C2-KIT_v124\BLDC_Sensored

    Q: I have to add a hall_drv module in the feedback loop? Is that correct?

    A: Yes. But you will need to use the entire C2000 version of the project. The project on LM3S818 is ONLY InstaSPIN-BLDC.  The InstaSPINBLDC.lib is not useful for sensored BLDC. You will need the hall_drv as well as the counters for commutation.

    Q: How about the connections and the modifications in the code?

    A: It's probably easier to copy/paste in all the yellow blocks from the C2000 document (level 6), use the ADC and PWM driver provided with LM3S818, and then either port the Hall Driver from Piccolo to Stellaris or use a Hall driver from StellarisWare (see the RDK-BLDC).  I recommend the StellarisWare (SW-RDK-BLDC) version for simplicity.

    Q: Can you please explain me about the commutation technique used in sensored approach in DRV8312-C2 kit.

     **hall_gpio_BLDC.h file is confusing me

    A: I'd use StellarisWare for hall_ctrl.c and .h in the SW-RDK-BLDC download.

  • Hi, thanks for ur help.

    Which .lib files should i add to use it for sensored approach?

    Where to include in the new project? In Build properties,include options?

    What are the peripherals to be configured to use hall effect sensor outputs?

    I am planning to use GPIO ports, but what are the things to be configured to use it?

    There is a hall_drv module in C2 kit for sensored approach, where the actual reading of GPIO ports is done.

    iam following that and while configuring the GPIO ports by using driver library functions, iam getting confused about what are the functions to be used?

    If i want to use the same way, what is the procedure?

    Please help me

  • No library is needed for sensored.

    I still recommend the StellarisWare hall driver and the capture pins, it is much simpler than the Piccolo version which relies on edge detecting GPIO.

    download the SW-RDK-BLDC and look at how the halls are set-up in that package

    C:\StellarisWare\boards\rdk-bldc\basic-bldc

  • Hi Chris..

    Thanks for your quick reply. Iam able to progress in my project because of your help only. Thanks a lot.

    I have one doubt.

    I changed the code to run for sensored approach  in LEVEL4 and LEVEL6 but i didn't change the LEVEL1. But when i debug the code in LEVEL1, RunMotor is not changing the value after setting the EnableFlag. When i do the same with the InstaSPIN_Build_levels project (that came with the kit) its working properly. I tried so much but could not find the reason. Iam sure about LEVEL1 , i didn't change it. Compared so many times with the original code.

    Dont know how to proceed.

    Please help me.

  • which code have you been changing?

    if it's the Stellaris InstaSPIN_BuildLevels, did you change any of the original settings in the .h?

    #define BEGIN_START_RPM 50.0
    #define END_START_RPM 200.0
    
    
    this is what controls the ramp generation in level 1
  • Thanks for ur quick reply.

    No..

    I have not changed those settings.

    I just changed the generation of Commutation_trigger.

    In the original code its being generated by BEMF method, iam generating using a hall_drv module (which i coded) which takes hall inputs.

    This is what i have done. LEVEL1 is exactly same and in .h file i didn't change any parameters.

    Please help me

  • Hi Chris,

    I could solve the Run Motor value problem.

    Iam reading the hall inputs directly to GPIO ports.

    The following are the things i have done.

    Iam using GPIO B4,B5, B6 pins to read.

    I used the following driver functions

        GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
          
            GPIOPinTypeEPI(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
           
        Uint32 temp;
        Uint16 HallGpioBitA,HallGpioBitB,HallGpioBitC;
        
        //Read the values in to the temp variable write the stmt which reads from GPIO
        temp = GPIOPinRead(GPIO_PORTB_BASE,(GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6));
        HallGpioBitA = (temp&0x00000001);            /* save GPIO24 - A*/                        
        HallGpioBitB = (temp&0x00000002)>>1;        /* save GPIO25 - B*/                        
        HallGpioBitC = (temp&0x00000004)>>2;        /* save GPIO26 - C*/                        
        HallGpioBitA = HallGpioBitA;/*<<2;                 shift GPIO24 - A*/                        
        HallGpioBitB = HallGpioBitB<<1;                /* shift GPIO25 - B*/                        
        HallGpioBitC = HallGpioBitC<<2;/*<<1;                 shift GPIO26 - C*/                        
                                                                                                
        v->HallGpio = HallGpioBitA + HallGpioBitB + HallGpioBitC;

    Can you please tell me whether iam doing wrong?

    Iam getting 0 when i see the the variable HallGpio in watch window. Its value is not getting changed

    Can u plz tell me the corrections to be made?

    Thank you

  • since this has now become a question regarding stellaris SW usage and the hall driver I'd suggest you post specifically to the Stellaris Forum, you will get a better answer to your question than from me

    http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471.aspx

  • Chris,

    I'm trying hard to follow the examples given in the article " Sensorless Trapezoidal Control of BLDC Motors Using BEMF Integration (InstaSPIN™-BLDC) on Stellaris® Microcontrollers", but my CCS v4 doesn't debug the InstaSpin_BuildLevels project. It says everytime that " Error connecting to the target: The target board you are attempting to connect to does not appear to be a Stellaris IDK and is not supported with this license. This license may only be used with the development board that is included with Stellaris IDKs bundled with Code Composer Studio."

    Well, I then got a 90-days license file to substitute the one that came with the kit, but it still doesn't working.

    I need to simply do an velocity closed-loop at 1 Hz for the dc motor that comes in the kit Stellaris® DK-LM3S-DRV8312 InstaSPIN™-BLDC. What's the best way to do an embedded software with this purpose?

    Thank you,

    Danilo

  • Some of these kits have an issue and need the firmware updated on the in circuit debug chip (the USB to serial). Follow this post.

    http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/t/155596.aspx

     

    For your project, use the GUI to find the Vth and PI values that work, any advnaced start-up features, then hard code those variable values into the standalone project with the appropriate build level (level 7 in your case)

     

  • Hi Chris,

    Thank you for the reply. Unfortunatelly it didn't work. I did exactly what you said: The bottom gray line changes from "Idle" to "Waiting for ICDI update to connect...". This phrase stays for 1 minute and then two error windows takes place in sequence:

    **ERROR**: Failed to reconnect ICDI device
    **ERROR**: Unable to program ICDI Firmare!

    I checked the device manager in order to see what happened and as you can guess the "Stellaris In-Circuit Debug Interface" (both the "Stellaris ICDI DFU interface" and the "Stellaris ICDI JTAG/SWD Interface") desappeared! Removing and adding the USB cable again reinstalled the old ICDI firmware.

    Is there another way to install the new firmware? Am I doing something wrong?

    Thanks for the tips regarding to control.

    Regards,

    Danilo

  • Danilo,

    I had issues the first time as well, and the thing that finally solved it was restarting my computer after the driver installation.

    I tried to document all the steps in the attached Stellaris InstaSPIN-BLDC Lab

    (this will be in the next update of Software package, along with an updated GUI that correctly auto-connects upon launch)

    InstaSPIN-BLDC_Lab_StellarisLM3S.pdf
  • Hi Chris,

    I didn't have problem with the InstaSPIN-BLCD-GUI using LM Flash on the Control Card. This program worked pretty well. My motor spinned and also did the cascade control you suggested.

    My problem is concerning to the Code Composer Studio v4. I want to work with InstaSpin_BuildLevels, in order to do actively control my dc motor. But the error message still happens when I try to debug those .bin file: " Error connecting to the target: The target board you are attempting to connect to does not appear to be a Stellaris IDK and is not supported with this license. This license may only be used with the development board that is included with Stellaris IDKs bundled with Code Composer Studio." I got an 90-days license from your website and then changed my kit-license.

    I tried to debug the same file using CCSv5, but an error windows appears as well: "Load program Error. Encountered a problem loading file C:\StellarisWare\AppNotes\sw01289\InstaSpin_BuildLevels\ccs\Debug\InstaSpin_BuildLevels.out Couldn't open file"

    I tried to upload the firmware using LM Flash, as suggested in http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/t/155596.aspx. Didn't work, as I mentioned before. Restarting the computer wasn't effective, no matter how many times.

    Couldn't you do a simple .bin program or whatever that verifies what is happening inside my ControlCard? Perhaps it has an issue and this .bin program could collect some information about it. And then I bring these .bin file back to you and finally you could send me another .lic file that works with the information collected by the .bin.

    I appreciate the help. Meanwhile, I will try to uninstall and then reinstall everything again...

    Danilo

  • Danilo,

    This appears to be something with the ICDI driver, how it is recognized in regards to being a supported emulator, and which version of CCS you are using.  I suggest you post on the Stellaris forum for immediate help.

    http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471.aspx

    Once you can connect to the ICDI debugger, and connect to the target, you will be fine.

  • Soumya Joshi,

    Can you tell me in details everything you have done to use the Hall Sensors? I have exactly the same problem as you: I have a Stellaris microcontroller.

    Thanks,

    Danilo

  • Hi Danilo,

    As far as i understand, your kit  has the problem of connecting to the target.

    Follow below instructions, it worked for me.

    There may be a problem with the CCS board-locked license feature on some MDL-LMS818CNCD controlCARDS.  The CCS debugger may fail to connect to the target  because it is unable to validate the security-key. 

    This will also affect some controlCARDS that are included in the DK-LM3S-DRV8312 BLDC motor kit.  The license issue only appliers to users who wish to use Code Composer Studio to debug the board and do not have a time-limited or full license. 

    If you encounter this issue, you will need to update the firmware in the Stellaris In-circuit Debug Interface (ICDI) located on the controlCARD.  To do this, first download LM Flash Program version 1381 or later (http://www.ti.com/tool/lmflashprogrammer).  Once LM Flash Programmer is installed, select the ‘Other Utilities Tab’ and click on the ‘ICDI Firmware Update’ button.  In a few seconds the firmware will update.  Close LM Flash Programmer and re-start CCS.  A board-locked license will now be available as long as CCS was installed using the default license included on the Stellaris DVD.

    Note: At the time of this post, LM Flash v1381 is available for download, but the text for the ‘current version’ on the download page had not been updated.

  • Thanks Soumya,

    I did that and it worked!

    But I'm trying to use the Hall Sensors with Stellaris. What did you do? Did you use hall_ctrl.c and .h?

    What are the other modifications to do in the main code? Probably, you`ve declared hall_ctrl.h in the header and modified the code to read the speed.  Did you use M3_BLDC_Main.c as the main code? Did you modify anything in GPIO ports? Can you help me?

    Thanks,

    Danilo

  • Hi,

    I used hall_ctrl.h and reading from GPIO ports i have done in main file itself. I used the same main code but modified according to the sensors reading.

    In the original code, they are using BEMF to generate trigger for the counter, that portion i changed to use from hall drive module.

    The GPIO ports that i used are D4, C5 and D5. U can get these things from DRV8312 circuit diagram.

    I read those ports and generated trigger for counter and controlled the motor.

  • Hi Soumya Joshi,

    Thank you. Well, I'm an undergrad student... I need some further explanation. It is my first time with electric motors.

    I tried to do what you suggested me. Could you please check if my code is correct? (The code is below)

    Obs.: I declared the hall_ctrl.h in the beggining.

    Obs2.: I didn't change anything in the "void main" code in M3_BLDC_Main.c

    / =============================== LEVEL 9 (just as a name) ===========================
    // ==============================================================================
    //To use with Hall Sensors closed loop.

    //Danny added

    #if (BUILDLEVEL==LEVEL9)



    // ------------------------------------------------------------------------------
    //    ADC conversion and offset adjustment
    // ------------------------------------------------------------------------------
        iqVaIn =  _IQ15toIQ((ulADC0_Value[0]<<5));
        iqVbIn =  _IQ15toIQ((ulADC0_Value[1]<<5));
        iqVcIn =  _IQ15toIQ((ulADC0_Value[2]<<5));

        //IDCfdbk=(_IQ15toIQ( ulADC1_Value[0]<<5)-IDC_offset)<<1;

    // ------------------------------------------------------------------------------
    //    Connect inputs of the MOD6 module and call the Modulo 6 counter function.
    // ------------------------------------------------------------------------------
        if(SpeedRef > _IQ(0.0))
        {
            mod_dir1.CntDirection = _IQ(1.0);
        }
        else
        {
            mod_dir1.CntDirection = _IQ(-1.0);
        }
        PreviousState = mod_dir1.Counter;
        mod_dir1.calc(&mod_dir1);

    // ------------------------------------------------------------------------------
    //    Connect inputs of the HALL module and call the Hall sensor read macro.
            //Danny added
    // ------------------------------------------------------------------------------
        HallInit;
        HallConfigure;
        GPIOBIntHandler;

    // ------------------------------------------------------------------------------
    //    Connect inputs of the SPEED_PR module and call the speed calculation function.
    // ------------------------------------------------------------------------------
        //while counting up we want positive speed
        if((mod_dir1.Counter==5)&&(PreviousState==4)&&(mod_dir1.TrigInput))
        {
            speed1.TimeStamp = VirtualTimer;
            speed1.calc(&speed1);
            SpeedLoopFlag = TRUE;
        }
        //while counting down we want negative speed
        else if((mod_dir1.Counter==0)&&(PreviousState==1)&&(mod_dir1.TrigInput))
        {
            speed1.TimeStamp = VirtualTimer;
            speed1.calc(&speed1);
            speed1.Speed = _IQmpy(speed1.Speed,_IQ(-1.0));
            speed1.SpeedRpm = _IQmpy(speed1.SpeedRpm,_IQ(-1.0));
            SpeedLoopFlag = TRUE;
        }

    // ------------------------------------------------------------------------------
    //    Connect inputs of the INSTASPIN_BLDC module and call the INSTASPIN_BLDC function.
    // ------------------------------------------------------------------------------
        /*InstaSPIN_BLDC1.Vag = iqVaIn - InstaSPIN_BLDC1.VaOffset;        // Adjust for offset of Va_in
        InstaSPIN_BLDC1.Vbg = iqVbIn - InstaSPIN_BLDC1.VbOffset;        // Adjust for offset of Vb_in
        InstaSPIN_BLDC1.Vcg = iqVcIn - InstaSPIN_BLDC1.VcOffset;        // Adjust for offset of Vc_in
        InstaSPIN_BLDC1.State = mod_dir1.Counter;                        // Update the state
        InstaSPIN_BLDC(&InstaSPIN_BLDC1);
        mod_dir1.TrigInput = InstaSPIN_BLDC1.Comm_Trig;*/

        if((rmp3.Ramp3DoneFlag == 0) || (SpeedLoopFlag == FALSE))
        {
    // ------------------------------------------------------------------------------
    //    Connect inputs of the RMP3 module and call the Ramp control 3 function.
    // ------------------------------------------------------------------------------
            rmp3.DesiredInput = CmtnPeriodTarget;
            rmp3.Ramp3Delay = RampDelay;
            rmp3.calc(&rmp3);

    // ------------------------------------------------------------------------------
    //    Connect inputs of the IMPULSE module and call the Impulse function.
    // ------------------------------------------------------------------------------
            impl1.Period = rmp3.Out;
            impl1.calc(&impl1);

    // ------------------------------------------------------------------------------
    //    Connect inputs of the MOD6 module and call the Modulo 6 counter function.
          //Danny added
    // ------------------------------------------------------------------------------
            mod_dir1.TrigInput = impl1.Out;
            //mod_dir1.Counter = (int32)hall1.HallMapPointer;
        }
        else
            mod_dir1.TrigInput = g_ulHallValue;//(int32)hall1.CmtnTrigHall;

    // ------------------------------------------------------------------------------
    //    Connect inputs of the PID_REG3 module and call the PID speed controller
    //      function.
    // ------------------------------------------------------------------------------
          pid1_spd.term.Ref = SpeedRef;
          pid1_spd.term.Fbk = g_ulHallRotorSpeed; //Danny changed. Original: speed1.Speed
          pid1_spd.calc(&pid1_spd);

    // ------------------------------------------------------------------------------
    //    Connect inputs of the PWM_DRV module and call the PWM signal generation
    //    update function.
    // ------------------------------------------------------------------------------

    // Switch from fixed duty-cycle or controlled Speed duty-cycle by SpeedLoopFlag variable
        if(SpeedLoopFlag == FALSE)
        {
            // fixed duty-cycle
            iqDuty = _IQmpy(DfuncStartup,mod_dir1.CntDirection);
        }
        else
        {
            // controlled Speed duty-cycle
            iqDuty = pid1_spd.term.Out;
        }

     // ------------------------------------------------------------------------------
     //    Connect inputs of the SPEED_PR module and call the speed calculation macro.
         //Danny added
     // ------------------------------------------------------------------------------
         /*  if ((pwm1.CmtnPointer==5)&&(PreviousState==4)&&(hall1.CmtnTrigHall==0x7FFF))
           {
              speed1.TimeStamp = VirtualTimer;
             SPEED_PR_MACRO(speed1)
           }

        Generate_Outputs(mod_dir1.Counter, iqDuty );*/         //    Generate the PWM and Reset outputs

    // ------------------------------------------------------------------------------
    //    Connect inputs of the DATALOG module
    // ------------------------------------------------------------------------------
        DlogCh1 = (int16)mod_dir1.Counter;
        DlogCh2 = _IQtoQ15(InstaSPIN_BLDC1.V_int);
        DlogCh3 = _IQtoQ15(*(InstaSPIN_BLDC1.Vphase));
        DlogCh4 = _IQtoQ15(InstaSPIN_BLDC1.Vag);


    #endif //(BUILDLEVEL = LEVEL9) //End Danny

  • Soumya and Chris,

    Probably my above code has some issues. Furthermore, it can't even be build. Some CCS errors occurred, such as "unresolved symbols remain", "unresolved symbol g_ulHallValue", "unresolved symbol g_ulHallRotorSpeed". Is it because I have to #include .h files that are mentioned in the header of hall_ctrl.c? That results in a cascade effect! I had to import a lot of files from C:\StellarisWare\RDK\boards\rdk-bldc\basic-bldc and some of these codes are not working at all!

    Did you have the same problem?

    Best,

    Danilo

  • Hi Chris,

    When I try to debug the codes that come in C:\StellarisWare\RDK\boards\rdk-bldc (where the ctrl_hall.h and  .c are), I get strapped in a while(1) case inside a FaultISR function. Do you know why? Is it related to the fact I have a Development Kit?

    Best,

    Danilo

  • I don't think the RDK code works correctly, but I can't speak to the details.

    just pull out the hall driver code into InstaSPIN-BLDC