Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Controlling stepper motor with rs232 and feedback pot

Status
Not open for further replies.

Varunme

Member
I want to control a stepper motor with rs232 with pot feedback , will the below algorithm works ?

Code:
position = adc_rd();
portd=0x00;




main(){

          while(position =! uart_read){     
               
            
           if (position < uart_read)                   
           { motor++};                  
          
                            

           elseif (position > uart_read)
           {motor-- };
             
            }
 
Last edited:
Yes logically it will work...
As you are taking the value from ADC and reading the value from the UART, after that you are comparing and accordingly the action will be taken...
 
that you can always put in the condition... that what you want to do when the UART value is not equals and when it is equals to...
Something like these
while(1)
{
if (position =! uart_read)
{
statement or condition as required
}

if (position == uart_read)
{
statement or condition as required
}

}
 
So, it can be modified as

Code:
while(1)
{
            if (position =! uart_read)
             {
                          if (position < uart_read)                   
                          { motor++};                  
 
 
 
                         elseif (position > uart_read)
                         {motor-- };
 
            }
}

            if (position == uart_read)
            {
            motor_stall();
            }

}

isnt it ?
 
The below code works in only the first if condition , that is whatever the value I sent through UART , poftb.f1 is activated and print "1" in serial terminal




Code:
         while(1)      {

           if ( ulong =! tlong )
             {
                          if ( ulong < tlong )
                          { PORTB.f1=1;
                          UART1_Write_Text("1");
                          break;
                          }
                          else if ( ulong > tlong )
                         {PORTB.f2=1;
                         UART1_Write_Text("2");
                         break;
                         }

           

           }
            if ( ulong == tlong )
            {
            PORTB.f3=1;
            UART1_Write_Text("3");
            break;
            }

          }


My intention is make a controller which adjust itself equal to the analog value sent through UART

by a stepper motor and pot ,
just for test , i just added the UART_write() and the portb bits to high when a condition is satisfied .
 
Last edited:
Hi Varun,

I am not finding any problem in logic what you have applied and i understood ur intension that wat you want exactly.
And one more thing there is no need of else if there it could be ok with else only, because either ulong<tlong or ulong>tlong.

May if possible can you monitor your both value i.e. ulong and tlong on the debugger if you have.
because i think there is some problem with your values of ulong and tlong.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top