Looking for a hal component
10 Jul 2023 20:14 #275155
by beefy
Looking for a hal component was created by beefy
Does a hal component exist where for example you can have a 5 input binary value is used to activate one of 32 output pins (bit out).
Ideally I could select the number for the input and output pins, i.e. 5 digit binary input value to activate one of 32 output pins, or 6 digit binary input value to activate one of 64 output pins.
Or would I have to write a custom component to achieve this.
Ideally I could select the number for the input and output pins, i.e. 5 digit binary input value to activate one of 32 output pins, or 6 digit binary input value to activate one of 64 output pins.
Or would I have to write a custom component to achieve this.
Please Log in or Create an account to join the conversation.
10 Jul 2023 20:39 #275156
by roland
Replied by roland on topic Looking for a hal component
Please Log in or Create an account to join the conversation.
10 Jul 2023 20:55 #275160
by rodw
Replied by rodw on topic Looking for a hal component
mux_generic should do this with a standard component
linuxcnc.org/docs/2.9/html/man/man9/mux_generic.9.html
linuxcnc.org/docs/2.9/html/man/man9/mux_generic.9.html
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19202
- Thank you received: 6436
10 Jul 2023 21:03 #275161
by tommylight
Replied by tommylight on topic Looking for a hal component
Mux = multiplexer = many inputs to less outputs
DeMux = demultiplexer = less inputs to many outputs
That is the rough explanation, depends a lot on what and how they are used.
He needs the latter, as noted by him and Roland.
DeMux = demultiplexer = less inputs to many outputs
That is the rough explanation, depends a lot on what and how they are used.
He needs the latter, as noted by him and Roland.
Please Log in or Create an account to join the conversation.
10 Jul 2023 23:48 #275178
by rodw
Replied by rodw on topic Looking for a hal component
My bad, There is a Demux component that will handle it as well
linuxcnc.org/docs/devel/html/man/man9/demux.9.html
Half the battle is to know what terminology has been used with the hal names!
It would be better to use the standard components wherever possible.
linuxcnc.org/docs/devel/html/man/man9/demux.9.html
Half the battle is to know what terminology has been used with the hal names!
It would be better to use the standard components wherever possible.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19202
- Thank you received: 6436
11 Jul 2023 00:06 #275179
by tommylight
I vividly recall it being named "Car area network" back when i first read about it as it was designed especially for use in cars, now i could not find that naming through several pages of results, despite all of them referring to it's use in cars!
Replied by tommylight on topic Looking for a hal component
That is becoming difficult at an alarming rate, earlier had a search for CAN bus, everything came back as "control area network"!!! WTF is control area????Half the battle is to know what terminology has been used with the hal names!
I vividly recall it being named "Car area network" back when i first read about it as it was designed especially for use in cars, now i could not find that naming through several pages of results, despite all of them referring to it's use in cars!
Please Log in or Create an account to join the conversation.
11 Jul 2023 06:42 #275190
by beefy
Replied by beefy on topic Looking for a hal component
Thanks a lot everyone.
I had actually looked at DEMUX previously but the description left me somewhat confused. I find so many things in Lcnc are explained like the reader is some experienced programmer or developer and it makes it hard to get to the intermediate stage.
Example, from the DEMUX description:
One of these bits will be set based on interpreting the bit-inputs as a binary number and then adding on the integer input.
Most uses will use only one or the other, but it is possible to use the bits as a ""shift"" if required
Ha ha, I was left thinking what the heck does that mean. I bet it's easy as pie once it's understood though.
Roland,
I checked out your component and I love it. I really like the way you used a FOR loop, and that makes it so easy to modify the code for any number of I/O. Myself, if I hadn't seen your example, I'd probably have done a lengthy switch-case statement LOL.
I haven't made a custom hal component before so I just need to better understand the first half of the code where most of the setup is done. I'll look into this further.
Keith
I had actually looked at DEMUX previously but the description left me somewhat confused. I find so many things in Lcnc are explained like the reader is some experienced programmer or developer and it makes it hard to get to the intermediate stage.
Example, from the DEMUX description:
One of these bits will be set based on interpreting the bit-inputs as a binary number and then adding on the integer input.
Most uses will use only one or the other, but it is possible to use the bits as a ""shift"" if required
Ha ha, I was left thinking what the heck does that mean. I bet it's easy as pie once it's understood though.
Roland,
I checked out your component and I love it. I really like the way you used a FOR loop, and that makes it so easy to modify the code for any number of I/O. Myself, if I hadn't seen your example, I'd probably have done a lengthy switch-case statement LOL.
I haven't made a custom hal component before so I just need to better understand the first half of the code where most of the setup is done. I'll look into this further.
Keith
Please Log in or Create an account to join the conversation.
11 Jul 2023 07:32 #275195
by rodw
Replied by rodw on topic Looking for a hal component
Great you have a solution, I certainly agree the docs are very confusing with some of these components. IN fact it's probably easier to write a component than work out how to use the component!
If you want an interesting C coding exercise which is rarely seen would be to use a union where one variable is overlaid over each other. This way, the actual bits in the input number becomes the output bit. Without checking it compiles, I think it looks like this:
The component could then have a personality to determine how many bit pins are published by the loop. No maths at all!
If you want an interesting C coding exercise which is rarely seen would be to use a union where one variable is overlaid over each other. This way, the actual bits in the input number becomes the output bit. Without checking it compiles, I think it looks like this:
struct operator {
unsigned in;
union {
int out[32]:1;
} types;
};
The component could then have a personality to determine how many bit pins are published by the loop. No maths at all!
Please Log in or Create an account to join the conversation.
11 Jul 2023 08:48 #275198
by rmu
Replied by rmu on topic Looking for a hal component
The datastructure as written does not overlay "in" with "out", in fact it doesn't overlay anything. Unions are not really "rarely seen", but are somewhat tricky to use and carry a bunch of foot-guns. You have to carefully think about C aliasing and undefined behaviour rules or the compiler may optimize your code away.Great you have a solution, I certainly agree the docs are very confusing with some of these components. IN fact it's probably easier to write a component than work out how to use the component!
If you want an interesting C coding exercise which is rarely seen would be to use a union where one variable is overlaid over each other. This way, the actual bits in the input number becomes the output bit. Without checking it compiles, I think it looks like this:struct operator { unsigned in; union { int out[32]:1; } types; }; The component could then have a personality to determine how many bit pins are published by the loop. No maths at all!
Please Log in or Create an account to join the conversation.
12 Jul 2023 01:33 - 12 Jul 2023 01:35 #275248
by rodw
Just in this case, you don't overlay the bitmap structure but instead should be able to use an array of unsigned chars the same length as the word.
Replied by rodw on topic Looking for a hal component
Yes you are right. I forgot I had a real example. Here is an example from a component I wrote to decode an Ethercat CIA402 status word that shows breakup of the individual bits.
//CIA Status Word
typedef union
{
struct
{
unsigned char ReadyToSwitchOn : 1; // 00
unsigned char SwitchOn : 1; // 01
unsigned char OperationEnabled : 1; // 02
unsigned char Fault : 1; // 03
unsigned char VoltageEnabled : 1; // 04
unsigned char QuickStop : 1; // 05
unsigned char SwitchOnDisabled : 1; // 06
unsigned char Warning : 1; // 07
unsigned char keep1 : 1; // 08
unsigned char Remote : 1; // 09
unsigned char TargetReached : 1; // 10
unsigned char bit11 : 1; // 11
unsigned char bit12 : 1; // 12
unsigned char keep2 : 3; // 13-15
}b;
hal_u32_t Word;
}Status_t;
hal_u32_t statusword; // IN - Drives CiA402 Statusword, index 0x6041
Just in this case, you don't overlay the bitmap structure but instead should be able to use an array of unsigned chars the same length as the word.
Last edit: 12 Jul 2023 01:35 by rodw.
Please Log in or Create an account to join the conversation.
Time to create page: 0.082 seconds