Signed Int to Pin Output

More
08 Nov 2010 16:45 #5165 by thedirk
Working on a 25 tool changer carousel and would like to take a signed int (iocontrol.0.tool-prep-number) and output it in binary to 5 pins. Is there an easy way to set this up in my HAL file or will I need to make a HAL component to do the conversion logic? This seems like it should be easy to do, but I cannot find any examples.

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

More
08 Nov 2010 17:08 #5166 by andypugh
I can't see an easy/sensible way to do it with existing components.

Creating a component should be very easy. It would be nice if it took a "personality" input to define the number of bits to be output.

linuxcnc.org/docs/html/hal_comp.html

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

More
08 Nov 2010 19:03 - 08 Nov 2010 19:05 #5167 by andypugh
In fact, here is a component to do the job. I have attached a file, but have also left it in here to show how simple comp makes this sort of thing.

You should be able to compile and install it in a single step with

comp --install split_u32_bit.comp

(You might need a sudo)

If you get a message saying that comp can't be found, then you probably need to sudo apt-get install emc2-dev.
component split_u32_bit "Split an integer into bits and set output pins accordingly";
pin out bit bit-##[32:personality];
pin in u32 in_;
function _ nofp;
license "GPL";
author "andy pugh";
;;

FUNCTION(_){
int i;
    for (i = 0 ; i < personality ; i++){
        bit(i) = in_ & (1 << i);
    }
}

File Attachment:

File Name: split_u32_bit.comp
File Size:0 KB
Attachments:
Last edit: 08 Nov 2010 19:05 by andypugh.
The following user(s) said Thank You: Cpk_Rbt

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

More
09 Nov 2010 01:33 - 09 Nov 2010 11:38 #5171 by thedirk
Replied by thedirk on topic Re:Signed Int to Pin Output
Thank you for the quick reply. That worked very well.
Last edit: 09 Nov 2010 11:38 by thedirk.

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

More
15 Jun 2018 16:46 - 15 Jun 2018 16:48 #112418 by Cpk_Rbt
Replied by Cpk_Rbt on topic Re:Signed Int to Pin Output
FYI for anyone else digging up this old thread, the package is now linuxcnc-dev instead of emc2-dev
Also! the comp command has been replaced by halcompile
Last edit: 15 Jun 2018 16:48 by Cpk_Rbt.

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

More
18 Jun 2018 12:57 #112541 by andypugh
And furthermore this component now exists as:

linuxcnc.org/docs/2.7/html/man/man9/bitslice.9.html
The following user(s) said Thank You: marian

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

More
18 Jun 2018 15:06 #112544 by skunkworks
I did the same thing in ladder...

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

Time to create page: 0.083 seconds
Powered by Kunena Forum