Analog Feed and Spindle speed override using Potentiometers (100k)

552 views
Skip to first unread message

Sag ich Dir nich

unread,
Oct 9, 2016, 1:09:25 PM10/9/16
to Machinekit
Hi,

so i want to implement manual overrides for spindle and feed from 0-150%. First i searched in the web for an example and i found some posts about looking a the file "ReadTemp.py", so i looked at it and found a rather long list of Temp/Resistance and Alpha values (first of all what is the Alpha value for?). The resistance values are single Ohm right? If so, 0% must be 0 or 100.000 for a 100kohm Pot right?
ADC value to Temperature conversation may be removed as i need %.

So all i see is a very long list of values (in my case 150 lines or even more for 0-150%) and i am thinking, isnt it possible to make it like floating values (if floating means what i think it means) so it calculates the % value itself?

as input pins i want to use the Thermistor inputs

thanks

Sag ich Dir nich

unread,
Oct 9, 2016, 1:10:50 PM10/9/16
to Machinekit
forgot to mention i am using the CRAMPS Board

Charles Steinkuehler

unread,
Oct 9, 2016, 2:05:57 PM10/9/16
to machi...@googlegroups.com
On 10/9/2016 12:09 PM, Sag ich Dir nich wrote:
> Hi,
>
> so i want to implement manual overrides for spindle and feed from 0-150%. First
> i searched in the web for an example and i found some posts about looking a the
> file "ReadTemp.py", so i looked at it and found a rather long list of
> Temp/Resistance and Alpha values (first of all what is the Alpha value for?).
> The resistance values are single Ohm right? If so, 0% must be 0 or 100.000 for a
> 100kohm Pot right?

The big lists of values are tables for converting the resistance value
into a temperature. A thermistor is a non-linear resistor with it's
resistance value highly dependent on the temperature. The tables make
for more accurate conversion rather than just using a single point and
the beta value.

You can ignore everything having to do with converting resistance values
into temperature.

> ADC value to Temperature conversation may be removed as i need %.
>
> So all i see is a very long list of values (in my case 150 lines or even more
> for 0-150%) and i am thinking, isnt it possible to make it like floating values
> (if floating means what i think it means) so it calculates the % value itself?
>
> as input pins i want to use the Thermistor inputs

You will need the code that reads an ADC value. You should look a bit
at the code that converts the ADC value into a resistance. You may be
able to reuse this code, or you may need to change it depending on how
you hook up your variable resistor. Once you know the resistance, you
will need to convert it to a speed value and output it as a value on a
HAL pin.

--
Charles Steinkuehler
cha...@steinkuehler.net

Sag ich Dir nich

unread,
Oct 10, 2016, 1:51:53 PM10/10/16
to Machinekit
Thank you,

I'll have a look

Sag ich Dir nich

unread,
Oct 14, 2016, 7:11:41 PM10/14/16
to Machinekit
Hi,

i have some questions about the file

from the "readtemp.py" file:
# The BeBoPr board thermistor input has one side grounded and the other side
# pulled high through a 2.05K resistor to 3.6V. Following this is a 470R
# resistor, some protection diodes, and a voltage divider cosisting of two
# 10.0K resistors. The ADC voltage read is the voltage across the lower 10K
# resistor in the 470R + 10K + 10K series chain
def adc2r(V_adc):
V_T = 0.0 # Voltage across the thermistor (and the 470R + 10K + 10K resistor chain)
I_PU = 0.0 # Current flowing through the 2.05K pull-up resistor
R_TD = 0.0 # Resistance of thermistor and the 470R + 10K + 10K divider chain in parallel
R_T = 0.0 # Resistance of the thermistor
V_T = V_adc * 2.0470 <= Is this the 2.05k resistor?
# No dividing by zero or negative voltages despite what the ADC says!
# Clip to a small positive value
I_PU = max((3.6 - V_T ) / 2050, 0.000001)
R_TD = V_T / I_PU
# Acutal resistance can't be negative, but we can get a negative value
# from the equation below for some real ADC values, so clip to avoid
# reporting crazy temperature values or dividing by zero
if R_TD >= 20470 : <= is this the resistance of the potentiometer i am going to use?
R_TD = 20470 - 0.1
# 1 / Rtotal = 1 / ( 1 / R1 + 1 / R2 )
# R2 = ( R1 * Rtotal ) / ( R1 - Rtotal )
R_T = ( 20470 * R_TD ) / ( 20470 - R_TD )

also i dont know what i have to use and what not to use from the following:

return R_T
# Convert resistance value into temperature, using thermistor table
def r2t(n, R_T):
temp_slope = 0.0
temp = 0.0
i = max(bisect.bisect_right(R_Key[n], R_T) - 1, 0)
temp_slope = (thermistor[n][0][i] - thermistor[n][0][i+1]) / (thermistor[n][1][i] - thermistor[n][1][i+1]) |
temp = thermistor[n][0][i] + ((R_T - thermistor[n][1][i]) * temp_slope) | i guess i dont need this part
#print "Temp:", temp, "i.R_T:", i, R_T, "slope:", temp_slope, |
#print "Deg.left:", Thermistor["epcos_B57560G1104"][i], "Deg.right:", Thermistor["epcos_B57560G1104"][i+1] |
return temp
parser = argparse.ArgumentParser(description='HAL component to read ADC values and convert to temperature')
parser.add_argument('-n','--name', help='HAL component name',required=True)
parser.add_argument('-N','--num_chan', help='Number of analog inputs to support',default=1)
parser.add_argument('-a','--adc', nargs='+', help='ADC input to read', required=True)
parser.add_argument('-t','--therm',nargs='+', help='Thermistor table to use', required=True)
args = parser.parse_args()
num_chan = int(args.num_chan)
if len(args.adc) != num_chan :
raise UserWarning('Incorrect number of ADC channels specified! Expected:' + str(args.num_chan) + str(len(args.adc)) )
if len(args.therm) != num_chan :
raise UserWarning('Incorrect number of thermistors specified! Expected:' + args.num_chan)
syspath = '/sys/devices/ocp.*/44e0d000.tscadc/tiadc/iio:device0/'
FileName = []
for i in range(num_chan):
TempName = glob.glob (syspath + 'in_voltage' + args.adc[i] + '_raw')
FileName.insert(i, TempName[0])
try:
if len(FileName[i]) > 0:
f = open(FileName[i], 'r')
f.close()
time.sleep(0.001)
else:
raise UserWarning('Bad Filename')
except (UserWarning, IOError) :
print("Cannot read ADC input: %s" % Filename[i])
sys.exit(1)
thermistor = []
R_Key = []
for i in range(num_chan):
if args.therm[i] in Thermistor:
# Shuffle array to make three lists of values (Temp, Resistane, Alpha)
# so we can use bisect to efficiently do table lookups
thermistor.insert(i, map(list, zip(*Thermistor[args.therm[i]])) )
# Pull out the resistance values to use as a key for bisect
R_Key.insert(i, thermistor[i][1] )
else:
print("Unknown thermistor type: %s" % args.therm)
print 'Try one of:', Thermistor.keys()
sys.exit(1)
h = hal.component(args.name)
for i in range(num_chan):
h.newpin("raw" + str(i), hal.HAL_U32, hal.HAL_OUT)
h.newpin("temp" + str(i), hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
Err = 0.0
ADC_V = 0.0
temp = 0.0
while 1:
try:
for i in range(num_chan):
f = open(FileName[i], 'r')
ADC_IN = int(f.readline())
h['raw' + str(i)] = ADC_IN
ADC_V = float(ADC_IN) * 1.8 / 4096.0
temp = r2t(i,adc2r(ADC_V))
h['temp' + str(i)] = temp
#print ADC_IN, temp
f.close()
time.sleep(0.001)
time.sleep(0.049)
except IOError:
continue
except KeyboardInterrupt:
raise SystemExit

thanks in advance

Charles Steinkuehler

unread,
Oct 15, 2016, 12:12:19 PM10/15/16
to machi...@googlegroups.com
On 10/14/2016 6:11 PM, Sag ich Dir nich wrote:
> Hi,
>
> i have some questions about the file
>
> from the "readtemp.py" file:
> # The BeBoPr board thermistor input has one side grounded and the other side

The BeBoPr is probably the most complex example to use as a reference,
since it has a more complicated input circuit than any of the other
boards.

Basically, you need to create a routine that converts a raw ADC value
into the resistance of your variable resistor. How to do this depends
on how you have the resistor connected and the input circuitry (if
any) between the ADC and your variable resistor.

If you are using a standard board (BeBoPr or CRAMPS or whatever) you
can use the routine for that board to get a resistance value as long
as you haven't changed any of the input circuitry.

What you do with the resistance value from there on is up to you, you
can feed it directly into HAL as a value, convert it to a percentage,
apply a linear or log scale to the value (which might be needed to get
the response curve you want from various dial positions which again
will depend on the type of potentiometer you are using and the input
circuitry).

--
Charles Steinkuehler
cha...@steinkuehler.net

Sag ich Dir nich

unread,
Jun 28, 2017, 11:28:44 AM6/28/17
to Machinekit
hello, i tried feeding the thermistor value to halui.spindle-override.counts but i got an error "can not add float to s32" so i added a rt component called conv_float_s32 and technically it worked and started without error. I can see changes (very non-linear!) in adc value therm.ch04.raw from 1 to 4010 when i turn the pot but not on halui.spindle-override.counts(also no change in spindle speed when i turn the pot). What do i have to add to let the adc value change the counts from halui?

this is my code:

# Python user-mode HAL module to read ADC value and generate a thermostat output for PWM
# c = analog input channel and thermistor table
loadusr -Wn Therm hal_temp_bbb -n Therm -c 04:epcos_B57560G1104,05:epcos_B57560G1104 -b CRAMPS

###########################
#Spindle and Feed Override#
###########################

loadrt conv_float_s32 count=2 

#newsig bed.temp.meas float
#newsig Feed.override float

net conv-float-s32.1.in <= Therm.ch-04.value
net conv-float-s32.1.out => halui.spindle-override.counts

setp halui.spindle-override.scale 0.1
#net bed.temp.meas <= Therm.ch-04.value
#net bed.temp.meas => halui.spindle-override.counts# <= Therm.ch-04.value

#setp halui.feed-override.scale 0.01
#net Spindle.override <= Therm.ch-05.value
#net Feedoverride halui.feed-override.counts# <= Therm.ch-05.value


thanks

Sag ich Dir nich

unread,
Jul 1, 2017, 11:19:54 AM7/1/17
to Machinekit
i can see, that the value or raw input from the thermistor is going into conv-float-s32.1.in but conv-float-s32.1.out is always zero, why is this?

Bas de Bruijn

unread,
Jul 1, 2017, 12:51:24 PM7/1/17
to Sag ich Dir nich, Machinekit


On 1 Jul 2017, at 17:19, Sag ich Dir nich <stevie.r...@live.de> wrote:

i can see, that the value or raw input from the thermistor is going into conv-float-s32.1.in but conv-float-s32.1.out is always zero, why is this?

Did you add the function to the servo thread?

--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
Visit this group at https://groups.google.com/group/machinekit.
For more options, visit https://groups.google.com/d/optout.

Sag ich Dir nich

unread,
Jul 1, 2017, 3:25:30 PM7/1/17
to Machinekit, stevie.r...@live.de
yes i did, but it gives me an error, either with "addf conv-float-s32.1 servo-thread" or "addf conv-float-s32 servo-thread" it says:

machinekit@beaglebone:~$ linuxcnc
MACHINEKIT - 0.1
Machine configuration directory is '/home/machinekit/machinekit/configs/ARM.BeagleBone.CRAMPS'
Machine configuration file is 'CRAMPS.ini'
Starting Machinekit...
io started
halcmd loadusr io started
cape-universal overlay found
cape-bone-iio overlay found
CRAMPS.hal:712: addf failed: hal_add_funct_to_thread:230 HAL error: function 'conv-float-s32' not found
Shutting down and cleaning up Machinekit...
exiting HAL component Therm
Cleanup done
Machinekit terminated with an error.  You can find more information in the log:
    /home/machinekit/linuxcnc_debug.txt
and
    /home/machinekit/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal
machinekit@beaglebone:~$


isnt it the function called "conv_float_s32.so"? if yes, i have that file in the xenomai directory.

Bas de Bruijn

unread,
Jul 1, 2017, 3:31:06 PM7/1/17
to Sag ich Dir nich, Machinekit


On 1 Jul 2017, at 21:25, Sag ich Dir nich <stevie.r...@live.de> wrote:

yes i did, but it gives me an error, either with "servo-thread" or "addf conv-float-s32 servo-thread" it says:


Below statement explains:
hal_add_funct_to_thread:230 HAL error: function 'conv-float-s32' not found

In a terminal type:
halcmd show function

This spits out all the functions (of components you instantiated) you can add to the servothread. It probably is named something like conv-float-s32.1.funct

Sag ich Dir nich

unread,
Jul 1, 2017, 3:52:09 PM7/1/17
to Machinekit, stevie.r...@live.de
thank you,

because i dont know what all these values mean, i will just copy what it gives me. This is what it shows:

machinekit@beaglebone:~$ halcmd show function
Exported Functions:
  Comp   Inst CodeAddr      Arg           FP   Users Type    Name
  1111   1113 0000b51d5aa9  0000b66a6eb0  YES      1 xthread abs-speed.funct
   712        0000b53179b5  0000b66a78f8  NO       1 thread  bb_gpio.read
   712        0000b5317865  0000b66a78f8  NO       1 thread  bb_gpio.write
  1368   1370 0000b517dab9  0000b66a6600  YES      0 xthread conv_float_s32.0.fu nct
  1368   1379 0000b517dab9  0000b66a65e8  YES      0 xthread conv_float_s32.1.fu nct
    66        0000b66c46fd  000000000000  NO       0 user    delinst
  1072        0000b51f9d0d  0000b66a6f10  NO       1 thread  eqep.update
   778        0000b52f09a1  0000b66a7780  YES      1 thread  hpg.capture-positio n
   778        0000b52f0a0d  0000b66a7780  YES      1 thread  hpg.update
  1052   1054 0000b520ca79  0000b66a6fe0  YES      1 xthread limit1.0.funct
  1052   1063 0000b520ca79  0000b66a6fc8  YES      1 xthread limit1.1.funct
   350        0000b55e03d5  000000000000  YES      1 xthread motion-command-hand ler
   350        0000b55e38c9  000000000000  YES      1 xthread motion-controller
  1145   1340 0000b51a2afd  0000b66a6638  YES      1 xthread near.0.funct
    66        0000b66c45ad  000000000000  NO       0 user    newinst
  1098   1100 0000b51e6ac1  0000b66a6ed0  YES      1 xthread pid-correction.func t
  1052   1192 0000b520ca79  0000b66a6d90  YES      1 xthread pid-limit.funct
   980    982 0000b521e06d  0000b66a70a8  YES      1 xthread pid.0.do-pid-calcs
   980   1017 0000b521e06d  0000b66a7000  YES      1 xthread pid.1.do-pid-calcs
  1123   1514 0000b51c4a49  0000b66a63f0  YES      1 xthread scale-current-feed. funct
  1123   1322 0000b51c4a49  0000b66a6688  YES      1 xthread scale.0.funct
  1123   1331 0000b51c4a49  0000b66a6670  YES      0 xthread scale.1.funct
   980   1157 0000b521e06d  0000b66a6da8  YES      1 xthread speed-pid.do-pid-ca lcs
  1145   1147 0000b51a2afd  0000b66a6e50  YES      1 xthread spindle-at-speed-de tect.funct
  1134   1136 0000b51b3a81  0000b66a6e70  YES      1 xthread spindle-rpm-filter. funct
  1123   1125 0000b51c4a49  0000b66a6e90  YES      1 xthread spindle-rps2rpm.fun ct
  1206        0000b518f355  0000b66a66d0  YES      0 thread  stepgen.capture-pos ition
  1206        0000b518f011  0000b66a66d0  NO       0 thread  stepgen.make-pulses
  1206        0000b518f4b1  0000b66a66d0  YES      0 thread  stepgen.update-freq

machinekit@beaglebone:~$

Bas de Bruijn

unread,
Jul 1, 2017, 4:14:24 PM7/1/17
to Sag ich Dir nich, Machinekit


On 1 Jul 2017, at 21:52, Sag ich Dir nich <stevie.r...@live.de> wrote:

thank you,

because i dont know what all these values mean, i will just copy what it gives me. This is what it shows:

Well, read the last mail. That was about finding the correct name for adding your components function to the servothread.

The output shows the available functions of all instantiated components you have.

You add the function (find the name of the component function (in this case it ends with .funct, but that could bet named otherwise), and add that to a thread.
(not going to do the reading for you ;) )

Sag ich Dir nich

unread,
Jul 1, 2017, 4:43:54 PM7/1/17
to Machinekit, stevie.r...@live.de
excuse me, i had to make "_" out of "-" and add ".funct" to addf (which i did not know because in the manual it says "conv-float-s32.N"). Now it is like: addf conv_float_s32.0.funct servo-thread

now it loads without error but still no output. The thing is, the Halmeter pins "conv_float_s32.0.in" and "conv_float_s32.1.in" also have 0 as value but the signals have a value which i can change by turning the pot.  The Parameters "motion.debug-s32-0" and "motion.debug-s32-1" also have a value of 0

Bas de Bruijn

unread,
Jul 1, 2017, 5:18:17 PM7/1/17
to Sag ich Dir nich, Machinekit


On 1 Jul 2017, at 22:43, Sag ich Dir nich <stevie.r...@live.de> wrote:

excuse me, i had to make "_" out of "-" and add ".funct" to addf (which i did not know because in the manual it says "conv-float-s32.N"). Now it is like: addf conv_float_s32.0.funct servo-thread

now it loads without error but still no output. The thing is, the Halmeter pins "conv_float_s32.0.in" and "conv_float_s32.1.in" also have 0 as value but the signals have a value which i can change by turning the pot.

Are you sure you have a signal going into your component?

What does the following say:
halcmd show pin conv_float_s32.0

Sag ich Dir nich

unread,
Jul 1, 2017, 5:54:35 PM7/1/17
to Machinekit, stevie.r...@live.de
got it working now :)

thats my config:

###########################
#Spindle and Feed Override#
###########################

loadrt conv_float_s32 count=2 

newsig spindleoverride1  float
newsig spindleoverride2  s32
newsig feedoverride1     float
newsig feedoverride2     s32

addf conv_float_s32.0.funct servo-thread
addf conv_float_s32.1.funct servo-thread 

net spindleoverride1 conv_float_s32.0.in <= Therm.ch-04.value
net spindleoverride2 conv_float_s32.0.out => halui.spindle-override.counts

net feedoverride1 conv_float_s32.1.in <= Therm.ch-05.value
net feedoverride2 conv_float_s32.1.out => halui.feed-override.counts

setp halui.spindle-override.count-enable 1
setp halui.spindle-override.scale 0.01

setp halui.feed-override.count-enable 1
setp halui.feed-override.scale 0.01

thank you very much for your help!

Sag ich Dir nich

unread,
Jul 1, 2017, 6:01:03 PM7/1/17
to Machinekit, stevie.r...@live.de
but i need to get it linear, also when i turn the pot to max (100% and 150%) and then turn it slightly back, it is instantly at 0%. If i slowly or fast turn it, but not to max, this doesnt happen.

Sag ich Dir nich

unread,
Jul 1, 2017, 7:37:39 PM7/1/17
to Machinekit, stevie.r...@live.de
Updated code:

###########################
#Spindle and Feed Override#
###########################

loadrt conv_float_s32 count=2 

loadrt limit1   names=spindle-limit
loadrt limit1   names=feed-limit

newsig spindleoverride1  float
newsig spindleoverride2  s32
newsig feedoverride1     float
newsig feedoverride2     s32

addf conv_float_s32.0.funct servo-thread
addf conv_float_s32.1.funct servo-thread 
addf spindle-limit          servo-thread
addf feed-limit             servo-thread

setp spindle-limit.max   172
#setp spindle-limit.min   0
setp feed-limit.max      172
#setp feed-limit.min      0

net spindlelimit spindle-limit.in <= Therm.ch-04.value

net spindleoverride1 conv_float_s32.0.in <= spindle-limit.out #Therm.ch-04.value
#net spindleoverride1 conv_float_s32.0.in <= Therm.ch-04.value
net spindleoverride2 conv_float_s32.0.out => halui.spindle-override.counts

net feedlimit feed-limit.in <= Therm.ch-05.value

net feedoverride1 conv_float_s32.1.in <= feed-limit.out #Therm.ch-05.value
#net feedoverride1 conv_float_s32.1.in <= Therm.ch-05.value
net feedoverride2 conv_float_s32.1.out => halui.feed-override.counts

setp halui.spindle-override.count-enable 1
setp halui.spindle-override.scale 0.01

setp halui.feed-override.count-enable 1
setp halui.feed-override.scale 0.01


Sag ich Dir nich

unread,
Jul 2, 2017, 2:11:32 PM7/2/17
to Machinekit, stevie.r...@live.de
okay i need a little advise here, i want to change the Thermometer Table to linear, can i just delete all values between the first and the last and machinekit calculates all inbetween itself?

Daren Schwenke

unread,
Jul 5, 2017, 7:43:31 PM7/5/17
to Machinekit, stevie.r...@live.de
Never tried it, but that should work.  If not, create one more value mid-way.  
As the thermistor code is just python, you could hack your own as well without the table pretty simply.

I often thought of doing exactly what you did here, and I'll be stealing your config bits probably.  :)
Physical buttons for x,y,z feed and a home button are on the agenda too.

Sag ich Dir nich

unread,
Jul 6, 2017, 4:12:48 AM7/6/17
to Machinekit, stevie.r...@live.de
feel free to use my code :)

Sag ich Dir nich

unread,
Jul 7, 2017, 5:24:34 PM7/7/17
to Machinekit, stevie.r...@live.de
this Thermistor table worked for me (using linear Rotary Potentiometers):

# Thermistor table for Linear2
# Temp Resistance aplha
0.0 9500 7.4 
150.0 0.0 1.4  

the 9500 is the working resistor value for me, if your feed override doesnt go to 0% try reducing it to for example 9000

mine is called Linear2.txt and placed in usr/share/fdm/thermistor_tables and loaded with:

loadusr -Wn Therm hal_temp_bbb -n Therm -c 04:Linear2,05:Linear2 -b CRAMPS 

Am Donnerstag, 6. Juli 2017 01:43:31 UTC+2 schrieb Daren Schwenke:

Sag ich Dir nich

unread,
Sep 9, 2017, 5:48:31 PM9/9/17
to Machinekit
finally i found out how to change it to absolute:

loadrt conv_float_s32 count=2 

loadrt limit1   names=spindle-limit
loadrt limit1   names=feed-limit

newsig spindleoverride1  float
newsig spindleoverride2  s32
newsig feedoverride1     float
newsig feedoverride2     s32

addf conv_float_s32.0.funct servo-thread
addf conv_float_s32.1.funct servo-thread 
addf spindle-limit          servo-thread
addf feed-limit             servo-thread

setp spindle-limit.max       400
setp feed-limit.max          400

net spindlelimit spindle-limit.in <= Therm.ch-04.value

net spindleoverride1 conv_float_s32.0.in <= spindle-limit.out
net spindleoverride2 conv_float_s32.0.out => halui.spindle-override.counts

net feedlimit feed-limit.in <= Therm.ch-05.value

net feedoverride1 conv_float_s32.1.in <= feed-limit.out
net feedoverride2 conv_float_s32.1.out => halui.feed-override.counts
net feedoverride2 conv_float_s32.1.out => halui.rapid-override.counts

setp halui.spindle-override.count-enable 1
setp halui.spindle-override.scale 0.01
setp halui.spindle-override.direct-value true

setp halui.feed-override.count-enable 1
setp halui.feed-override.scale 0.01
setp halui.feed-override.direct-value true

setp halui.rapid-override.count-enable 1
setp halui.rapid-override.scale 0.0066666666666666666666666666666667
setp halui.rapid-override.direct-value true



it works good but one thing, you need to turn the knob just a tiny bit otherwise the overrides stay at 100% at startup of the machine.
Reply all
Reply to author
Forward
0 new messages