Changing mux2.0.sel values every X time.
01 Feb 2013 20:06 #29433
by casetero
Changing mux2.0.sel values every X time. was created by casetero
Hello everyone, i´m trying to learn some HAL code, and i don´t know if its possible to do that creating a thread or something.
The thing i want to do is that the PIN mux2.0.sel changes its values from 0 to 1 every 0.2 seconds for example.
I don´t have any idea to do it, maybe with a thread like base-thread or servo-thread, or something different. I´m starting to use the HAL code and i´m very lost.
Sorry for my english.
Thank you very much.
The thing i want to do is that the PIN mux2.0.sel changes its values from 0 to 1 every 0.2 seconds for example.
I don´t have any idea to do it, maybe with a thread like base-thread or servo-thread, or something different. I´m starting to use the HAL code and i´m very lost.
Sorry for my english.
Thank you very much.
Please Log in or Create an account to join the conversation.
02 Feb 2013 01:44 #29450
by ArcEye
Replied by ArcEye on topic Changing mux2.0.sel values every X time.
Hi
Just trying to clarify the question
Do you want a component to link to mux2.sel pin to switch it on and off at preset intervals OR
do you just want to re-write mux2 so that it oscillates output between in1 and in0 at preset intervals without an external connection?
The latter seems the easiest, the code for mux2 is extremely simple, you would just need to add a counter to match the speed of the thread for the elapsed 0.2 seconds and reset the sel pin.
Something like this
regards
Just trying to clarify the question
Do you want a component to link to mux2.sel pin to switch it on and off at preset intervals OR
do you just want to re-write mux2 so that it oscillates output between in1 and in0 at preset intervals without an external connection?
The latter seems the easiest, the code for mux2 is extremely simple, you would just need to add a counter to match the speed of the thread for the elapsed 0.2 seconds and reset the sel pin.
Something like this
component mux-toggle " toggles between two input values at preset rate";
pin out float out "Follows the value of in0 if timer > period or in1 if timer < period";
pin in float in1 "if no period set will default to this;
pin in float in0;
param rw s32 period = 0 "number of thread periods between toggles";
variable s32 timer = 0;
function _;
author "ArcEye arceye@mgware.co.uk";
license "GPL";
;;
FUNCTION(_)
{
if(timer < period)
{
out = in0;
timer++;
}
else
{
out = in1;
timer = 0;
}
}
regards
The following user(s) said Thank You: casetero
Please Log in or Create an account to join the conversation.
02 Feb 2013 02:25 #29452
by PCW
Replied by PCW on topic Changing mux2.0.sel values every X time.
Thats not quite right as it will only select in1 for 1 thread period...
you probably want something dealing with timer < and > period over 2
you probably want something dealing with timer < and > period over 2
Please Log in or Create an account to join the conversation.
02 Feb 2013 05:29 - 02 Feb 2013 06:32 #29454
by casetero
Replied by casetero on topic Changing mux2.0.sel values every X time.
Hi,
PCW, i think what i want to do is what ArcEye has post, i can´t fully understand you, sorry for my english. I want that a PIN be excited by mux2.0.in0 and mux2.0.in1, changing between both every 0.2 seconds.
Thinking of it, will this charge much the processor and give me more latency??
Arceye doing this i will change the mux2 component in general, if i rename it as mux2_period.c and compile it like the shuttlexpress will work too??
I say this because maybe i need to use mux2 with his normal behaviour in other place. EDIT = Sorry i see now you have renamed to mux2-toggle.
Thank you!
PCW, i think what i want to do is what ArcEye has post, i can´t fully understand you, sorry for my english. I want that a PIN be excited by mux2.0.in0 and mux2.0.in1, changing between both every 0.2 seconds.
Thinking of it, will this charge much the processor and give me more latency??
Arceye doing this i will change the mux2 component in general, if i rename it as mux2_period.c and compile it like the shuttlexpress will work too??
I say this because maybe i need to use mux2 with his normal behaviour in other place. EDIT = Sorry i see now you have renamed to mux2-toggle.
Thank you!
Last edit: 02 Feb 2013 06:32 by casetero.
Please Log in or Create an account to join the conversation.
02 Feb 2013 05:35 #29456
by PCW
Replied by PCW on topic Changing mux2.0.sel values every X time.
Running such a simple component will not take much processor time at all
Yes compile it with a different name so you dont break the existing components
My previous post just mentions that there is a little bug in the code that needs to be fixed before it will do what you expect
Yes compile it with a different name so you dont break the existing components
My previous post just mentions that there is a little bug in the code that needs to be fixed before it will do what you expect
The following user(s) said Thank You: casetero
Please Log in or Create an account to join the conversation.
02 Feb 2013 06:43 #29458
by casetero
Replied by casetero on topic Changing mux2.0.sel values every X time.
Ok, so i have to put a file like it is as a file.c in /build/src/hal/user_components/ compile it and copy to the real path of linuxcnc or can i make a file.comp and compile it with comp--??
Can i compile it with nothing more code?? dependencies?
What is the little bug? it will change one time and will stay with the in1 value?
Thank you!
Can i compile it with nothing more code?? dependencies?
What is the little bug? it will change one time and will stay with the in1 value?
Thank you!
Please Log in or Create an account to join the conversation.
02 Feb 2013 07:17 #29460
by PCW
Replied by PCW on topic Changing mux2.0.sel values every X time.
This should be closer to equal time on both in0 and in1
component mux-toggle " toggles between two input values at preset rate";
pin out float out "Follows the value of in0 if timer > period or in1 if timer < period";
pin in float in1 "if no period set will default to this;
pin in float in0;
param rw s32 period = 0 "number of thread periods between toggles";
variable s32 timer = 0;
function _;
author "ArcEye arceye@mgware.co.uk";
license "GPL";
FUNCTION(_)
{
if(timer < period)
{
out = in0;
timer++;
}
else
{
out = in1;
timer++;
}
if(timer =period*2)
{
timer = 0;
}
}
Please Log in or Create an account to join the conversation.
02 Feb 2013 15:12 - 02 Feb 2013 19:37 #29470
by ArcEye
Replied by ArcEye on topic Changing mux2.0.sel values every X time.
Thank you Peter
I had realised the error after I shut down the computer, but had other things to do
Your fix is exactly the same one I thought of
Regards compiling, it is a component, name the file mux-toggle.comp
and run sudo comp --install mux-toggle.comp
It won't build in the source tree under that name unless you change the makefile
regards
I had realised the error after I shut down the computer, but had other things to do
Your fix is exactly the same one I thought of
Regards compiling, it is a component, name the file mux-toggle.comp
and run sudo comp --install mux-toggle.comp
It won't build in the source tree under that name unless you change the makefile
regards
Last edit: 02 Feb 2013 19:37 by ArcEye.
The following user(s) said Thank You: casetero
Please Log in or Create an account to join the conversation.
02 Feb 2013 17:10 #29473
by casetero
Replied by casetero on topic Changing mux2.0.sel values every X time.
Ok, so i do create a file called mux-toggle.comp with the code and run sudo comp --install mux-toggle.comp.
But in what directory do i do all this??
Do i have to link the component after to any servo-thread or base-thread??
How do i fix the timer to 0.2 seconds?
Thank you!
But in what directory do i do all this??
Do i have to link the component after to any servo-thread or base-thread??
How do i fix the timer to 0.2 seconds?
Thank you!
Please Log in or Create an account to join the conversation.
02 Feb 2013 18:55 #29477
by andypugh
You could do this with existing components, if you preferred.
www.linuxcnc.org/docs/html/man/man9/siggen.9.html
loadrt siggen num_chans=1
addf siggen.0 servo-thread
setp siggen.0.frequency 5
net toggle siggen.0.clock => mux2.0.sel
(I am not 100% certain that the "clock" output is a square wave, it might be necessary to use a conv_float_bit function on the square-wave output instead.)
However, learning how to write custom components in the comp preprocessor is a good thing to do, as you can see from mux2 it is much simpler than the C-code required for something like shuttlexpress.
Docs here:
www.linuxcnc.org/docs/html/hal/comp.html
(don't confuse the "comp" preprocessor with the "comp" HAL component)
Replied by andypugh on topic Changing mux2.0.sel values every X time.
The thing i want to do is that the PIN mux2.0.sel changes its values from 0 to 1 every 0.2 seconds for example.
You could do this with existing components, if you preferred.
www.linuxcnc.org/docs/html/man/man9/siggen.9.html
loadrt siggen num_chans=1
addf siggen.0 servo-thread
setp siggen.0.frequency 5
net toggle siggen.0.clock => mux2.0.sel
(I am not 100% certain that the "clock" output is a square wave, it might be necessary to use a conv_float_bit function on the square-wave output instead.)
However, learning how to write custom components in the comp preprocessor is a good thing to do, as you can see from mux2 it is much simpler than the C-code required for something like shuttlexpress.
Docs here:
www.linuxcnc.org/docs/html/hal/comp.html
(don't confuse the "comp" preprocessor with the "comp" HAL component)
The following user(s) said Thank You: casetero
Please Log in or Create an account to join the conversation.
Time to create page: 0.087 seconds