Signed Int to Pin Output

More
15 years 11 months ago #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 to join the conversation.

More
15 years 11 months ago #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 to join the conversation.

More
15 years 11 months ago #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.
Code:
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); } }

Attachment split_u32_bit.comp not found

Please Log in to join the conversation.

More
15 years 11 months ago #5171 by thedirk
Replied by thedirk on topic Re:Signed Int to Pin Output
Thank you for the quick reply. That worked very well.

Please Log in to join the conversation.

More
8 years 4 months ago #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

Please Log in to join the conversation.

More
8 years 4 months ago #112541 by andypugh
And furthermore this component now exists as:

linuxcnc.org/docs/2.7/html/man/man9/bitslice.9.html

Please Log in to join the conversation.

More
8 years 4 months ago #112544 by skunkworks
I did the same thing in ladder...

Please Log in to join the conversation.

Time to create page: 0.110 seconds
Powered by Kunena Forum