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.

program to control stepper motor

Status
Not open for further replies.

Tiabak

Newbie level 3
Newbie level 3
Joined
Apr 13, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,310
Hi everybody

i have a problem to program my 16f877A to control a stepper motor via uln2003A in order to guide my solar tracker.
the analogic inputs of the pic are RA0 and RA1 who are connected to ldr,and the output are the impulsions send from PORTD to the uln2003A after the stepper motor. some information :
Vref+=5v, Vref-=2v,clock=8Mhz
this is my schema in proteus :




and this is my code in mikroc :

unsigned long sens1;
unsigned long sens2;
void main() {
ADCON1=0b10001000;
TRISA=0xff;
PORTA=0x00;
TRISD=0x00;
PORTD=0x00;
while(1){
sens1=ADC_Read(0);
sens2=ADC_Read(1);

while(sens1>sens2){

PORTD=0b00000001;
delay_ms(50);
PORTD=0b00000100;
delay_ms(50);
PORTD=0b00000010;
delay_ms(50);
PORTD= 0b00001000;
delay_ms(50);
if(PORTD==0b00001000)PORTD=0b00000001 ;
}
while(sens1<sens2){
PORTD=0b00000001;
delay_ms(50);
PORTD=0b00001000;
delay_ms(50);
PORTD=0b00000010;
delay_ms(50);
PORTD=0b00000100;
delay_ms(50);
if(PORTD==0b00000100)PORTD=0b00000001;

}
if(sens1==sens2) PORTD=0x00;
}
}

the simulation was som strange :s
pleaseeeeeeeeeeeee help me it's urgent
 

the problem is the sens of rotation,normaly when sens1>sens2 the stepper motor turn in the right and if sens2>sens1 it turn into the left. but in my simulation,thr stepper motor turn in one sens. and how do i do to control the speed of the rotation ? or it's not important ?
thank you

- - - Updated - - -

http://obrazki.elektroda.pl/9677430200_1365887964.jpg
 

To control spped you have to change the delays. You have used 50 ms delay. use a variable like ms in the delay function like delay_ms(ms); and use a button to increment or decrement the value of ms on every button press. You can use ms = ms + 1; and ms = ms - 10; for increment and decrement. Use a button code with debounce of 30 or 50 ms. Also check if ms > max value then ms = 0 and if ms < 0 then ms = max value.

Write a code and I will help you.
 
  • Like
Reactions: Tiabak

    Tiabak

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top