|
|
View previous topic :: View next topic |
Author |
Message |
zeyad
Joined: 24 Feb 2015 Posts: 22
|
stepper motor for loop |
Posted: Mon Mar 02, 2015 9:52 pm |
|
|
Code: | #include <18f6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20M)
//int16 table[4]={3,6,12,9};
int8 ax[4]={9,12,6,3};
void s1(unsigned int rev)
{
int j;
int i=0;
for(i=0;i<(rev*360/1.8);i++){
output_b(ax[i%4]);
for (j=1000;j<50;j--){
delay_ms(j);
}
}
}
void main()
{
//setup_adc_ports(NO_ANALOGS);
//set_tris_c(0xff);
//set_tris_b(0x00);
do{
s1(1);
}while(true);
}
|
My stepper motor is not rotating more than 1.8 degrees. What i want to do is to gradually ramp up the stepper motor. Please help.
Last edited by zeyad on Wed Mar 04, 2015 4:24 am; edited 3 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 02, 2015 10:56 pm |
|
|
ckielstra told you not to use 'short' in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=53579&start=4
But you are still doing it here:
Quote: |
void s1(unsigned short rev)
{
int16 j;
int16 i=0;
|
We expect you to read everything we say, and fix every problem. |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
thnx |
Posted: Tue Mar 03, 2015 5:25 am |
|
|
|
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
still didn't work |
Posted: Tue Mar 03, 2015 5:33 am |
|
|
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Mar 03, 2015 6:10 am |
|
|
Your code is neither complete nor compilable.
You do not have a main().
Follow the instructions/advice given in previous threads.
Read the forum guidelines.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Mar 03, 2015 8:26 am |
|
|
this...
int16 table[4]={3,6,12,9};
int16 ax[4]={9,12,6,3};
seems 'silly' to me as
1) the data are not 16 bit values
I am 'assuming' the 3,6,12,9 would be better shown as binary ( bits) to visually show others the 'stepper motor' control signals. I'd probably use unsigned int8 or char. Char is the same as unsigned int8 but I always think of it a 0-255 as 'int' to me is -127 to +128.
2) one table could be used
This would save space, make coding easier,faster,etc. You can got 'forward' and 'reverse' using + or - in the index variable.
Also table[] and ax[] really do not say WHAT the data is for. CCS C allows you to name them with 'real' names like 'stepping_motor_drive_sequence' or something shorter, similar. It's really help you and others debug when you name variables with their intended use...
Jay |
|
|
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
Stepper speed ramp up and down |
Posted: Tue Mar 03, 2015 2:29 pm |
|
|
I use bipolar stepper motors and save a lot of headaches by using driver boards such as you can get from Sparkfun and Pololu. These usually accept three inputs such as Enable, Step and Direction. A typical routine I use for ramping up and down is here: Code: |
unsigned int16 i, j, memLength // globals - counters and desired total length of wire in .2" increments
void Feed( void )
{
output_low( M1ENA );
output_high( M1DIR );
for( j=325L; j>240; j--){ // Speedup for 1 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( j*5 );
}
for( j=0; j<memLength-10; j++) {
for( i=0; i<17; i++ ) { // 1/5 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( 1200 );
}
}
for( j=240; j<325L; j++){ // slowdown for 1 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( j*5 );
}
output_high( M1ENA );
}
|
I use this to feed wire off a large reel an have a little bit of a ramp to avoid jerking on the reel or slipping the wire in the feeder. The ideal step spacing for this particular motor is 1200 microseconds (us) between steps. To ramp up I start out with 1625 us per step and decrease that in a loop. When I slow down I just do the reverse. If you need a more gradual ramp just change the timing some more. I'm using the default 200 steps per rev, which was "good enough" for me. Some boards support up to 3200 steps per revolution, allowing for very detailed control and smooth ramping.
You can see this in action here: http://youtu.be/qVjijZRdiTA _________________ Jürgen
www.jgscraft.com |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
Re: Stepper speed ramp up and down |
Posted: Wed Mar 04, 2015 4:12 am |
|
|
jgschmidt wrote: | I use bipolar stepper motors and save a lot of headaches by using driver boards such as you can get from Sparkfun and Pololu. These usually accept three inputs such as Enable, Step and Direction. A typical routine I use for ramping up and down is here: Code: |
unsigned int16 i, j, memLength // globals - counters and desired total length of wire in .2" increments
void Feed( void )
{
output_low( M1ENA );
output_high( M1DIR );
for( j=325L; j>240; j--){ // Speedup for 1 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( j*5 );
}
for( j=0; j<memLength-10; j++) {
for( i=0; i<17; i++ ) { // 1/5 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( 1200 );
}
}
for( j=240; j<325L; j++){ // slowdown for 1 inch
output_high( M1STP );
delay_us( 1 );
output_low( M1STP );
delay_us( j*5 );
}
output_high( M1ENA );
}
|
I use this to feed wire off a large reel an have a little bit of a ramp to avoid jerking on the reel or slipping the wire in the feeder. The ideal step spacing for this particular motor is 1200 microseconds (us) between steps. To ramp up I start out with 1625 us per step and decrease that in a loop. When I slow down I just do the reverse. If you need a more gradual ramp just change the timing some more. I'm using the default 200 steps per rev, which was "good enough" for me. Some boards support up to 3200 steps per revolution, allowing for very detailed control and smooth ramping.
You can see this in action here: http://youtu.be/qVjijZRdiTA |
thnx alot this helps me alot |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
now see please |
Posted: Wed Mar 04, 2015 4:25 am |
|
|
Mike Walne wrote: | Your code is neither complete nor compilable.
You do not have a main().
Follow the instructions/advice given in previous threads.
Read the forum guidelines.
Mike |
Code: | #include <18f6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20M)
//int16 table[4]={3,6,12,9};
int8 ax[4]={9,12,6,3};
void s1(unsigned int rev)
{
int j;
int i=0;
for(i=0;i<(rev*360/1.8);i++){
output_b(ax[i%4]);
for (j=1000;j<50;j--){
delay_ms(j);
}
}
}
void main()
{
//setup_adc_ports(NO_ANALOGS);
//set_tris_c(0xff);
//set_tris_b(0x00);
do{
s1(1);
}while(true);
}
|
My stepper motor is not rotating more than 1.8 degrees. What i want to do is to gradually ramp up the stepper motor. Please help. |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
now see please |
Posted: Wed Mar 04, 2015 4:26 am |
|
|
temtronic wrote: | this...
int16 table[4]={3,6,12,9};
int16 ax[4]={9,12,6,3};
seems 'silly' to me as
1) the data are not 16 bit values
I am 'assuming' the 3,6,12,9 would be better shown as binary ( bits) to visually show others the 'stepper motor' control signals. I'd probably use unsigned int8 or char. Char is the same as unsigned int8 but I always think of it a 0-255 as 'int' to me is -127 to +128.
2) one table could be used
This would save space, make coding easier,faster,etc. You can got 'forward' and 'reverse' using + or - in the index variable.
Also table[] and ax[] really do not say WHAT the data is for. CCS C allows you to name them with 'real' names like 'stepping_motor_drive_sequence' or something shorter, similar. It's really help you and others debug when you name variables with their intended use...
Jay |
Code: | #include <18f6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20M)
//int16 table[4]={3,6,12,9};
int8 ax[4]={9,12,6,3};
void s1(unsigned int rev)
{
int j;
int i=0;
for(i=0;i<(rev*360/1.8);i++){
output_b(ax[i%4]);
for (j=1000;j<50;j--){
delay_ms(j);
}
}
}
void main()
{
//setup_adc_ports(NO_ANALOGS);
//set_tris_c(0xff);
//set_tris_b(0x00);
do{
s1(1);
}while(true);
}
|
My stepper motor is not rotating more than 1.8 degrees. What i want to do is to gradually ramp up the stepper motor. Please help. |
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Wed Mar 04, 2015 4:42 am |
|
|
Data type and order of operations
Quote: | void s1(unsigned int rev)
{
int j;
int i=0;
for(i=0;i<(rev*360/1.8);i++){
output_b(ax[i%4]);
for (j=1000;j<50;j--){
delay_ms(j);
}
}
} |
You're performing float math on an integer and are you sure your equation is doing what you intend? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Wed Mar 04, 2015 4:45 am |
|
|
You are still ignoring lots of things you have been told. I'll put some comments in part of your code, _read them_:
Code: |
{
int j;
int i=0;
for(i=0;i<(rev*360/1.8);i++){
//rev *360, will overflow the maths being used as soon rev>1
output_b(ax[i%4]);
for (j=1000;j<50;j--){
//What is the biggest number that 'j' can hold?.
//Is the loop ever going to execute?. j is never '<50' so loop
//will exit immediately.
delay_ms(j);
//If it did work, just how long is this going to take?. 1 step per second
//at the start!.....
}
}
}
|
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Mar 04, 2015 9:39 am |
|
|
You're still making it difficult to help. So I'll use another tack.
Try this code and tell us what happens as you change the value for "t". Code: | #include <18F6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
int8 step[4]={0b1001,0b1100,0b0110,0b0011};
main()
{
int8 t=50;
int8 i;
while (1)
{
for (i=0 ; i <4 ; i++ )
{
output_b(step[i]);
delay_ms(t);
}
}
} | Mike
EDIT
You changed the code in your original post, after several responses.
That alters the logic of the thread and make it difficult to follow.
Your motor does 200 steps per rev, so why mess about with 360/1.8 floating point maths? |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
reply |
Posted: Wed Mar 04, 2015 10:27 pm |
|
|
Mike Walne wrote: | You're still making it difficult to help. So I'll use another tack.
Try this code and tell us what happens as you change the value for "t". Code: | #include <18F6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
int8 step[4]={0b1001,0b1100,0b0110,0b0011};
main()
{
int8 t=50;
int8 i;
while (1)
{
for (i=0 ; i <4 ; i++ )
{
output_b(step[i]);
delay_ms(t);
}
}
} | Mike
EDIT
You changed the code in your original post, after several responses.
That alters the logic of the thread and make it difficult to follow.
Your motor does 200 steps per rev, so why mess about with 360/1.8 floating point maths? |
so that i can take the code to greater steps |
|
|
zeyad
Joined: 24 Feb 2015 Posts: 22
|
reply |
Posted: Wed Mar 04, 2015 10:38 pm |
|
|
Mike Walne wrote: | You're still making it difficult to help. So I'll use another tack.
Try this code and tell us what happens as you change the value for "t". Code: | #include <18F6723.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
int8 step[4]={0b1001,0b1100,0b0110,0b0011};
main()
{
int8 t=50;
int8 i;
while (1)
{
for (i=0 ; i <4 ; i++ )
{
output_b(step[i]);
delay_ms(t);
}
}
} | Mike
EDIT
You changed the code in your original post, after several responses.
That alters the logic of the thread and make it difficult to follow.
Your motor does 200 steps per rev, so why mess about with 360/1.8 floating point maths? |
when i change the value of t the motor speed increases or decreases corresponding to the delay |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|