I'll have a look
| # 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 ) |
| 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 | |
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?
--
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.
yes i did, but it gives me an error, either with "servo-thread" or "addf conv-float-s32 servo-thread" it says:
thank you,because i dont know what all these values mean, i will just copy what it gives me. This is what it shows:
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-threadnow 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.