Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Tumpes
PostPosted: May 16, 2012 - 07:00 PM
Newbie


Joined: Apr 14, 2012
Posts: 5
Location: Eldoret,Kenya

need a c code to step a stepper in individual steps i.e if i need to move a stepper one step, a function like

MoveSTEPPER(6); should move the motor 6 steps

Regards.
 
 View user's profile Send private message  
Reply with quote Back to top
MBedder
PostPosted: May 16, 2012 - 07:15 PM
Raving lunatic


Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia

You need it - you write it, what's the problem?

_________________
Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
 
 View user's profile Send private message  
Reply with quote Back to top
Tumpes
PostPosted: May 16, 2012 - 08:05 PM
Newbie


Joined: Apr 14, 2012
Posts: 5
Location: Eldoret,Kenya

MBedder wrote:
You need it - you write it, what's the problem?


The problem is am still a newbie and i tried to develop the code bt was unable.the code i developd is shown below.it can only move the motor four steps or multiples of four.

void ForwardStepperMotor()
{
for(unsigned int x=0; x < 6; x++)
{
//Normal Bipolar Stepping,forward
PORTD = 0X50;
_delay_ms(100);
PORTD = 0X48;
_delay_ms(100);
PORTD = 0X28;
_delay_ms(100);
PORTD = 0X30;
_delay_ms(100);

}
}


kindly help!
 
 View user's profile Send private message  
Reply with quote Back to top
ka7ehk
PostPosted: May 16, 2012 - 08:37 PM
10k+ Postman


Joined: Nov 22, 2002
Posts: 12052
Location: Tangent, OR, USA

How are you driving the motor from PortD?

Jim

_________________
Jim Wagner
Oregon Research Electronics, Consulting Div.
Tangent, OR, USA

"The only thing standing between us and victory is defeat" P.G.Wodhouse in Wooster & Jeeves series
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 16, 2012 - 08:41 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13847
Location: Vancouver, BC

Create an array that holds the 4 values you need for assigning to PORTD, keep track of the current index into the array for the current step. Use that in the for loop to step the motor.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: May 16, 2012 - 09:23 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21271
Location: Orlando Florida

Welcome to the AVRfreaks forum. Thank you for filling in your city and country. Please search for 'jones on stepper motors' on google. This is a good explanation of how to drive the stepper motors. There are many projects in the projects section here also. If there are 4 outputs driving the coila and coilb on the low 4 bits of portd, you energize them in this sequence:0b0101 0b0110 0b1010 0b1001 then back to the start 0b0101. Step thru the table backwards to step backwards.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Tumpes
PostPosted: May 16, 2012 - 10:26 PM
Newbie


Joined: Apr 14, 2012
Posts: 5
Location: Eldoret,Kenya

ka7ehk wrote:
How are you driving the motor from PortD?

Jim


its a Bipolar stepper motor and am using two Toshiba half-bridge chips(TA7291SG) to drive the motor.
am wondering if its possible to write a function that makes it possible to step the motor in single steps according to the parameter of the function eg
stepmotor(int steps)
{
}
The function can then be used to step the motor a given number of steps by specifying the function parameter for example,to step seven steps the function can be called;

stepmotor(7);
 
 View user's profile Send private message  
Reply with quote Back to top
Tumpes
PostPosted: May 16, 2012 - 10:29 PM
Newbie


Joined: Apr 14, 2012
Posts: 5
Location: Eldoret,Kenya

bobgardner wrote:
Welcome to the AVRfreaks forum. Thank you for filling in your city and country. Please search for 'jones on stepper motors' on google. This is a good explanation of how to drive the stepper motors. There are many projects in the projects section here also. If there are 4 outputs driving the coila and coilb on the low 4 bits of portd, you energize them in this sequence:0b0101 0b0110 0b1010 0b1001 then back to the start 0b0101. Step thru the table backwards to step backwards.


Thanx 4 the quick reply.the sequence makes the motor move 4 steps.is it possible to step the motor a given number of steps eg 2 steps,7 steps

Regards
 
 View user's profile Send private message  
Reply with quote Back to top
Tumpes
PostPosted: May 16, 2012 - 10:32 PM
Newbie


Joined: Apr 14, 2012
Posts: 5
Location: Eldoret,Kenya

Koshchi wrote:
Create an array that holds the 4 values you need for assigning to PORTD, keep track of the current index into the array for the current step. Use that in the for loop to step the motor.


This seems a great solution.could please help with example code,thnx
 
 View user's profile Send private message  
Reply with quote Back to top
lincoln
PostPosted: May 16, 2012 - 10:51 PM
Hangaround


Joined: Jul 22, 2011
Posts: 146
Location: San jose, CA, USA

What part of what Koshchi wrote are you having a problem with?

One way to go about it from C would be:
Code:

/*** varables section ****/
// array for step values
// index of above array storing current motor position

/*** subroutine section ***/
void stepmotor_cw(int steps) {
   //loop until steps = 0
      //add one to index
      // figure out if index is too big and set to 0 if so
      // copy array[index] to stepper pins
       // delay some amount to let the stepper actually move
      //subtract 1 from steps
      // go to loop


}

void stepmotor_ccw(int steps) {
   //loop until steps = 0
      //subtract one to index
      // figure out if index is too small and set to 3 if so
      // copy array[index] to stepper pins
      // delay some amount to let the stepper actually move
      //subtract 1 from steps
      // go to loop

}

/** main section **/

main(){
  //setup portd to be outputs
  for(;;){
     // your awesome app code gos here
  }



Bonus points for figuring out how to write stepmotor( steps, direction)

Almost every one here is happy to teach you how to fish, however this is not a fish market. Smile

_________________
link

i am a NOOO00B!!

Don’t let that undermine what I just said.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
bobgardner
PostPosted: May 17, 2012 - 12:45 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21271
Location: Orlando Florida

Actually, I would be willing to show him my complete compilable example if I knew that would suddenly make it all coalesce into a sensible result. This is the Instant Of Learning when the Aha! happens.
To Mr. Kumpes from the land of Fast Runners: the dude from San Jose is from the world epicenter of computers, electronics and software innovation. I think it is Safe To Say that if you convert each one of his comments into a syntactically correct c statement, you will have a compilable working program that you and the other freaks can critique and debug.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
metron9
PostPosted: May 17, 2012 - 04:40 AM
Resident


Joined: Aug 25, 2005
Posts: 911
Location: U.S.A

You must also control the timing of the steps.
A sub routine that performs a loop to step a motor more than 1 step that also incorporates time delays can be very poor code if your AVR is doing other threaded tasks.

I set up as Koshchi suggests for the 4 (or other number) steps and then put your step output in a timer interrupt. Simply set the new position of the stepper in a global variable and the timer ISR functions on it's own similar to putting a character in the USART and the hardware performs the timing of the output of all the bits.

So you call a routine to set the stepper at a new position and then check your DRO values (updated by the ISR) to see when the motor has reached that position. That allows you to monitor limit switches, output data and other things while the hardware interrupt controls the smooth ramp speed up and down to the desired position. Yo can't just start a stepper at top speed and stop it on a dime if you plan to use the top speed of a stepper or it will just hum. Use the frequency of the ISR and change the frequency inside the isr after each step. you can also calculate ramp speed using the delta of where the motor is and where it is going as well as change on the fly from 1/8 step to full stepping while at top speed and back down to 1/8 steps (or other smaller steps) depending on the complexity of the driver circuit, current control etc...
 
 View user's profile Send private message  
Reply with quote Back to top
haker_fox
PostPosted: May 17, 2012 - 06:10 AM
Resident


Joined: Oct 15, 2005
Posts: 530
Location: Russia, Far East Siberia, Irkutsk

Tumpes wrote:
This seems a great solution.could please help with example code,thnx

I'd suggest to read some literature about "C programming" to you. You also should read some book about stepper motor control.
Your questions are quite simple. You'll pay one - two days to study the stuff.
If you haven't got studied it now you'll not be able to solve more difficult problems... IMHO.

Good luck!
 
 View user's profile Send private message  
Reply with quote Back to top
lincoln
PostPosted: May 17, 2012 - 06:12 AM
Hangaround


Joined: Jul 22, 2011
Posts: 146
Location: San jose, CA, USA

Hello metron9,
ya, ya, still need to start at the basics. Smile

_________________
link

i am a NOOO00B!!

Don’t let that undermine what I just said.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits