Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4151

MicroPython • Re: Pico W Micropython bootloader (Jan 2024) may have caused my errors

$
0
0
FWIW

This is the 100k thermistor code I use for a multichannel PID 3d printer bed . The multiple channels are externally multiplexed into a single PICO ADC channel the set_filter() function is called from a 40mS timer.

The polynomial gives a wide range accurate result in less than 500uS. The 4th order coefficients are obtained by plotting the thermistor response v. temperature entering the data into a libre-calc spreadsheet and using the trend command to get a good fit

Code:

class Sensor(object):    def __init__(self, Channel, Ave=10):        #print(f"sensor{Channel} initialised")        self.adc0 =ADC(0)        self.CH = Channel        self.Filter=[]        self.Ave = Ave            def VT(self,X):        '''convert ADC Value to temp in °C'''        #4th order polynomial           X2 = X * X        X3 = X2 * X        X4 = X3 * X        T0 = (5.425E-16 * X4)        T1 = (6.485E-11 * X3)         T2= (2.895E-06 *X2)        T3 = (0.0548 * X)         return -T0+T1-T2+T3 - 273        def set_filter(self):        self.Filter.append(self.adc0.read_u16())        if len(self.Filter) >self.Ave :            self.Filter.pop(0)      def get_value(self):        Mtot=0        for M in self.Filter:            Mtot += M                return self.VT(Mtot//self.Ave)                    

Statistics: Posted by BillTodd — Wed Jan 24, 2024 7:18 pm



Viewing all articles
Browse latest Browse all 4151

Trending Articles