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.

[PIC] Problem with Stepper Motor Simulation

Status
Not open for further replies.

georgio17

Newbie level 6
Joined
Aug 25, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
129
Hi i am newbie and i am just learning how to write programs in c for PIC 16f877a
I have written a code for rotating a stepper motor forward and backward.
Its basically i want to move the panel from morning 6 to evening 6 that is i want the motor to rotate 180 degrees in the entire 12 hour period and then quickly return to back its original position that is rotate revese by 180 degrees quickly and wait till 6 next morning to start rotating again.
The problem i have noticed is that in PROTEUS simulation i have set the stepper motor to move at an angle of 90* but in the first cycle it moves 45* and then by 90* each so when it comes back to its original position it does boack by -45* I dunno why this is.
Also what is the minimum delay i can implement on a stepper motor??
And i want to implement a delay of about 12 hours what code should i use or can i use a code to turn it off for 12 hours??
Could you'll please help me.
Sorry for asking so many questions but i would really help me to understand better.
Thank You
 

Attachments

  • proj.PNG
    proj.PNG
    16.5 KB · Views: 106
  • Project.rar
    16.9 KB · Views: 91
  • Code.txt
    575 bytes · Views: 96
Last edited:

You are using a bipolar stepper

change the code from


Code:
for(i=1;i<3;i++)
  { 
	PORTB=0X04;
	__delay_ms(1500);
	PORTB=0X02;
	__delay_ms(1500);
	PORTB=0X08;
	__delay_ms(1500);
    PORTB=0X01;
    __delay_ms(1500);
  }
  for(j=1;j<3;j++)
  { 
    PORTB=0X08;
    __delay_ms(500);
	PORTB=0X02;
    __delay_ms(500);
	PORTB=0X04;
    __delay_ms(500);
	PORTB=0X01;
    __delay_ms(500);
  }
 
Last edited by a moderator:
Thanks alot S.P.S..
It really helped me..
And thanks for the links jayanth.devarayanadurga.. It was good information
 

Hi there, Thanks for helping me..
I am now planning to expand my project cause i really have gotten into the mood of doing it.
I am planning to interface another motor to the pic but using the portD.
I want to know if it is possible to run both programs simultaneously cause i want to set different delay periods for the for both the motors but i need them to run simultaneously.
E.g I want a loop that turns the first motor to turn evey 2 minutes and simulataneously anothe loop to turn the 2nd motor after every 2 hours in the same process as the above program that is both forward and reverse directions.
Any suggestions or help..
Thanks once again..
 

using timer it is possible to do simultaneously rotate both motor .
 

Use two timers for the above task.you need to write Timer ISR for better operation.Do it yourself and post the code in case of error.


Regards.
 

what is step angle of steeper motor which is you used i think it may be of 0.9 degree so your getting exactly half rotation. try by using giving double pulses to stepper.
 

Thanks for your reply.
Sorry for the delay. Was having exams.
I decided to rotate the motor after i rotate the first motor backward as i have time.
I am finding interrupt hard to understand.
I expanded the code.
Just see what is the problem.
I am using isis stimulation and have written the program where after a count of 2 it rotates the motor by 1 step.
but after it rotates by one step the loop should start again at the firtst motor by counting from 0 till 2 but it doesn't stop at 2 and goes into a continous loop.
Please help me
I have put a video file along with it
Thanks again..
 

Attachments

  • Projectpro.rar
    292.7 KB · Views: 83

I fond the problem.. i had to remove that count=0 cause it was setting it to 0 when the if condition was not satisfied but still cant get it to work...
 

why u don't make a 2 loop like

Code:
int count = 0 , count1 = 0 ;
main()
{
while(1)
{
if(count ==  0)
{
    run first motor code here
    count1 = 1 ;
    count =  1 ;
}
if (count1 == 1 )
{
    run second motor code here
    count = 0 ;
   count1 = 0 ;
}
}
}
 

Thanks for your help..
I am trying to interface an lcd with the pic now..
I have stumbled on a problem..
The problem i find here is that if i write it as int am1 i get output as 1.0 (I want the output to show 1.8)
if i write it as double am1 i get an error saying operator not applicable to this operands
If i write it as long am1 it does not rotate properly i.e it turns 90 degrees and then 180* in the opposite direction (Considering Step Angle is 90*)
And can you tell me what does Lcd_Chr(1,10,48+am1); the 48+ part mean??
By the way i have shifted the code to mikroC as the lcd code was easily avaliable.
Thanks again for your time.
Is there any way where i can display it??

- - - Updated - - -

I got another problem also..
I have put 2 while loops if certain conditions are not satisfied..
Now after the while loops it should go to the infinite loop but after the first 2 for loops in the infinite loop it seems to start from the begining i.e. the while loop
Just see what is the problem..
 

Attachments

  • New Text Document (2).txt
    4.5 KB · Views: 77
  • LCD.rar
    80.1 KB · Views: 65
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top