This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STEPPER MOTOR PROBLEM

Can any body give me a good source code for controlling the 12 volt stepper motor speed .I am using Atmel's 89C52 controller.I am just using 4 pins of my port-1 to energize the motor's windings. this is the the code unit which i work for but its not wotking some how,

*********************************************
int i,j;
unsigned char STEP[4] = {0x0A,0x09,0x05,0x06};
//these r my switching sequence for my unipolar stepper motor//
while(1)
{
for(i =0;i<4; i++)
{
P1 = STEP[i];
for(j=0;j<5;j++)
{
_nop_();
}
}
}

  • "12 volt stepper motor ... just using 4 pins of my port-1"

    Are you sure that the port pins can directly drive a motor??

    Are you sure that the timing of your code is correct?

    Please follow the instructions and use the pre and /pre tags when posting code!

  • Can you be clearer about what it is that is not working?

    One thing that strikes me is that the inner delay loop is very short. Your stepper motor may not be able to instantly accelerate to the implied speed.

    int i,j;
    unsigned char STEP[4] = {0x0A,0x09,0x05,0x06};
    //these are my switching sequence for my unipolar stepper motor//
    int delay = 1000;
    while(1)
    {
        for(i = 0; i < (sizeof(STEP)/sizeof(STEP[0])); i++)
        {
            P1 = STEP[i];
            for(j=0;j<delay;j++)
            {
                _nop_();
            }
            if( --delay == 4 )
            {
                delay = 5;
            }
        }
    }
    

  • Hi,

    We use the 89c52 with stepper motors but they are connected via stepper driver ic's and allow us to have very precise control over them, but here is a link http://motion.sourceforge.net/tracking/
    with a very simple inplementation that you may find useful (even some example code!).

    http://www.doc.ic.ac.uk/~ih/doc/stepper/control2/connect.html is also another example of a very similar solution using a darlington driver to drive the stepper as I feel that you have got to address this problem first, then as has aready been said you will need to start off with a long delay bewteen steps gradually reducing that time as the motor accelerates.

    Hope this Helps,
    Mark

  • Thanx, for your response
    Regarding your question ... No stepper motor is not driven directly but they are driven through the Darling driver ULN2064B.... ULN2003 i am not using because ... my motor has got two stacks and each draws 0.475A of current which exceeds the current handling capacity of ULN2003 (i.e. around 0.5A)

  • Thanx Mr. Cole for your valuable suggestion.
    I have one query regarding the modified code you have suggested to me..... i.e. the codition ********************
    if( --delay == 4 )
    {
    delay = 5;
    }
    ********************
    I don't understand why this is here? Can you plaese suggest me for the same?
    Regards
    Saurabh Raval

  • I have not actually tried out the code that I suggested, it is just there to give a general idea. The reason for the code block that you highlight is to ensure that delay cannot get too short - cannot be less than 5 in this case. The minimum delay needs to corespond with the maximum possible speed of your stepper motor.

    You should be able to look up the maximum speed of your stepper motor on its data sheet. The maximum possible acceleration will depend on the power of the motor versus the load you have to drive.

    Unless your system is very simple, you might want to think about driving the stepper motor from an interrupt function so that the processor can do other things while the motor is being driven.

    Please let me know how you get on.

  • Thanx Mr. Cole....
    I tied out with your suggestion of increasing tthe delay.....but still some times it just gets stucked up..... I don't know why.... can you please suggest me as you have suggested me for the previous problem... thanx again
    Regards
    Saurabh

  • In what way does the motor get stuck? Timing is everything, so are you either driving the motor past its maximum speed or acceleration?

    I might help to start with a single phase driver just to verify that there are no fundemental problems with you driver circuit.

    Driving stepper motors should be fairly straightforward, but the details of the characteristics of a particular motor and its load are very important.

    There is loads of information on the internet. There is some basic information here: http://209.41.165.153/stepper/Tutorials/UniTutor.htm