Stepper motor control

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Stepper motor control

Postby wjwong » Sat Nov 05, 2011 5:03 pm

Any example of programming stepper?

90 degree = 50 step
+50step =100step
-100step =0degree
Attachments
stepper.jpg
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Stepper motor control

Postby robosang » Wed Nov 09, 2011 8:26 pm

:mrgreen:
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Stepper motor control

Postby shahrul » Thu Nov 10, 2011 11:30 am

Did you understand how stepper motor operates? What programming you have done on it?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Stepper motor control

Postby kl84 » Thu Nov 10, 2011 12:46 pm

I think it's going to be much easier for you (if you are a newbie) to follow this:
http://www.arduino.cc/en/Tutorial/StepperUnipolar
User avatar
kl84
Amateur
 
Posts: 166
Joined: Thu Jul 08, 2010 12:14 pm

Re: Stepper motor control

Postby wjwong » Mon Nov 14, 2011 11:30 pm

CODE: SELECT_ALL_CODE
#define sw1         RD1
#define Relay      RB1
#define led_error1   RB2
#define led_error2   RB3
#define led1      RC1
#define led2      RC2
#define led3      RC3
#define led4      RC4
//   function prototype
//==========================================================================
void delay(unsigned long data);


//   global variable
//==========================================================================


//   main function
//==========================================================================

void main(void)
{

   //assign variable
   unsigned char A,B,C               //declare a temporary variable for reading ADC


   //unsigned char mode;               //declare a variable to represent current mode
   
   //set I/O input output
   TRISA=0b11111111;               //Ensure port A bits input
   TRISC=0b00000000;               //Ensure port C bits output
   TRISD=0b11111111;               //Ensure port D bits input
   TRISB=0b00000000;               //Ensure port B bits output


   //configure ADC
   ADCON0=0b10000001;               //enable ADC converter module
   ADCON1=0b10000100;               //configure ADC and ANx pin//configure ADC
   
   //initial condition
   led1=0;
   led2=0;
   led3=0;
   led4=0;

while(1)                     //infinity loop
   {
      if(sw1==0)                //if SW1 OFF
      {
         
         if(PORTC==0b00000000)         //Stepper at 0degree
         {
            PORTC=0b00000000      //Stepper return 0degree
            
   
         }
         else if(PORTC==0b00000101)      //Stepper at 90degree
         {
            B=00000101;         //Stepper return 0degree
            PORTC=PORTC&B;
            
            
   
            
         }
         else if(PORTC==0b00001001)      //Stepper at 180degree
         {         
            C=00000011;
            D=PORTC^C;
            PORTC=~D;         //1001^0011 then =~(0101)
            if(PORTC=00000101)
            {
               B=00000101;      //Stepper return 0degree
               PORTC=TRISC&B;
            }   
            
            
         }



   }
      else if(sw1==1)               //SW1 ON
      {
         


      }

//i have no idea on minebea stepper motor full stepping sequence "I just temporarily follow theory and waiting stepper motor to try" This is my first times on PIC in C hopes i doing right~~
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Stepper motor control

Postby wjwong » Mon Nov 14, 2011 11:32 pm

Table Three. The normal sequence.

Step Q4 Q3 Q2 Q1

1 0 1 0 1

2 1 0 0 1

3 1 0 1 0

4 0 1 1 0


If sequence confirm is better to use shifting on C?
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Stepper motor control

Postby shiyan » Tue Nov 15, 2011 7:45 am

wjwong WROTE:Table Three. The normal sequence.

Step Q4 Q3 Q2 Q1

1 0 1 0 1

2 1 0 0 1

3 1 0 1 0

4 0 1 1 0


If sequence confirm is better to use shifting on C?


You need to try before you ask question, that's call learning. So how are you going to shift the above sequence in C?
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 4 guests