Sign in to follow this  
Followers 0
davefirewalker

A little help please

21 posts in this topic

Hi guys.... Someone out there will probably shoot me down in flames, I've seen requests for code being treated with derision, but I will ask the question anyway. Firstly I do not work in plc's though I do have some (very small) experience, mainly with allen bradley I am trying to develop a personal application (not commercial) which seems to be ok, until I hit a small problem. I need to drive a stepper motor, I have NO experience of this at all !!! I have scavanged a few units, to put together The units I have are an omron cpm-2a relay output version. (no good for stepper control) and a 20 IO transistor expansion (maybe ok for stepper) Just managed to get a NT21 touchscreen off ebay to put with it. Ok...... All the programming is done and works OK..Ive read the manual (such as it is) :( the touchscreen is fine...no probs there and after a few weeks of trying it all works fine NOW THEN... the stepper control my problem I need to use a stepper motor to rotate to a set position between 0 -180 degrees taking its position input from the nt21. I can sort out the adressing of the nt21 its just the programming of the cpm-2 I need help with. I have a stepper and a driver card for it. my question.... how do I send the train of pulses to the stepper, for example if I wanted it the motor to be half way I would send one train of n pulses, then if I wanted to increase the position do I either just send the extra pulses or return the motor to "0" and then send N+extra. I know where "0" is by a limit switch For example. I have a "thumbwheel" on the nt21 (0-100). I input 45 and the motor receives 45 steps, later I want to increase this to 75. Then I may want to fine tune this by 1or 2 steps. this only has to happen very infrequently, the motor position is not constantly changing an one position may be ok for a few hours before it has to change, then it may be either up or down, a few degrees or more. I understand how the nt21 communicates with the cpm2a and have set aside a memory area for this. i am stuck on how to access the memory area and give that train of pulse to the stepper I suppose i am asking how to read a memory area, compare it and fire the results to a loaded shift register. Then use the shift register to turn an output on/off a certain number of times. I can probably work it out given time....but some help or a quick sample to look at may help. I am not asking for someone to write the entire thing, but just to put me on the right path. Please be aware that I am not too technical, but I believe that any problem can be surmounted, looking at an example often gives you clues how to do it hope someone can help, rgds Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites
The relay style output version of the CPM2A does not have high speed Pulse Outputs for stepper motor control. Unless you get a transistor version you will struggle to accurately control the motor using standard expansion I/O transistor outputs. A stepper motor generally works best with a 50% duty cycle pulse input. You will be hard pressed to maintain this at different speeds using the standard transistor outputs. That's WHY the transistor unit has all the functionality built in for the control you need. For a description of stepper motor applications using the CPM2A read section 2-5 of the manual. This gives an exhaustive description and programming examples. Here's the manual http://www.omron247.com/doc/pdfcatal.nsf/2...353E1041003.pdf Edited by BITS N BYTES

Share this post


Link to post
Share on other sites
thanks BNB I didnt think it would be as simple as I thought. I am doing this on a bit of a budget....so buying new is not an option. I already had to hand the stuff ive got. Is there anyway to send the required pulse trains from the transitor expansion, I dont need the motor to run continuously. I only need it the stepper to move from 0 to a given spot then stop. It doesnt have to do this very quickly either upto 30s would be fine. I will have a look at the manual suggested (edit) Just had a look at section 2.5......seems to deal with the transitor option only...:( ah well....... will keep on trying, might come up with something rgds Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites
Don't give up THAT easy!! If your CPM1A is -V2 you can use the TMHH(18) instruction to simulate a pulse train output to the expansion transistor outputs. To generate a 50% ON/OFF cycle you could use the attached program which uses the very high speed timer TMHH instruction as a pulse simulator. The best resolution [highest speed] you will get is 2mSec = 500Hz. If this is meets the needs of your application then continue on................... CPM2A_Pulse_Output.zip Edited by BITS N BYTES

Share this post


Link to post
Share on other sites
thanks for the input...... I'm not giving up at all developing a pulse train would never be the problem (I think). The problem i seem to have is translating the input from the hmi to a specific pulse train ie if the hmi was set to 45...... then to develop the required amount of pulses (45) to the stepper. then to be able to increment it by a specified amount ie an extra (+n or - n etc). Do I do a compare and take away the initial # and add the extra pulses, or do a reset and add the new whole? you could look at this application as maybe a volume control or a manual valve with a 180deg rotation. It needs to be set at a certain positon once, them maybe adjusted or "jogged", then reset a bit later on to a different position. I could do this manually...but it is in an inaccessable place :( how do i get a specific no of pulses to the stepper? thats the problem ! this is no longer looking that easy hope someone can help rgds Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites
Just a thought. Use the value from the HMI as a preset value for a counter. The counter could count the number of times the stepper output pulses. When the counter counts out, disable the stepper output rung. Either use one of the built in pulse bits or create one. Hope this helps.

Share this post


Link to post
Share on other sites
This is the path I am now exploring, I intend to use compare, and use the flag bits to either inc or dec a reversible counter along with the output pulses until the = flag bit is true let you know how i get on ps.......Can compare be used permanantly ON (inside a subroutine) or does it have to "clocked" or "pulsed" rgds Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites
Hello Dave, Compare can be permanantly on.

Share this post


Link to post
Share on other sites
Would this work...I cant test it as yet....any ideas this section in a subroutine compare looks at hmi input and counter, sets flag if <=> pulse output 11.00 (transitor) (.002s), and inc or dec reversible counter depending on flag, continues until = any mods or comments rgds Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites
Typically the comparision bits (255.05, .06 and .07) need to be in the same rung at the CMP instruction. Branch them from the horizontal to the CMP and use internal bits for the compare state. Then use those internals in the counter rung. My concern is the CNTR instruction will always be counting with the logic shown. You may want to create an "enable" bit that will only energize the logic when the output to the stepper is actually required to move. Just my thoughts. Edited by gtsuport

Share this post


Link to post
Share on other sites
Not so - instruction result flags remain in the condition of the most recnet instruction until another instruction causes them to be re-evaluated.

Share this post


Link to post
Share on other sites
Ok guys just redone it..... i wanted to use the < flag for an output anyway (direction), so all flags have gone to spare outputs (just in case) I have got rid of the .02 s pulse and replaced it with two timers Its not as simple or as elegant....in fact it is starting to grow........ Anways...any thoughts or has anyone ANY better ideas rgds Dave

Share this post


Link to post
Share on other sites
Dave, just be aware of the restrictions of the reversable counter CNTR as can be found in the following thread http://forums.mrplc.com/index.php?showtopic=2465&hl=cntr

Share this post


Link to post
Share on other sites
Yeah ....ive just had a read of that may cause problems or not, i dont know Its not an industrial solution I'm after, its for a personal project, so a bit of inaccuracy can be put up with. Anyway is the coding any good? will it work? could it be done better? rgds Dave

Share this post


Link to post
Share on other sites
Dave, It has been seven years since I last touched an omron. {C200H was just debuting}, but you code is readable and I can follow it still. The fellows are right that the compare bits retain the state of the last instruction to use them. The reason we always branched them in the same rung was so no one could slip in a new rung and change flag states by accident.

Share this post


Link to post
Share on other sites
1990 or something? I now have trouble remembering that far back.By the way Dave, with the CPM you can use bit 253.13 in front of a rung - it is always on. Then if you want to disable the rung, you just put a slash (/) through it. Very handy for debugging.

Share this post


Link to post
Share on other sites
Ok guys next question........ how do I keep it inside the subroutine until it's finished...ie until the equals flag is set.... would a jump instruction do it ? Dave

Share this post


Link to post
Share on other sites
??? Doesn't make sense! How do you keep 'what' in side a subroutine? The program will run to END and then restart. The structure of your ladder means that when the conditions are met, your equals flag will switch on (assuming 0.00 is on) and the pulse output will stop - is this not enough? or am i missing something? And why put it in a subroutine? to segregate? A subroutine is most useful for running the same code a variable number of times in 1 scan (usually where some 'input parameter' changes) and this is usually data manipulation as IO is (usually) not processed till after the END instruction. e.g. ' If Fault is on, then fill D100 & call SBN 100 to do something clever using same ladder but different value LD FAULT1 MOV #0001 D100 SBS #100 ' If Fault is on, then fill D100 & call SBN 100 to do something clever using same ladder but different value LD FAULT2 MOV #0002 D100 SBS #100 ' If Fault is on, then fill D100 & call SBN 100 to do something clever using same ladder but different value LD FAULT2 MOV #0003 D100 SBS #100 If you were to use a subroutine & it was called many times - you would not switch the outputs unless you did an IO refresh in the subroutine. As your program seems to be a stepper controller only, it seems superfluous. If you are intent to have it in a SBN then I suggest something like... * Have your ON switch (or command position change) @SET a H bit (e.g. H0.00) * Use H0.00 to call the SBN e.g.... LD H0.00 SBS #100 * In your SBN when 11.02 comes on, RSET H0.00 Please clarify & I'll see if I can help further.

Share this post


Link to post
Share on other sites
Hi I have a program running that requires a stepper to be driven infrequently the stepper only has to move from 0-180 degrees or anywhere in between. The program illustrated is not the whole program it's just the stepper part of it. It just supplies the required number of pulses taken from a HMI, and some sort of direction info (up or down) the reason I wanted it in a subroutine was that nothing else needs to run while the stepper part is running. and I wanted the stepper to move to its position as quickly as possible.....in fact i wanted the stepper program to finish before anything else COULD run. And please be aware I am not an expert PLC programmer, i dont do this for a living. This is a personal project, made up from bits and pieces I've scrounged. I will look at your advice and see if there is anyway i can incorporate it in a rewrite thanks Dave Edited by davefirewalker

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0