Propeller and CNC
T Chap
Posts: 4,223
I was going to do this with 3 SX's and just had the thought that 1 Prop might do it all:
Requirements:
4 outputs x 3 for unipolar stepper drive transistors
2 inputs x 3 each for the encoders
total 18 i/o's req'd for motors/encoders
inputs from PC:
Step and Dir x 3 = 6 i/o's
Total 24 i/o's for all In's and Out's
I need to have the 4 outs to control sequencing do a pseudo PWM on each pin, so that if the motor is sitting still at say 1010 coil sequence, they are really PWMing from 1010 to 0000 at a few microseconds at 50% duty.
Is there an existing object for steppers that do what I am looking for? I am p[noparse][[/noparse]retty lost at how to run though the sequences according to the Direction input and STEP. It seems there needs to be some way to keep track of what sequende it is on, so that in a reverse direction it can go back a sequence.
Thanks
Post Edited (originator99) : 9/30/2006 2:38:49 AM GMT
Requirements:
4 outputs x 3 for unipolar stepper drive transistors
2 inputs x 3 each for the encoders
total 18 i/o's req'd for motors/encoders
inputs from PC:
Step and Dir x 3 = 6 i/o's
Total 24 i/o's for all In's and Out's
I need to have the 4 outs to control sequencing do a pseudo PWM on each pin, so that if the motor is sitting still at say 1010 coil sequence, they are really PWMing from 1010 to 0000 at a few microseconds at 50% duty.
Is there an existing object for steppers that do what I am looking for? I am p[noparse][[/noparse]retty lost at how to run though the sequences according to the Direction input and STEP. It seems there needs to be some way to keep track of what sequende it is on, so that in a reverse direction it can go back a sequence.
Thanks
Post Edited (originator99) : 9/30/2006 2:38:49 AM GMT
Comments
While I love the Propeller, I think you are selling the SX short.
I believe, that for myself at least, it would be easier to complete your task with a SINGLE SX48 than with a Propeller. One of my main reasons for stating this is the superior debugging facility with the SX-Key. Also the higher speed of the SX makes fast state machines (a good candidate for your application) a breeze.
The other reason is that I perceive running all these inter-related real-time functions in a single SX, which I think it can readily do, is simpler than inter-cog communications.
That said, my view comes from a perspective of plenty of SX assembler experience, and as yet only a limited amount of Propeller experience-- I find it hard to pass up on the SX; it still does wonders for me!
I'm not looking to pick a fight, and surely there will be many who wish to disagree with me, but I'm pretty sure of where I stand on this. It would be fun to have a contest.... but then how would one assess "ease"; perhaps hours spent??
Anyhow best of luck regardless of your approach.
Cheers,
Peter (pjv)
My main issue is finding the bext way to run the sequences regardless of chip. Maybe someone has a much better way to do this, but below is an idea I am kicking around. I don't know yet how to navigate this cvoncept in Spin, as with the other basic you can jump atound as needed with no need for a returns.
Concept for moving to new sequence according to Step input and Direction based on whole step with 4 sequences:
Main: 'boot init state
Motor = SeqA 'string %0101 to produce 4 outs 1010 sequence
Pause 1 'psuedo pwm, needs to be fast, like under a microsec
CoilA = SeqNull
Pause 1
IF Step = 1 and Dir = 1 Then SequenceB 'move forward one seq
IF Step = 1 and Dir = 0 Then SequenceD 'move back one seq
Goto Main
SequenceA:
Motor = SeqA 'first sequence
Pause 1 'psuedo pwm, needs to be fast, like under a microsec
Motor= SeqNull 'no outs
Pause 1
IF Step = 1 and Dir = 1 Then SequenceB 'move forward one seq
IF Step = 1 and Dir = 0 Then SequenceD 'move back one seq
GOTO SeqA
SequenceB:
Motor = SeqB
Pause 1 'psuedo pwm, needs to be fast, like under a microsec
Motor= SeqNull
Pause 1
IF Step = 1 and Dir = 1 Then SequenceC 'move forward one seq
IF Step = 1 and Dir = 0 Then SequenceA 'move back one seq
GOTO SeqB
SequenceC:
Motor = SeqC
Pause 1 'psuedo pwm, needs to be fast, like under a microsec
Motor= SeqNull
Pause 1
IF Step = 1 and Dir = 1 Then SequenceD 'move forward one seq
IF Step = 1 and Dir = 0 Then SequenceB 'move back one seq
GOTO SeqC
SequenceD:
Motor = SeqD
Pause 1 'psuedo pwm, needs to be fast, like under a microsec
Motor= SeqNull
Pause 1
IF Step = 1 and Dir = 1 Then SequenceA 'move forward one seq
IF Step = 1 and Dir = 0 Then SequenceC 'move back one seq
GOTO SeqC
Next is get some code to convert quadtrature encode output to up or down pulse used internally to modify a counter, then compare with a Step command, and report if motor doesn't move.
On the Prop, since I don't know how to navigate as the above illustration, I think it would work like this in general:
PUB START
Repeat
If Step = 1 and Direction = 1
SequenceMovePos
If Step = 1 and Direction = 0
SequenceMoveNeg
PUB SequenceMovePos
'some method to determine current sequence of 4
'increment sequence 1 in positive direction
LoopTheUpdatedSequence 'new cog loops the sequence until it it updated again
PUB SequenceMoveNeg
'some method to determine current sequence of 4
'increment sequence 1 in negative direction
LoopTheUpdatedSequence 'new cog loops the sequence until it it updated again
Any suggestions would be appreciated
pjv,
I don't see how there would be any intercog communication with what originator99 described, I would just write a tight program to handle the stepping and direction and checking the encoder feedback for that stepper, then launch 3 cogs, each dedicated to a stepper channel
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
1111 'all high
pause .03125 micro
1010 ' Seq A = A high B low C high D low
pause .03125 micro
1111
pause .03125 micro
1010
pause .03125 micro
There is no current sensing on the motors, so I want to just keep the same PWM timing as that has worked all along.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
I am thinking the encoder decoding method could run on a separate cog, constantly updating a variable. If anyone has seen something like quadrature input decoding, it would be nice to study it. There are two signals in from the endoder, 90 degrees out of phase. Depending on which pulse is seen first determnines the direction. So it may tun out to be simple once I get to that point.
Thanks for the help. Should be a fun leraning experience.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
If you plug the motor in with no PWM, and send it sequence 1, the high side rail will drop from 20V to 7V. With the PIC doing pwm on the 4 pins the rail was always rail at around 18.
I just ran this code below with an SX as a test and got around 17V on the Rail and a ton of of torque:
These signals get inverted after the SX as they are driving the existing 7400 NAND gates they were using as inverters. This is the first sequence of four in a whole step pattern. coil 1 high coil 2 low coil 3 high coil 4 low
main:
m1 = 0 'high
m2 = 1 'low
m3 = 0 'high
m4 = 1 'low
pause 1
m1 = 1 'low
m2 = 1 'low
m3 = 1 'low
m4 = 1 'low
pause 1
goto main
Regarding your question, the average pulse length from the PC is around a microsecond long, but can be adjusted upwards. The frequency of the pulses average around 4 pulses for every .1 microseconds sample on the scope, so maybe .025 microseconds apart?
Figure that 4000 pulses = 1 inch of motion (20 threads per inch rod @ 200 revs per thread). If you calculated an example of 1 inch per second that might be an average for cutting a part on the machine, some much slower depending, but some faster, even double that while rapid planing.
I hope this answered the questions.
Thanks
I was just experimenting with an SX sending a pulsed sequence like this to see what the voltage drop was
Thinking out loud
1. Take step and dir pulses from paralell cable for X,Y, Z. Convert Step and Dir to Sequences for each motor. I am using a unipolar 6 wire, so it has 4 wires that have to be shunted to ground to drive that coil. My system is using TIP120's at 20 volts. 5 volts is turning the TIP on, shorting the appropriate coil to GND. If the DIR pin changes, the sequence needs to reverse.
2. Convert 2 quadrature encoder inputs into up or down pulses, or maybe a single clock out with direction. Add or subtract those pulses to a global variable.
3. On boot up, all variables are reset. and when a motor moves in a direction, it is adding or subtracting to a variable i.e. XCount. The motor moves and spins the encoder, the code interprets the direction from the quadrature inputs, and adds or subtracts to its own variable. i.e. XEncCount. On every STEP pulse, there is a comparison of XCOUNT and XEncCount. If XEncCount is not within a few pulses of XCount, it sends an E-STOP back to the PC, plus shuts down all motion from the Prop as well.
I'm still quite sure you don't have your measurements correct. You continue to use numbers which indicate pulses of very short duration such as those from a PC, and to boot be only 0.025 microseconds apart. Although not impossible, this is incrediby fast, even for NASA and rocket scientists!
Frankly, I don't believe it, and secondly no SX or Propeller or PIC can deal with those..... so I suspect you need to do some more homework.
Cheers,
Peter (pjv)
At whole steps, 200 pulses per rev, 20 threads per inch = 200*20=4000 in about a second
Post Edited (originator99) : 9/30/2006 9:22:02 PM GMT
Are you sure it is a 1.8 deg step motor?
Are you driving them in half step or full step mode?
James L
·
It is fairly easy to hold your hand on the motor shaft which has set screws on it, you can roughly count 20 revs per second. But that is not as fast as it will actually run, just a typical speed. 20 revs * 200 steps per rev = 4000.
Post Edited (originator99) : 9/30/2006 9:28:23 PM GMT
Just as I thought, your measurement was off by a factor of 10,000 !
At 4,000 steps for 1 inch in one second, there are 4 steps per one millisecond, which is one step per 250 microsecond (250 uS), and NOT the 0.025 microseconds you were suggesting.
This number is believable and easily within reach of a PIC, Propeller or SX.
Cheers,
Peter (pjv)
Post Edited (originator99) : 9/30/2006 10:26:23 PM GMT
I have one simple question and I can get this going.
I want to set up "labels" as in Pbasic:
SequenceA: '1010
'loop here until STEP from PC, then depending on DIR, go forwards or backwards 1 sequence
SequenceB '0110
'loop here until STEP from PC, then depending on DIR, go forwards or backwards 1 sequence
SequenceC '0101
'loop here until STEP from PC, then depending on DIR, go forwards or backwards 1 sequence
SequenceD '1001
'loop here until STEP from PC, then depending on DIR, go forwards or backwards 1 sequence
I can do this in Pbasic, but cannot see how to navigate in Spin without having the Return always wanting to take the pointer back where it was.
How about this unfinished example-- The motor stays where it is unless it sees a pulse, then it checks the DIR and goes where it needs to.
PUB SequenceA
repeat
outa[noparse][[/noparse]coilX1] := xxxx
outa[noparse][[/noparse]coilX2] := xxxx
outa[noparse][[/noparse]coilX3] := xxxx
outa[noparse][[/noparse]coilX] := xxxx
pause x 'pseudo pwm duty cycle
outa[noparse][[/noparse]coilX1] := 0000
outa[noparse][[/noparse]coilX2] := 0000
outa[noparse][[/noparse]coilX3] := 0000
outa[noparse][[/noparse]coilX4] := 0000
pause x 'pseudo pwm
IF STEP == 1 and DIR ==1
SequenceB 'move forward
IF STEP == 1 and DIR ==1
SequenceD 'move back one sequence
PUB SequecneB
'same as A with Y motor outs, and
BTW the psuedo pwm pauses shown in the SPIN file hold the motor in place very nicely without dropping the rail too much. Without a load, the High side sits at 20V, with the old controller which had no sense circuitry, they ran the outputs similar to the way I have done it with the pauses. Their controller would have around a 3v drop down to 17v, my pauses also have it at 17V as well.
This code will get me to seqA but can't move out of it
Post Edited (originator99) : 9/30/2006 11:32:07 PM GMT
SeqA 1010
SeqB 0110
SeqC 0101
SeqD 1001
The motor needs to sit at one of the 4 above until the controller gets a new STEP pulse, then the STEP pin cycles forward or backward through the sequences depending on the DIR pin.
If anyone knows where I can look at some existing object to study how to cycle forwards and backwards through a data table, please let me know. The code I have works for learning and testing only.
Thanks
Post Edited (originator99) : 10/1/2006 1:02:24 AM GMT
Can someone please tell me a way to do this? Thanks
Post Edited (originator99) : 10/1/2006 2:50:17 AM GMT
dan
Just thought I'd pass this along for what it is worth.· I really know very little about true CNC operation.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Need a TV Module?
Newzed@aol.com
·
kelvin
The problem I am having is mainly lack of Spin knowledge. I know exactly what I want to do, but don't know the methods to do it. For example:
This waits for the STEP pin to go from low to high, and on every high it goes through one step of 4 in the sequence. This works great as is, but, this is based on the DIR pin being ignored. What really needs to happen is, it looks at the STEP pin, if 1, then looks at the DIR pin:
if DIR = 1 then do this:
With the above example, you can have it WAITPEQ for one state, but can't WAIT for another at the same time.
Now, if there were enough cogs, maybe one cog could be forward, one back.
But, I have to count the encoder pulses as well, which means ideally that should use a single cog per axis too.
The same problem applies to the encoders, there are two pins to monitor, A and B, ech 90 degrees out of phase. On A = 1 and B = 0 then you are moving in one directon and need to ADD to the counter. On A = 1 and B = 1, you are moving the other way and need to SUBTRACT from the counter. Then, each iteration of STEP and ENCODER read, compare the COUNTER, and make a decision if different.
There are 3 motors, 3 encoders. That is 6 cogs, leaving two for other stuff. I like WAITPEQ but don't have enough cogs to park all I need. That means back to IF THEN's from my little knowledge, leaving the slight possibility that while reading through it's lists of stuff to check, a pulse coud take place in a blind spot while one IF THEN is acting on some condition. What is needed is a state machine, where one state does X. I am clueless how to do that, and have seen no examples.
Post Edited (originator99) : 10/1/2006 8:06:03 PM GMT
This demo allowed me to run these motors way faster than I have seen them run before. I cranked the software up to 120 inches per minutes, 4000 pulses per inch, and it looked and sounded like a DC motor spinning. Altought the torque at that speed is useless, but the smoothness of it was impressive.
Sawmiller and Newzed, I am sure you guys may already have looked at this, but you can get a MACH3 full functional demo(limited to 1000 lines of Gcode) for free. It is 159 for the license. Since you already have the Prop hooked up to 3 motors, it would be a breeze to run a new code and patch in a PC with 6 wires off a parallel port, and run your machine from MACH3. If you like making simple homebrew PCB's( I used to but too much hassle), you could get an EAGLE demo (limited to around 2" x3" approx output PCB), and John Johnsons PCB-Gcode ULP for EAGLE, and run double sided boards easily after a slight curve. Just output Gcode from Eagle, load it in Mach3 and engrave the boards. I have done them and they worked great after you sort out the end mills, and set a few parameters. I'd recommend getting some thompson anti backlash nuts instead of try to code it out.