ELS Project - spindle position read-out

Fixed the issue of the creeping error when the lathe spins, and fixed the bug of it starting at the wrong value.

edit: I just realised that my logic for avoiding under/overflow makes no sense, which happens when I do my coding last thing at night :/ It works at the moment but there's scope for errors, just so you know. Important to note that I don't see any reason why this function could affect any functionality outside of the spindle position counter, so there's no safety issue with this.
 
Last edited:
I made the pCount=0 change and that initialized spindle to 0 position on startup. I commented out the code below out and had no problems. Ran lathe for > 1-1/2 hrs. Position was still right on, no over-runs. One thing I have noticed, is between 360 and 1 degree, it doesn't display a decimal but only 1-9, until you hit 1.0 or 360.0 going reverse.

// // Manage overflow - as count approaches maximum uint32 value, deduct 0x000fffff
// if ( pcurrent > 0x0fffffff ) {
// pcurrent -= 0x000fffff;
// pprevious -= 0x000fffff;
// }
//
// // Manage underflow - as count approaches zero, add 0x000fffff
// if ( pcurrent < 0x0000ffff ) {
// pcurrent += 0x000fffff;
// pprevious += 0x000fffff;
// }
 
I've made a complete change to the logic to calculate the position and it's now much simpler and handles under/overflow without a problem (hopefully). Latest version of my code is on my github.

I also took the opportunity to add 0. in front of numbers below 1deg.
 
I've made a complete change to the logic to calculate the position and it's now much simpler and handles under/overflow without a problem (hopefully). Latest version of my code is on my github.

I also took the opportunity to add 0. in front of numbers below 1deg.

It appears that you are counting the total pulses number of pulses, correcting for under/overflow to determine spindle position? The Omron E6B2-C encoders have a Z phase output which occurs at an origin position. Can you not use that output to determine spindle position by resetting a counter and counting CE/CCW pulses? The counter would be reset with each pass of the origin so the total count would never exceed the 4K/rev.
 
The original Clough42 code uses pulse counts to calculate stepper motor pulses for a given feed. The way he has implemented this gave no consideration to what I wanted to achieve. As such, James' code doesn't use the index pulse to reset the pulse count register, rather his code resets at an arbitrarily large integer. This in itself isn't a problem, you can easily change one flag to have the counter reset of the index pulse. However, because this was not anticipated in James' code, it won't play nice because of his implementation of under/overflow management for stepper control.

It wouldn't be that big a deal to rewrite his code, but given my much lower expertise than James, I'd rather leave his reliable code alone and work around it in the way I have.
 
I've used it several times in last couple of days. I had a radial muzzle brake that doesn't have ports on bottom 120 degrees. Put an electronic level on bottom of recoil lug and rotated until it read 180 (it was upside down), with backlash taken up out of gear train, powered ELS down then back up and now position is 0 with lug straight down. Screw on brake and then simple matter to use position function to figure exact number of degrees brake needs to rotate to be clocked correctly.

Then I made a couple reamer stops and easy to mark the 40 tpi locks while they are still in lathe.

Sure is nice that the function is there and nothing hanging off of lathe.
 
Back
Top