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.

DRV8412 Dual motor pulsing

Other Parts Discussed in Thread: CONTROLSUITE

Hello,

Hopefully someone here can help with my problem, as I've been unable to find a solution via searching the net.

I've got my hands on a delightful DRV8412-C2-Kit for the purpose of developing dual motor patterns for a project.

Unfortunately while I know C/C++ to an okish level, I know next to nothing about TI boards and CC programming. I've found it impossible to find any really basic guides on writing, and the example projects included are rather complex.

I'm wondering if anyone could point me to a basic guide or show me an example of code that would perform the following;

* Turn motor 1 on for 500ms at full cycle

* Turn off motor 1 and turn on motor 2 for 500ms at full cycle

* wait for 500ms

* Repeat

I don't need any state feedback, no input buttons, no GUI just the code that will perform this function endlessly until the power is turned off.

  • Zen,

    Based on your comments I assume that you are interested in the 2xDC_Motor project.  I would start off running this project (with the help of the following guide):
    \controlSUITE\development_kits\DRV8412-C2-KIT_v131\2xDC_Motor\~Docs\Dual Axis BDC.pdf

    I would also recommend starting with Level 4 because, even though it has things you don't need (like state feedback), it will be easiest to get something running quickly this way.  Then as you understand more you can strip out more as necessary.

    After exploration, your task will be automating what you're doing in a CCS watch/expression window into C-code.  To do this I would recommend using the state machines that exist in the project (~lines 336-546 in 2xDC_Motor.c).  Basically A0, B0, and C0 are each called as often as possible.  However, they will call A1/A2/A3, B1/B2/B3, or C1/C2/C3 respectively every xx ms depending on the period (a variable) of each of the CPU Timers (CpuTimer0, CpuTimer1, and CpuTimer2 respectively).

    Since none of the B tasks are being used by the motor control software, change CpuTimer1's period (~line 183) to mSec500.  Then change B1's B_Task_Ptr (~line 479) to B_Task_Ptr = &B1;  This will make it to where only B1 will be called by B0 and B1 will now get called approximately every 500ms.  You then should add code to do what you've done in the watch window to the beginning of the B1 function.

    Note that this will get you started, but you may need to change the rc (ramp controller's settings) or remove it.  It's responsible for soft-starting the motor.


    Thank you,
    Brett

  • Hello Bret,

    Than k you for your response and advice.

    I am indeed interesting in the 2xDC project, and I'll look into trying what you explain when I'm next able to at work.

    The functionality I'm trying to achieve is to have a easy to modify project where you can specify pluses of motor on/off activity in milliseconds..

    (It's to aid in designing effective 'patterns' for a vibrating appliance.)

    I'll let you know if I have any further questions once I have tried what you explain above.

    Thank you again.

    Zen

  • Hello again Brett,

    Having some time free this morning I sat down at my desk and went though your advice, thank you.

    You explained perfectly what I need to edit to set the timers how I require them, and I can already see translating some of our more complex patterns into a series of calls using the other state machines.

    The only other question I have is the following;

    How exactly do I specify within B1 that I want only motor 1 to turn on for 500ms and then switch off.

    I'd then do the same with B2, but motor 2 on 500ms, off..

    I can see the solution in my head.. but do not know how to correctly translate that into TI syntax

    void B1(void) // Toggle GPIO-00
    {

        IRef1 = 0.25;   // motor 1 Current Ref
        DELAY_US(500);
        IRef1 = 0.0;
        //-----------------
         B_Task_Ptr = &B1;
        //-----------------
    }.

    Unfortunately this doesn't work, it builds and debugs fine, just doesn't do anything. (setting IRef1 in the watch window works as normal)

    Care to show me the correct way to write that ?

    Thank you again for the pointers.

  • Zen,

    Something like the attached was what I was thinking (where motorStateMachine and motorsPulsingEnabled are global variables).   This allows you to avoid using delays directly and therefore allows the bandwidth of the CPU to be spread between the various state machine tasks such as A1, A2, B1, C1, etc.  Note that within the function DELAY_US() the CPU will not be doing anything useful.

    However, you can accomplish your goal in many ways.  For example, you could go the route that you're thinking above, but I'd put your code within the 'forever' for loop at line 307 instead.  You'd then keep/move the code from A1 into the forever for loop and remove/comment-out all the code relating to the A0, A1, B1, etc state machine such as (*Alpha_State_Ptr)(); and all the associated functions (lines 329-448 in the original pjt).

    Hopefully, I've given you some ideas above...

    As for why your code isn't working, I believe EnableFlag may need to be set to TRUE at some point.


    Thank you,
    Brett

  • Brett,


    Thank you for the ideas, you've helped enormously.. its a real pain being the only tech person at my company as when I get stumped by somethign outside my normal area of training (such as this) I've no one to bounce ideas with.

    I'll have a crack at what you recommend later today when I have time (I'm busy doing QC tests most of the day) but I follow your line of thinking perfectly.

    With regards to my code attempt, I had enable set to true manually using real time debugging, but I'll move all the code into the forever loop just to check it works as it should.

    Thank you again, I know where to come now with future thoughts & questions.

  • Worked perfectly..

    Even been able to use your loop idea to alter CpuTimer1Regs.PRD.all timers within the B1{ }

    So I can do X loops of motor at 500ms then X at 50ms and back within the same state machine. /Cheer

    One last query.. because 2xDC motor in build mode 4 works by current control.. how could I adjust the voltage given out to one particular motor, but still use current to turn on/off..

    (Lets pretend I want to use a different motor for motor 2, and it can only cope with 3volts max) .. what would be the way to cap that, so it doesn't overheat. ?

  • So motor 1 is 24V whereas motor 2 is 3V?


    -Brett

  • Currently Yes (In this example the project has a  large motor and a very small one)

    But as I need to be able to adjust my project template for future product design assume any values you wish,

    I just need to know how to set 2 different max voltages for the 2 motors.

    If it makes things easier I don't "have" to use current control, (assuming build mode 4 can be altered to use voltage control) changing to voltage control the motors would not effect any of my work. But then I'd need to know how to set max currents for each motor. (again so I don't damage a smaller motor)

    either-way is fine, as my work currently is just to create visual examples of various on/off motor patterns using the dev kit.

    Thank you again, you've helped massively already. :)

  • Zen,

    I'm not an expert on this kit, so the first thing I would do is take a look at the voltage signals going to each motor when you run the kit normally.  (specifically Vhb1-Vhb4)

    If these signals are filtered adequately and kept relatively steady, these could serve as inputs into your controller.  Then by changing up the software and retuning the controller coefficients you could then control the voltage going to the motors directly.  Under this scheme, the C2000 would still look at the current to determine an over-current condition (this overcurrent could be checked directly using the ADC, or made to trip the PWMs via the on-chip comparator)

    Final question, will you be pulsing the motors in one direction, or will you go bidirectional?


    Thank you,
    Brett

  • Hello Brett,

    thanks for the ideas,

    I had a play about and I've got build mode 4 working with voltage control (though it could also be called build mode 2 with 2 motors :D )

    I've not blown up any motors yet.. (tested from 24v right down to 1v pager motors)

    Motors are one direction only, as they are there only to spin counterweights and produce vibration. (hint I design adult toys :p )

    I'm still having a few teething issues with state machine timers being spot on, but other than that everything works..

    I've even got a pair of motors pulsing to some black sabbath songs for a laugh ! ..

    Thank you for all the detailed help, you've enabled me to step into using a development kit I knew nothing about 2 months ago.. and use it to fulfill all the needs of my projects.

    I can't thank you enough.

    Have a wonderful week, and I know where to come with any future TI queries.

    Regards,

    Zen