× Forum Header

Configuring Spindle Feedback with Proximity Sensor

More
01 Feb 2011 04:42 #6911 by rkappius
Hi, I'm trying to add a proximity sensor to my lathe to allow threading. I've gotten the pyVCP window to correctly show the spindle speed once I got the scalar correct in the custom_postgui.hal. I'm connecting pin 15 to PhaseA and it seems to work (the sensor only has one output, a NPN). Since I have a correct display of the RPM in the GUI I'm close.

However, when I air run the threading.ngc example code (EMC2 2.3.0) the code hangs at the first G33 line. I tried executing the G33 line by hand and got a "spindle not turning" message.

Seems to me that somehow the wiring from the scale.0 module doesn't connect to EMC proper. (sorry if this is messy nomenclature, I'm a hal newby.)

Could someone help me get EMC to be aware of the current spindle speed so I can execute G33, G33.1, and G76 commands?

And since I'm asking newby questions, can someone tell me what PWM rate and PDM mode means?

Thanks,
Rus

Please Log in or Create an account to join the conversation.

More
01 Feb 2011 12:50 #6916 by andypugh
rkappius wrote:

Seems to me that somehow the wiring from the scale.0 module doesn't connect to EMC proper. (sorry if this is messy nomenclature, I'm a hal newby.)

I am surprised to see that you are using a scale module, you really need to use an encoder module for G33 and G76.
For a single pulse channel you need to put the encoder in counter mode (ie setp encoder.0.counter-mode 1)
www.linuxcnc.org/docview/html/man/man9/encoder.9.html
You then need to link encoder position (or better, encoder position-interpolated to the motion.spindle-revs pin (this is very critical)
linuxcnc.org/docs/html/examples_spindle.html

Could someone help me get EMC to be aware of the current spindle speed so I can execute G33, G33.1, and G76 commands?

However, you still have one very important part of the puzzle missing. You also need a one pulse per rev index, as that is where EMC2 starts the thread. For this you will need to have another sensor working off a feature on the spindle or a deeper/longer slot on your existing feedback wheel (What are you using at the moment?)
It is probably possible to use a single pulse per rev as both index and counter (though I would not expect that to work especially perfectly) and it should also be possible to synthesise an index pulse from the encoder counts (but I can't see a HAL function to do that in the current version, you would have to write a custom component which checks if encoder counts is an integer multiple of the encoder scale, which is not exactly difficult, but needs some effort).
A real once-per-rev index is better.

And since I'm asking newby questions, can someone tell me what PWM rate and PDM mode means?

PWM generates variable mark-space ratio square waves. The PWM rate is the base frequency of those square waves.
Consider that the base thread on your machine runs at something around 20,000nS (or 20uS in sensible units). Every 20uS the PWM function runs, and decides whether to turn on or off the output. It does this by incrementing a counter, and seeing if the value of the counter is above a threshold.
This means that the resolution of the PWM generator is a function of PWM frequency.
Consider a 50kHz base thread frequency. This means that a 1kHz PWM can count from 0 to 50, switching at 25 for 50% PWM value, 10 for 20% PWM value, etc. This gives you a PWM with 50 possible mark-space ratios.
At 10kHz PWM frequency you only get 5 possible values.
PDM is a different way to achieve much the same effect, but it will run at a fixed frequency, equal to the base thread. Every time the function runs it decides if the time-averaged value of the output is above or below the target, and sets the output high or low accordingly.
en.wikipedia.org/wiki/Pulse-density_modulation

Please Log in or Create an account to join the conversation.

More
01 Feb 2011 13:31 #6924 by rkappius
Thank you so much for the info. I haven't read your links yet, but will. In the mean time I wanted to answer your questions.

First, I think I am using the encoder, but didn't mention that. The encoder output is fed to the scale module, but I failed to mention that.

Here is what I'm using for a sensor:

cgi.ebay.com/Pre-wired-Proximity-Switch-...976b1#ht_3202wt_1142

(I used Ron Steele's guide to retrofit CNC a HarborFreight 7x10 lathe and this is similar to what he recommended.)

As far as I can tell it just emits a pulse once every rotation. And it seems that the reading I'm getting in the postprocessing once scaled by 60 to take it to rpm from rps is correct. I checked this by running the lathe slowly for 60 seconds and counting rotations which matched the readout.

I have no problem writing a custom component if needed but was hoping to avoid this.

Thanks for the education on PWM/PDM. I know my sample rate is set to 17000 ns. I'll absorb what you said and decide what to do here, but seems to me first off that PDM might work just fine.

Thanks again, if you see anything about that sensor that you can pass on I would greatly appreciate it.

Please Log in or Create an account to join the conversation.

More
01 Feb 2011 13:52 #6926 by andypugh
rkappius wrote:

As far as I can tell it just emits a pulse once every rotation.


Sounds very Mach3-ish :-)

EMC2 works best with an index and multiple (hundreds) of pulses per rev, but you should be able to make it work with one PPR.

You need to connect the incoming pulse to both the encoder index and pulse channels (A and Z), connect encoder.0.position-interpolated to motion.spindle-revs and set the encoder.0.scale to 1.

Let us know how that goes.

Please Log in or Create an account to join the conversation.

More
02 Feb 2011 02:26 #6950 by rkappius
I've gotten closer I think, and now have the motion.spindle-revs == encoder.0.position-interpolated, and motion.spindle-speed-in reading correct RPS. However motion.spindle-speed-out is zero, and motion.spindle-at-speed is False as is motion.spindle-forward. motion.spindle-on is also False.

I tried to hard code motion.spindle-on to 1 in my .hal file and EMC2 didn't like that.

How do I get the motion object to correctly process the spindle-speed-in and know it's on? And how do I get the RPS input to RPM output (that I assume I need)


Rus

Please Log in or Create an account to join the conversation.

More
02 Feb 2011 04:35 - 02 Feb 2011 04:37 #6952 by rkappius
Got it to work. All I had to do was issue a speed command, which was in the threading.ngc example code.

Hacking that code to cut a 1/2"-13 thread I got the attached.

Finally ready to get back to real prototyping.

Thanks for your help,
Rus
Attachments:
Last edit: 02 Feb 2011 04:37 by rkappius. Reason: resized photo

Please Log in or Create an account to join the conversation.

More
28 Mar 2011 19:51 - 28 Mar 2011 19:57 #8215 by RotarySMP
I am a new convert to EMC2 ( from TurboCNC) , so my lathe also has a one/rev spindle indexer installed.

I have the lathe running under EMC2.4.3 with Ubuntu 10.04, and the input pin 15 is correctly receiving the spindle index signal (I checked it with the HAL Meter and HAL Scope - cool features)

I understand what is to be done conceptully here, but don't understand the syntax that I need to write in my .HAL file to get this happening.

"You need to connect the incoming pulse to both the encoder index and pulse channels (A and Z), connect encoder.0.position-interpolated to motion.spindle-revs and set the encoder.0.scale to 1. "
How do I do that?

"I've gotten closer I think, and now have the motion.spindle-revs == encoder.0.position-interpolated, and motion.spindle-speed-in reading correct RPS. However motion.spindle-speed-out is zero, and motion.spindle-at-speed is False as is motion.spindle-forward. motion.spindle-on is also False."
What is the syntax to do this please?

I would really appreciate if you could post the spindle portion of your .HAL file please Rus.
Last edit: 28 Mar 2011 19:57 by RotarySMP.

Please Log in or Create an account to join the conversation.

More
28 Mar 2011 20:14 #8218 by rkappius
Will do. I'll post the section tonight. Rus

Please Log in or Create an account to join the conversation.

More
29 Mar 2011 02:00 #8238 by rkappius
Attached is my complete hal file. FWIW I never used turboCNC so I'm not sure what the connection with 1 signal per rev is. Anyway my sensor is working dandy. Let me know if you have any other questions. I'm using a slightly older rev of EMC2 but don't think it matters. Rus

Here's the section:
addf stepgen.capture-position servo-thread
addf encoder.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
addf abs.0 servo-thread
addf scale.0 servo-thread
net spindle-cmd <= motion.spindle-speed-out

setp encoder.0.position-scale 1.000000
setp encoder.0.counter-mode 1
net spindle-position encoder.0.position-interpolated => motion.spindle-revs
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
net spindle-phase-a encoder.0.phase-A
net spindle-phase-a encoder.0.phase-Z
...
net spindle-phase-a <= parport.0.pin-15-in

File Attachment:

File Name: rkappius_lathe.hal
File Size:3 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
29 Mar 2011 20:33 #8265 by RotarySMP
Thanks Rus. I have inserted that in my HAL. Didn't get a chance to test it tonight, as the computor is inside hanging on the lan cable.

Please Log in or Create an account to join the conversation.

Time to create page: 0.095 seconds
Powered by Kunena Forum