stepper motor cct

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

stepper motor cct

Post by nuwan5213 »

hi all.
im really struglling with my recently built cct.
this time my project is elastic cutter and stepper motor runs several loops and stops then cutter will cut the elastic, after that motor runs same loop.
im using flowcode student licence then i dont have stepper controler module.then i wrote all the steps manually to port c.
i use time delays in between steps and motor run nice and smooth.
circuit build with bdx 53 darlington transistors and i use 10A ,5V power supply to run the motor.
MY PROBLEM IS STEPPER MORTER DOESNOT STOPS SAME POSITION EVERY TIME.that means my elastics are not the same size.
please advice me what to do.

:( :(
Attachments
STEPPER4.fcf
my program.
(12.5 KiB) Downloaded 359 times
Electronics for better world.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

Hi nuwan
In your code you have a redutant Output box after the exit from each sub-loop: 255--> Port C5, C6. You can also place the condition of each sub-loop "Until COUNT=x00" at the end of loop instead at the start. This can give you a faster exit from each sub-loop. Though i don't think that can resolve your problem. Your outputs to stepper motor coils seems to be correct.
What type is your stepper motor? Unipolar or Bipolar?
Fotis
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: stepper motor cct

Post by medelec35 »

Hi nuwan5213,
Im a bit confused :? (trust me it don't take much :lol: )
Why have you got the same port e.g RC4 during part of the cycle and going on the the next cycle to go high for 2ms ,then low for 10us then back high for 2ms then low for 2ms ect
I think you may have some masked outputs wrong?
Stepper4.png
(8.18 KiB) Downloaded 7436 times
Here is a simulator showing the issue.

Martin
Martin

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

@ Martin
Good morning Martin
Yes, you are right about this strange delay of 10μs. From those i can perceive, nuwan5213 uses a bipolar stepper motor (his A-A', B-B' terminology should be correspond to: A=A, A'=B, B=C and B'=D of FlowCode stepper motor component) in "Full Step" drive mode (that from the output sequence on his flowchart, because there are 4 different output combinations - phases). Do you think that this repeated lag of 10μs can cause the problem of nuwan5213? In Configuration screen i have noticed that he has selected "Oscillator = RC". Is an RC oscillator sufficiently accurate for the given project?
BTW, i have a question about your oscilloscope picture: What virtual oscilloscope are you using? It looks great!
Thanks
Fotis
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: stepper motor cct

Post by medelec35 »

The off times should be longer than the on times. So what I believe is happening is after say port RC4 goes low for 10us, RC4 goes back to high by mistake, and it should be RC5 for example that goes high instead of RC4.

@Fotis
I have use that simulator to test compiled hex code on different threads.
e.g
http://www.matrixmultimedia.com/mmforum ... 998#p24998
That also has a download link. I use flowcode to create the hex file, then try compiled file in the simulator. Finally if I'm happy, compile code to hardware

@nuwan5213
What type of drive are you wanting to use e.g the normal Full step or 1/2 step?
I will see if I can help with full step, but I have not yet had much experience with stepper motors.
As for configuration, Fotis was right to mention this, as it looks like its not been set.
On my Flowcode it's set to the default 3FFF. This means osc is set for RC, watchdog and low voltage programming are enabled etc
Did you set the configuration in expert configuration settings? If so Flowcode V4.5 has not picked them up.

Martin
Martin

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

Hi again :mrgreen:
Just now i finished a simulation of stepper motor on FlowCode. Assuming that the step. motor of nuwan5213 is indeed bipolar and driven in full step mode, i did the configuration of FlowCode component in the same way. Assuming - again - that the FlowCode stepper motor component is correct, and by simulating the motor step by step, i have noticed that it executes 48 steps per revolution, or 48 steps/360 deg. If this is true, then the 3 counter values of nuwan5213 have big problem because are based on that: when the counter executes 500 or 600 or 700 steps the motor should be execute the same number of steps. According to FCD simulator that is true. So: 500 counts = 500 steps X 360 deg / 48 steps = 3750 deg total. This does not lead to a whole number of rotations (1 rot = 360 deg) it leads to 3750 / 360 deg = 10.416666 rotations! Same for 600 counts: 600 steps X 360 deg / 48 steps = 4500 deg total or 4500 / 360 = 12.5 rotations. For 700 counts: 700 X 360 / 48 = 5250 deg / 360 = 14.5833333 rotations. How on the earth could the stepper motor stop at the same point? Even in the case of 600 counts that give 12.5 rotations of motor, in the next stop the motor will shift by 180 deg from the previous stop point. I saw it during simulation, the rotor of stepper motor never stops at the same point and later i did the above calculation that proves it.
To the present, i think the problem of nuwan5213: STEPPER MORTER DOESNOT STOPS SAME POSITION EVERY TIME has been identified. It remains to we solve it... by changing the counter "number-clature".
Fotis
Last edited by fotios on Sat Aug 20, 2011 9:29 pm, edited 2 times in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

Well, the FlowCode stepper motor component by default is placed at 48 Full steps/rev. You can see that in the "Component properties" window if you click on the component icon placed on the panel. Accordingly, in any connection BIPOLAR, UNIPOLAR +ve or UNIPOLAR -ve the motor executes 48steps/rev in FULL STEP and WAVE drive modes or 96steps/rev in HALF STEP drive mode. Therefore, the variable "Counter" of the attached fcf should get values which are multiples of 48 in Full Step and Wave modes and 96 in half step mode. Only then the shaft could be stopped at the same point each time. Please, try the attached fcf with e.g. "until count = 480" and the shaft will execute exactly 10 revolutions. Try "until count = 672" and you will get exactly 14 revolutions. And so on. Green Led will help you to observe it during simulation.
There is offered a lot of HYBRID stepper motors on the market (please try a search on the web for data) which execute e.g. 200steps/revolution. In such a case, you must type in the Full steps / rev box found in the component properties window the number 200. Then, you have to give in variable "Counter" values which are multiples of 200 so as the shaft will stop at the same point each time. For example, if you give in Loop icon "Until count = 200" the green Led will lit 1time/1 rev. For "Until count =400" the Led will lit 1 time/2 rev. In HALF STEP drive mode and for "Until count = 800" Led will also lite 1 time/2 rev.
Fotis
Attachments
bipolar stepper.fcf
(6.5 KiB) Downloaded 354 times
Last edited by fotios on Sun Aug 21, 2011 9:57 am, edited 2 times in total.
Best Regards FOTIS ANAGNOSTOU

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

hi my dear friends.

where am i now?????
could you please explain how to solve the problem.im using bipolar stepper motor.is my timing chart wrong mean 2ms for on and 2micro s for off the port c.im sure hardware is ok. :oops:
fotios i don't have stepper motor component to create the program because it is student version.
please give me the suggestions for this program.
thanks.......................................................
Electronics for better world.

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

ops i forgot
im using xtal oscillator and it is done by my third party programming sw.
Electronics for better world.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

nuwan5213 wrote:hi my dear friends.

where am i now?????
could you please explain how to solve the problem.im using bipolar stepper motor.is my timing chart wrong mean 2ms for on and 2micro s for off the port c.im sure hardware is ok. :oops:
fotios i don't have stepper motor component to create the program because it is student version.
please give me the suggestions for this program.
thanks.......................................................
Hi nuwan
I need the number of steps per revolution of your stepper motor. Have you datasheet? Or part number? If not, try to count the steps manually by rotating the shaft of motor with your fingers. I think you can feel each "click" of shaft. The number should be EVEN.
Fotis
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

nuwan5213 wrote:ops i forgot
im using xtal oscillator and it is done by my third party programming sw.
Please nuwan
Tell us the frequency of your XTAL.
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

Hi nuwan
Are you still counting steps? :mrgreen: Don't worry and let me guess: you have the most commonly used stepper motor today, which is the HYBRID type of 1.8 deg / step. So the total steps should be 200. Attached is the modified fcf for you. If my assumption is correct, then you will have 1 or 2 or 3 or 4 revolutions. Then you will have elastics of equal length, but i don't know how much will be the length, that is your own issue, you have to modify the mechanical part of your machine. Please check in Configuration window, i placed Oscillator at HS supposing that you use XTAL from 4MHz and above.
Fotis
Attachments
STEPPER4_mod..fcf
(12.5 KiB) Downloaded 278 times
Last edited by fotios on Sun Aug 21, 2011 5:07 pm, edited 1 time in total.
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: stepper motor cct

Post by medelec35 »

I have also modified your flowchart.
This one should run exactly the same as if you used the built in stepper component with Bipolar, full step selected.
you will need to change the number of steps to suit your application.
The problem you had was to do with masking. You need to mask all 4 bits you are using, then assign a value.
Not just 2 bits and assign 255, since if you do that the bits that should be off are still on. I know you turned them off by using portC=0, but it gets a bit messy.

If the stepper motor and arrangement is different from bipolar and full step then please let us know.

IMPORTANT: Although you are using programmer to set configuration, you must make sure the clock speed in View, Project options is matching your oscillator speed. If not then delays will be out.

All you need to do now is add a switch or something to stop cycle keep repeating once all steps are completed

Martin
Attachments
STEPPER4 Modified.fcf
(10.5 KiB) Downloaded 259 times
Martin

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

medelec35 wrote:@Fotis
I have use that simulator to test compiled hex code on different threads.
e.g
http://www.matrixmultimedia.com/mmforum ... 998#p24998
That also has a download link. I use flowcode to create the hex file, then try compiled file in the simulator. Finally if I'm happy, compile code to hardware
Martin, this simulator looks amazing good! And cheap! I downloaded and tried it, its virtual function generator and oscilloscope are two usefull instruments.
Thanks for the link.
Fotis
Best Regards FOTIS ANAGNOSTOU

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

hi all,
thank you Martin,Medelec35,Fotis.
my problem was ok now.i dont have clear idea about stepper motor im working with brushless dc servo motor and ac servo motors.any how with your help i learnd how to drive stepper motor.i attach my final program to you.if have time please check.i reduse the time to 5 ms for each step because of i want more speed.but any how when i reduse much more like 4,3,2,ms motor slips and agai same problem coming to action .ok any way this speed is more than enough to me and thak you all agin.

PROBLEM SOLVED
THANKS. :)
Electronics for better world.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

nuwan5213 wrote:hi all,
thank you Martin,Medelec35,Fotis.
my problem was ok now.i dont have clear idea about stepper motor im working with brushless dc servo motor and ac servo motors.any how with your help i learnd how to drive stepper motor.i attach my final program to you.if have time please check.i reduse the time to 5 ms for each step because of i want more speed.but any how when i reduse much more like 4,3,2,ms motor slips and agai same problem coming to action .ok any way this speed is more than enough to me and thak you all agin.

PROBLEM SOLVED
THANKS. :)
Nice to you nuwan5213 :D But were is your final program? I can't see anything attached!
Just from curiosity, i would like to see the numbers you gave in variable "COUNT" in each Loop.
Fotis
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: stepper motor cct

Post by medelec35 »

It's nice to see the words 'PROBLEM SOLVED'
Thanks for letting us know.
Hope it all goes well for you.


@Fotios.
Your welcome. It seems to handle everything thrown at it PIC16 wise. More importantly, it does appear to replicate the real hardware very accurately. + You can see wahts happerning with the registers.
A Tip. Using Flowcode, compile to hex, then view ASM to find correct addresses for variables.
Glad you like it

Martin
Martin

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

sorry for mistake to all.
hear is my final project working nicely
thanks. :D
Attachments
STEPPERMOT_MOD3.fcf
(19.89 KiB) Downloaded 279 times
Electronics for better world.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: stepper motor cct

Post by Benj »

Hello,

I see you now have this working nicely but you mentioned that you could not speed the motor up any more. A good way to control steppers and really any motor is to use a ramping speed profile. for example you start the motor with 5ms intervals between steps, you then slowly reduce the delay allowing the motor to increase in speed. Near the end of the cycle you then start increasing the delays again to allow the motor to slow down, this then makes it easier to stop the motor on a precise step. For the final step position you want to hold this output on for a short time period to allow the motor to brake and stop, once the motor has stopped you then need to disable the outputs so that no further current is going through the motor coils until you are ready to start again.

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

Hi again,
ok the martin and fotis correct.i was trying to revolutions according to my lenth error occurs again.
as a solution what will happend to add feedback loop to this?.i mean configer one pin as a input and give a synchronizer signal and count what i want.stepper runs stand alone without synchronizer ,if it is attached to motor shaft i will run what i want revalutions.
what do you think.
is this time its going to be work.
regards,
nuwan
Electronics for better world.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

nuwan5213 wrote:Hi again,
ok the martin and fotis correct.i was trying to revolutions according to my lenth error occurs again.
as a solution what will happend to add feedback loop to this?.i mean configer one pin as a input and give a synchronizer signal and count what i want.stepper runs stand alone without synchronizer ,if it is attached to motor shaft i will run what i want revalutions.
Hi nuwan
That is against the principles of stepper motors! Stepper motors were invented to eliminate the need for feedback loops. Feedback is necessary only in servo motors.
Martin in his last post, gave you a code with the correct phase sequence (steps) of a bipolar stepper motor working in full step mode.
Ben's suggestion for a smooth acceleration of stepper motor to its full speed and a smooth deceleration to its brake point, is also very useful and you have to implement it in your code. There are lot of programming tricks to obtain this.
My own query (for days!) is, how in the earth have you obtained start - stop of stepper motor shaft at the same point by giving numbers like 215 - 300 - 315 etc. in variable "COUNT". I tried it in FlowCode simulator and it can do that only if i give a value of "Full steps / rev" = 5 in the motor properties window. That means a motor of 72 deg / step! I could not find a such type step. motor on the web. The type that is offered (i talk for NEMA standard motors) from any constructor is the HYBRID of 1.8 or 0.9 deg / step. That corresponds to 200 or 400 steps / rev (360 : 1.8 = 200 and 360 : 0.9 = 400). Unless you are not using NEMA motor. I also don't know what is coupled on the shaft of your stepper motor; a swivel equiped with blades? a pulley? a belt? ... That is also a good question for you. We are almost in full darkness regarding your project.
Can you enlighten us a little more please?
Fotis
Last edited by fotios on Wed Aug 31, 2011 4:12 am, edited 4 times in total.
Best Regards FOTIS ANAGNOSTOU

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

hi fotios,
according to martin i modifid only port masking outputs.i change the time delay between step obtain better speed.im using belt driven nurling naild roller assembly to drive the elastic between rollers.cutter is closed to rollers.
i need different lenths that why i use adc0 to controller in cct.i can only change the loop count to obtain my lenth.
my stepper has no name plate or i dont have any specifications it is remooved from old sawing machine elastic feeder called ARTHERDAK ok.
i attached pictures of my machine.
also send you a modified program.
im using full step unipolar +ve mode in my cct?????
what are the my variable "count" should be?///

best regards,
nuwan
Attachments
pic1.GIF
pic1.GIF (128.92 KiB) Viewed 12404 times
Electronics for better world.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

OK, that is a good picture.
Your stepper motor seems to be NEMA standard. As i told you, the most usual type is the standard Hybrid of 1.8deg/step (=200steps/rev) and the microstep Hybrid of 0.9deg/step (=400steps/rev). Your motor is probably of the standard type. But we can't be sure for this since the data of motor are unknown. First of all, we have to examine the steps/rev of the unknown motor. Try this: In the first branch of your flowchart (ADC < 2.5V) give a value of "200" in variable "COUNT". Start the motor and run it for e.g. 3 cycles. If it stops at the same point (i.e. if elastic pices have same length +/- 1mm) then your motor is indeed of 200 steps/rev. I attach a slight modified fcf which simulates exactly the stepper motor component of FlowCode. Take a look in the first branch, run it and if 200 steps/rev are fullfiled then the green Led should lit. If you change the "COUNT" to e.g. 215 green Led will never lit.
Fotis
Attachments
STEPPERMOT_MOD3.fcf
(21.51 KiB) Downloaded 250 times
Last edited by fotios on Wed Aug 31, 2011 4:20 am, edited 1 time in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: stepper motor cct

Post by fotios »

I forgot to mention that the number of steps/rev is the same in any connection, Bipolar or Unipolar. It depends only in drive mode: Full step and Wave mode have 4 different phases while Half step mode have 8 different phases and so the double number of steps/rev.
Fotis
Best Regards FOTIS ANAGNOSTOU

nuwan5213
Posts: 82
Joined: Thu Jul 29, 2010 10:03 am
Location: sri lanka
Has thanked: 24 times
Been thanked: 4 times
Contact:

Re: stepper motor cct

Post by nuwan5213 »

Hi fotis.,
this tme its running correctly.
4revolutions per cycle and port c 1comes up.
regards,
nuwan.Hi fotis.,
this tme its running correctly.
4revolutions per cycle and port c 1comes up.
regards,
nuwan.
Electronics for better world.

Post Reply