Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877A and Bipolar Stepper motor

Status
Not open for further replies.

nick703

Advanced Member level 1
Joined
Oct 17, 2011
Messages
422
Helped
21
Reputation
44
Reaction score
22
Trophy points
1,298
Location
surat
Activity points
3,987
Hello Friends,

I want to rotate 4 Stepper Motor Using PIC16f877a. i have a Stepper motor Driver of TMC2100 and Bipoar Stepper Motor. So i use Stepper Motor Driver 2 pin PULSE and DIR.

so my question is how to rotate 4 stepper motor using 3 timer of pic16f877a. is that possible to rotate different speed of stepper motor using same timer of pic ? i have to rotate 4 stepper motor using pic timer but different speed. and also pic16f877a has 3 timer . i am using timer of PIC to generate pulse.

please give me hint what can i do.
 

You can set the timer to whatever resolution you want for the stepper motors. For example, if you want one to have a frequency of 2KHz and the other of 3KHz (making up the number here for the illustration - also I don't know these devices but the underlying principle is correct if they are not PWM driven) then you make the timer at 6KHz (2*3) and every 2nd interrupt to trigger the 3KHZ motor and every 3rd you trigger the 2KHz motor).
In other words, set the timer to integer multiples of the triggers you want and have individual counters.
Susan
 

Hi,

If it is possible or not depends on your needs.
All motirs running with independent frequencies, high frequencies, low jitter...all at once will not be possible.

But if you can live with a timing granularity of 1ms...then you could even run all motors from one timer.
Maybe down to 100us, maybe even less..

It also depend what other task have to be processed by the microcontroller. Maybe ramp up, ramp down, calculating speed, position and doing other mathematics in real time... trigonometric functions, PID regulation loop...we don't know.

Klaus
 

thank you for reply. so basically using one timer to rotate multi motor is complex. but give me some logic or some hint to run only 2 motor with single timer with different frequency of any pic16f877a.
 

Not complex but you do need to review your actual requirements and see if the technique is applicable. Implementing it is quite straight forward.
Susan
 

yes right but actually i have do motor rotate algorithm is below
Code:
StepperA()
{
timer 0 off
     // on Bit of Specific Port (PORTB.F0)
     DelayuS(20);
    //  on Bit of Specific Port (PORTB.F0)
    And last genrate timer delay
   timer 0 on 
load value
}
// and same as other but use different timer
StepperB();
StepperC();
StepperD();

and isr routine of specific timer and same as other
isr motorA ()
{
   stepperA();
}

main()
{
  if(Some Button Start here)
  {
      rotate all motor code here
   }
  else 
  {
     stop all motor code here
  }
}

so confuse me last motor rotate with which timer because of pic16f877a running with 3 timer. and also can i use pwm for pulse generate last motor D ?
 

Hi,

Run an ISR timer controlled with relatively high frequency.
For each motor you need to decide if it should do the next step or not.

For stepper motors I recommend to do it NCO style.
NCO has the benefit of linear speed adjustment.
In many cases a one byte solution is sufficient. 0 = stop, 0 to 255 means 0 to 100% speed. 255 equal steps in speed.

What timer frequency to choose depends on your motor speed needs.
It must be at least twice the max motor step frequency.

What is your max motor step frequency?
What is your min motor steps frequency (> 0)?
What frequency resolution do you need? (How many different speed values)?
If you want us to do some calculations, then we need values.

Klaus
 

but give me some logic or some hint to run only 2 motor with single timer with different frequency of any pic16f877a.

Let us say that motor 1 need pulses every m sec and motor 2 need pulses every n sec (don't worry too much about the scales; you can assume that sec means msec); m and n must be integral values.

let the timer interrupt one service routine every sec; keep a counter in the ISR and increment the counter by 1 every interrupt.

If the counter is divisible by n produce a pulse for motor 1;
if the counter is divisible by m produce a pulse for motor 2;
if the counter is close to overflow (within n X m cycles), reset the counter.

A simple test for divisible is (counter/n)*n ==counter.

It is good to reset the counter to zero at every n * m sec and also the timer.
 

here is my some code and Proteus file but stepper motor is not running . please give me some resolution to rotate stepper motor . below is the proteus file and micro c code.
 

Attachments

  • test.rar
    44.8 KB · Views: 61

I assume that the code file is the only '.c' file in that rar file (i.e. StepperRotateADCTest.c)
For a start, never put a delay function into an ISR.
I'm not sure what you program is actually supposed to do. Perhaps the following pseudo-code might help get across what we are trying to tell you
Code:
#define task1Reset 4
#define task2Reset 7
volatile task1Counter;
volatile task2Counter;
volatile task1Flag;
volatile task2Flag;
void interrupt()
{
    TMR0 = <whatever the correct reset value should be>
    TMR0IF_bit = 0;

    // See if we need to trigger task 1 into action
    if( 0 == --task1Counter)
    {
        task1Flag = 1;  // Tell the main loop that task 1 needs to run
        task1Counter = task1Reset;  // Reset the counter
    }

    // Similarly, see if we need to trigger task 2 into action
    if( 0 == --task2Counter)
    {
        task2Flag = 1;  // Tell the main loop that task 2 needs to run
        task2Counter = task2Reset;  // Reset the counter
    }
}

main()
{
    <set up the processor, oscillator etc>
    task1Flag = 0;
    task1Counter = task1Reset;
    task2Flag = 0;
    task2Counter = task2Reset;
    <set up the timer with the base period>
    while(1)
    {
        if( task1Flag)
        {
            task1Flag = 0;
            <do whatever needs to happen for task 1>
        }
        if( task2Flag)
        {
            task2Flag = 0;
            <do whatever needs to happen for task 2>
        }
    }
}
Lets assume that the timer will go off every milliSecond. That means the code for 'task1' will be called every 4 milliseconds and the code for task 2 will be called every 7 milliseconds.
Of course, every 28 mSec, both tasks will be triggered at once but that is exactly what is supposed to happen anyway.
This assumes that the code for each task can be completed within a mSec or that any delays while one task executes does not affect the other task. If you are driving a fan this may or may not be the case.
As you can see, you can control 2 things (that I've called tasks here) with different timings form the same timer.
You can then apply the principle to your own case.
Susan
 

Hi,

Why can't you give values and specifications?
All the values I see in this thread come from those, who wants to help you, as examples.
But no value from you...
Are you sure you want a solution? Or just want to keep us busy?

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top