Zwilorg
Member level 5

Hello,
i am in need of some help trying to control the speed of a stepper motor...
Explanation:
1-receive a string from rs232
2-write it to a variable ("speed")
3-get it to work on a loop that increases the delay of each step on the motor.
i am posting a sample of my work to explain more or less what i am trying to to.
This works for 1 to 2 seconds before entering in an endless loop...
and being the while loop i need to insert numbers lower than 1 on the speed!
if i can´t get it working like this i would like someone to help get it to work using a for statement or something of the kind.
Decreasing the value just like an usual for cycle
i prefer this idea... because i would only need to get the value received from rs232 to the variable and then get it decreased from the value (for example 100) to 0 and each time causing a delay on the motor of 1second
but i can´t get it working and i don´t have sufficient knowledge in C to make the for loop a subroutine to be called after each step.
I hope you understand my problem :|
i am in need of some help trying to control the speed of a stepper motor...
Explanation:
1-receive a string from rs232
2-write it to a variable ("speed")
3-get it to work on a loop that increases the delay of each step on the motor.
i am posting a sample of my work to explain more or less what i am trying to to.
Code:
unsigned int speed;
void System_init(void)
{
TRISB = 0b00000000; //set B1-B7 as output, B0 as input
}
void delay_manualms(unsigned int ms)
{
while (ms--) __delay_ms(1);
}
void main(void)
{
System_init();
while(1)
{
PORTB=0b00000001; //Step 0
delay_manualms(speed);
PORTB=0b00000011; //Step 1
delay_manualms(speed);
PORTB=0b00000010; //Step 2
delay_manualms(speed);
PORTB=0b00000110; //Step 3
delay_manualms(speed);
PORTB=0b00000100; //Step 4
delay_manualms(speed);
PORTB=0b00010100; //Step 5
delay_manualms(speed);
PORTB=0b00010000; //Step 6
delay_manualms(speed);
PORTB=0b00010001; //Step 7
delay_manualms(speed);
}
}
This works for 1 to 2 seconds before entering in an endless loop...
and being the while loop i need to insert numbers lower than 1 on the speed!
if i can´t get it working like this i would like someone to help get it to work using a for statement or something of the kind.
Decreasing the value just like an usual for cycle
Code:
for(speed; i = 0;i--){
__delay_ms(1);
}
i prefer this idea... because i would only need to get the value received from rs232 to the variable and then get it decreased from the value (for example 100) to 0 and each time causing a delay on the motor of 1second
but i can´t get it working and i don´t have sufficient knowledge in C to make the for loop a subroutine to be called after each step.
I hope you understand my problem :|