Single execution HAL function
31 Mar 2021 01:23 #204160
by Limedodge
Single execution HAL function was created by Limedodge
Maybe a dumb question, but is there a way to call the single execution of a HAL function?
Context:
I want to create a custom M1XX PXXX code that will convert the PXXX value into 8 bit signal. To do this, I want to use the bitslice function to individually assign each of the 8 io pins with the corresponding value.
Do I have to add the function to a thread (addf) or is there a way to just execute it once when MXXX is called. Seems like a waste of computation power to constantly recompute the value over and over again at the servo thread level. Maybe I'm over thinking how much of a drag it is?
Something like this
Thoughts?
Context:
I want to create a custom M1XX PXXX code that will convert the PXXX value into 8 bit signal. To do this, I want to use the bitslice function to individually assign each of the 8 io pins with the corresponding value.
Do I have to add the function to a thread (addf) or is there a way to just execute it once when MXXX is called. Seems like a waste of computation power to constantly recompute the value over and over again at the servo thread level. Maybe I'm over thinking how much of a drag it is?
Something like this
#!/bin/bash
#save value from MXXX PXXX QXXX command
power=$1
#set the bitslice input
halcmd setp bitslice.0.in $power
<EXECUTE BITSLICE FUNCTION ONCE>
#set pins with bitwise values
halcmd setp hm2_7i96.0.gpio.040.in bitslice.0.out-00
halcmd setp hm2_7i96.0.gpio.041.in bitslice.0.out-01
halcmd setp hm2_7i96.0.gpio.042.in bitslice.0.out-02
halcmd setp hm2_7i96.0.gpio.043.in bitslice.0.out-03
halcmd setp hm2_7i96.0.gpio.044.in bitslice.0.out-04
halcmd setp hm2_7i96.0.gpio.045.in bitslice.0.out-05
halcmd setp hm2_7i96.0.gpio.046.in bitslice.0.out-06
halcmd setp hm2_7i96.0.gpio.047.in bitslice.0.out-07
exit 0
Thoughts?
Please Log in or Create an account to join the conversation.
31 Mar 2021 01:34 #204162
by Limedodge
Replied by Limedodge on topic Single execution HAL function
Maybe I should clarify, this command will be called numerous times (with different values) during the course of a program. Just nowhere near the rate of other thread functions. I realized I may have been too literal with the term "once".
Please Log in or Create an account to join the conversation.
31 Mar 2021 04:11 #204169
by Henk
Replied by Henk on topic Single execution HAL function
Out of interest, what would be the purpose of this?
H
H
Please Log in or Create an account to join the conversation.
31 Mar 2021 09:31 #204192
by andypugh
You can definitely make it run zero times, by loading it (loadrt) but not adding it to a thread.
Is there a way to call a loaded module once? I expect that there is, but I don't know how. But that is definitely the approach I would be researching.
Replied by andypugh on topic Single execution HAL function
Maybe a dumb question, but is there a way to call the single execution of a HAL function?
You can definitely make it run zero times, by loading it (loadrt) but not adding it to a thread.
Is there a way to call a loaded module once? I expect that there is, but I don't know how. But that is definitely the approach I would be researching.
Please Log in or Create an account to join the conversation.
31 Mar 2021 13:40 #204217
by Limedodge
Replied by Limedodge on topic Single execution HAL function
That's where I'm at right now.
The other way is to skip the bitslice function altogether and find another way to break a number into bits. Use a python code or something. It just seemed like an elegant solution if it worked
This is for power setting on a laser. Inputs are P0 thru P7,8 bit proportional power level. 0=0% 255=100%
There also a latching that needs to get done, but I'm still working on how to do that with oneshot
The other way is to skip the bitslice function altogether and find another way to break a number into bits. Use a python code or something. It just seemed like an elegant solution if it worked
This is for power setting on a laser. Inputs are P0 thru P7,8 bit proportional power level. 0=0% 255=100%
There also a latching that needs to get done, but I'm still working on how to do that with oneshot
Please Log in or Create an account to join the conversation.
31 Mar 2021 13:54 #204218
by andypugh
Maybe write a custom HAL component, and stick the bitslice code in that.
It's a pretty simple function:
github.com/LinuxCNC/linuxcnc/blob/master...onents/bitslice.comp
Replied by andypugh on topic Single execution HAL function
The other way is to skip the bitslice function altogether and find another way to break a number into bits. Use a python code or something. It just seemed like an elegant solution if it worked
Maybe write a custom HAL component, and stick the bitslice code in that.
It's a pretty simple function:
github.com/LinuxCNC/linuxcnc/blob/master...onents/bitslice.comp
Please Log in or Create an account to join the conversation.
31 Mar 2021 14:36 #204223
by cmorley
Replied by cmorley on topic Single execution HAL function
I would try writing the equivalent code in python and call the python script as the M code.
Actually I would just let the bitwise component run at the servo thread and not worry about it.
Actually I would just let the bitwise component run at the servo thread and not worry about it.
Please Log in or Create an account to join the conversation.
31 Mar 2021 17:37 - 31 Mar 2021 17:50 #204244
by PCW
Replied by PCW on topic Single execution HAL function
Out of curiosity, just measured the bitslice components time on
my hardware, about 30 ns average, really not worth bothering with.
That is you could have 100s of bitslice or similar components
and have negligible effect on the overall servo thread time.
my hardware, about 30 ns average, really not worth bothering with.
That is you could have 100s of bitslice or similar components
and have negligible effect on the overall servo thread time.
Last edit: 31 Mar 2021 17:50 by PCW.
Please Log in or Create an account to join the conversation.
31 Mar 2021 18:06 #204252
by Limedodge
Replied by Limedodge on topic Single execution HAL function
Oh wow, OK. I'll just add it to the servo and not over think it.
Thanks for looking into that PCW!
Thanks for looking into that PCW!
Please Log in or Create an account to join the conversation.
31 Mar 2021 19:57 #204283
by Limedodge
Replied by Limedodge on topic Single execution HAL function
Quick followup question
If I use the servo thread to calculate the bitslice, will I be able to call a new value in a MXXX PXXX and have it re-calculate in time to write to the new bits to pins? Or will it execute the m-code so fast that the previous value (stored in the bitslice module from the last calculation) will be used to set the 8 pins? Do I need a delay or something to allow time for recalc before I start writing to the io pins?
If I use the servo thread to calculate the bitslice, will I be able to call a new value in a MXXX PXXX and have it re-calculate in time to write to the new bits to pins? Or will it execute the m-code so fast that the previous value (stored in the bitslice module from the last calculation) will be used to set the 8 pins? Do I need a delay or something to allow time for recalc before I start writing to the io pins?
Please Log in or Create an account to join the conversation.
Time to create page: 0.078 seconds