Spindle Uppper and Lower Limit (Or, how to change speed step size)

More
21 Jan 2023 21:17 - 21 Jan 2023 21:24 #262609 by Askjerry
It's Alive !!
Tommylight - Ok, I'll leave it going forward.

Chris@cnc - I owe you BIG TIME!

It worked like a champ... no errors. I downloaded your file directly into my LAGUNA-BOGUS folder. (Running SIM mode in the house, will go out to the garage shortly and do the same on the real machine.) I followed the compile instructions and had no errors... very simple process once you understand it.

I made a slight change to the function such that anything over 25K will run the same bit pattern. Tested fine.
FUNCTION(_) {    
       // 0 to 10K RPM    
    if((spindelspeed) >0 && (spindelspeed) <=10999) {
        out1=1;
        out2=0;
        out3=0;
        }    
    // 15K  
    else if((spindelspeed) >=11000 && (spindelspeed) <=15999) {
        out1=0;
        out2=1;
        out3=0;        
        }    
    // 20K
    else if((spindelspeed) >=20000 && (spindelspeed) <=24999) {
        out1=1;
        out2=1;
        out3=0;
        }        
    // 25K
    else if((spindelspeed) >=25000 ) {
        out1=0;
        out2=0;
        out3=1;
        }            
}

Again... very excited, and thank you for both giving me a complete solution, and for teaching me a new useful (and dangerous) skill!
Last edit: 21 Jan 2023 21:24 by Askjerry. Reason: Editor screwed up the formatting
The following user(s) said Thank You: chris@cnc

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

More
21 Jan 2023 21:40 #262611 by rodw
writing custom components is linuxcnc's best kept secret. 
Once installed any custom component is treated as if its part of linuxcnc's core.

You don't need to compile before install

sudo halcompie --install mycomp.comp
compiles and installs
The following user(s) said Thank You: chris@cnc

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

More
21 Jan 2023 22:09 - 21 Jan 2023 22:11 #262613 by Askjerry
I went to the garage machine and it does not have the halcompile function.

How do I install linuxcnc-uspace-dev into this machine? (It has a much older version of Linux I believe.)  If needed, I'll reformat the machine and start over. I tried a sudo apt-get but that failed.

The sudo halcompie --install mycomp.comp command also failed. (No surprise.)

Thanks,
Jerry
Last edit: 21 Jan 2023 22:11 by Askjerry.

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

More
21 Jan 2023 22:29 - 21 Jan 2023 22:33 #262617 by chris@cnc
Thank you for the flowers, and I am happy to make you smile. 
You are right, could be a dangerous skill, but I hope you have peaceful minds. 
To install halcompile 
"apt-get install linuxcnc-uspace-dev"
or copy the file "yourmodul.so" from your simulator
"/usr/lib/linuxcnc/modules/" to your machine 

By the way, you forgot the range from 16K to 19K...

Thank you to Rod and Grotius.
They were my teachers and I want to pay it back.
I hope it wasn't a mistake to open the secret.
And yes is not needed to compile before install, but I need 100 times to test compile and solve grammar or logic errors before install...

And big thanks to all linuxcnc developers and forum admins to do this possible.
This is a really great tool and community, except the forum editor.
Last edit: 21 Jan 2023 22:33 by chris@cnc.
The following user(s) said Thank You: Askjerry, rodw

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

More
21 Jan 2023 23:39 #262619 by Askjerry
Ha ha... you are right...
else if((spindelspeed) >=11000 && (spindelspeed) <=15999) {

should say
else if((spindelspeed) >=11000 && (spindelspeed) <=19999) {

I will update that downstairs and copy the files to a thumbdrive. Once I have it working, I will add it, and the help you have given me to the next video I make. By the way... this is the playlist:

Thanks again.
Jerry

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

More
22 Jan 2023 07:37 #262637 by Askjerry
I am really getting the hang of this  I think... much to learn, but comfortable.

I realized the pins are ACTIVE LOW, so I had to reverse the logic in them, and I also added a pin fixedspeed so that I could create a pyvcp panel that shows the commanded speed along with the actual or ADJ speed. It worked out well. I also corrected spindelspeed to spindlespeed while I was in there.
component decoder " ";

description
"""
//Compile :
//halcompile --compile decoder.comp
//sudo halcompile --install decoder.comp
//Halfile load :
//loadrt decoder
//addf decoder.0 servo-thread
//setp decoder.0.spindlespeed 0
/* 4 Bit Spindlespeed decoder
    If speed 0-10000 -> out1
    If speed 10000-15000 -> out2
    If speed 15000-20000 -> out1 + out2
    If speed 20000-25000 -> out3        
*/
""";
 
author "Christian Schorsch";

license "GPL";

// Input pins
pin in float spindlespeed=0;        //speed float in
   

// Output pins
pin out bit out1=1;            
pin out bit out2=1;            
pin out bit out3=1;            
pin out float fixedspeed=0;

// Global variables
//variable float timer=0;


function _;

;;

#include "rtapi_math.h"

FUNCTION(_) {
    
       // 1 to 10K RPM    
    if((spindlespeed) >100 && (spindlespeed) <=10999) {
        out1=0;
        out2=1;
        out3=1;
        fixedspeed=10000;
        }
    //Spindle Less than 100 RPM
    else if((spindlespeed) <101 ) {
        out1=1;
        out2=1;
        out3=1;
        fixedspeed=0;
        }
    // 15K  
    else if((spindlespeed) >=11000 && (spindlespeed) <=19999) {
        out1=1;
        out2=0;
        out3=1;    
        fixedspeed=15000;    
        }    
    // 20K
    else if((spindlespeed) >=20000 && (spindlespeed) <=24999) {
        out1=0;
        out2=0;
        out3=1;
        fixedspeed=20000;
        }        
    // 25K
    else if((spindlespeed) >=25000 ) {
        out1=1;
        out2=1;
        out3=0;
        fixedspeed=25000;
        }
}

Tomorrow I need to handle one more thing... the sensors output 24vdc and the parallel circuit is 5vdc. The solution is to use three 4N35 optocouplers. I run the input signal to pin-1 va a 3.3K resistor, and connect ground to pin2. The output is taken from pin-4, and a 5vdc ia applied to pin-5. At that point, I define the home switches to the paraport inputs, and it should be fully functional.

I did have one issue that I solved in an oddball way. As the spindle pins are active-low, when I first turn on the computer, the spindle wants to run at 40,000 RPM.   That is not a good thing! The breakout boards have a relay with NC-COM-NO connections, and if the computer is off, they are both off... when the computer is booting and before AXIS, they are both on. So I routed the ground through the NO pin of the first relay, and into the NC pin of the second relay. The only way the spindle can run is if relay-1 is off and relay-2 is on. It is a bit Rube-Goldberg... but it works.

Ok... off to bed! Thanks again everyone!!!
Jerry

 

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

More
22 Jan 2023 08:29 #262640 by rodw
Gerry,

Sounds great.
Halcompile has one more trick and that is to ceate a man page with this command
halcompile --document rtexample.comp
 
There is a bit of a syntax for man pages you can read up on but it might be just as easy to consult sone of the existing components in github and follow their lead.. and review the html version on the docs page. or just type man and2 (for example)
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components

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

More
22 Jan 2023 10:29 #262651 by chris@cnc

I did have one issue that I solved in an oddball way. As the spindle pins are active-low, when I first turn on the computer, the spindle wants to run at 40,000 RPM. 

Basically have nothing to run without EMG release.
You could wire the enable Signal S0 to your enable Relay and your VFD should have parameter to invert the input logic.

@ Rod
That is the magic part, witchcraft for me. 
The following user(s) said Thank You: Askjerry, rodw

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

More
22 Jan 2023 12:09 - 22 Jan 2023 12:18 #262652 by chris@cnc
I clean up the mess of comment lines here a clean example

Warning: Spoiler!
Attachments:
Last edit: 22 Jan 2023 12:18 by chris@cnc.

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

More
22 Jan 2023 14:40 #262661 by Askjerry
The problem is upon powering the PC on, that pin also comes up high and then goes low... so the spindle suddenly starts up and as the other pins are low it gets the bit pattern 0,0,0 which is 40,000 RPM and it really screams.

This way, there will NEVER be a situation where they are in the needed relay1=on and relay2=off. It powers up as off/off and when AXIS starts they jump to on/on. It's crazy, but it is now VERY stable... and I have no need to use paraport-14 on the first board anyway.

So the document page makes a local document that can be viewed if the user needs to remember how to use the function? I will give it a try on what I have and see what it looks like... then evaluate what you did (The .P .RS .TP and .RS to see what they do so I understand them better.)

Where is the manual for this version of C? I need to study and experiment with it for future projects and enhancements. And I noticed after upgrading the garage computer... it produces a somefile.ko while inside the house, that computer produces a somefile.so which are both placed into different folders too. Odd... must have something to do with the Linux version used. In either case... they work properly, and I now have this as a reference to compile future works.

But I do need a link to the manual so I can see what else is possible. :-)

Thanks,
Jerry

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

Time to create page: 0.096 seconds
Powered by Kunena Forum