Page 1 of 1
some modules: PID, pulse density mod, MAX6675,...
Posted: Wed Oct 29, 2014 8:09 pm
by Beau
Hi all,
I implemented a little PID controller and associated modules. If anyone would be interested, the code is up on github
https://github.com/B3AU/micropython
for now it contains code for these things:
-PID: a PID feed-back loop
-MAX6675: thermocouple measurement chip (discontinued, will add code for the replacement soon)
-PDM: pulse density modulator, used to control a heater using an SSR. Has some benefits over PWM.
-lcd: sparkfun serial graphical lcd 'backpack'
-FIR: finite impulse response, moving average, smoothing class
-rotary: rotary encoder lib
Re: some modules: PID, pulse density mod, MAX6675,...
Posted: Wed Oct 29, 2014 10:57 pm
by dhylands
Cool - I've been thinking of making a reflow oven using micropython as the temperature controller.
Re: some modules: PID, pulse density mod, MAX6675,...
Posted: Thu Oct 30, 2014 7:41 am
by pythoncoder
@Beau There's some useful code there. I hope you don't mind a couple of constructive comments. Have you considered augmenting the FIR code (perhaps by means of a subclass) to handle a coefficients array to build a generic FIR filter?
Regarding the rotary encoder class, it might be worth using the exclusive or operator which avoids the conditional statements in the callbacks. See my
http://forum.micropython.org/viewtopic. ... =368#p1999
Regards, Pete
Re: some modules: PID, pulse density mod, MAX6675,...
Posted: Thu Oct 30, 2014 9:58 am
by Beau
Of course I don't mind. That's mainly why I share the code
I like that use of the OR operator and I'll include it over the weekend.
The coefficients seem like a good idea as well. Would be easier if I could just use floats though but the byte array doesn't seem to support that at the moment. Floats would also allocate memory and a FIR is probably more useful if you can use it as a callback from an interrupt.
I can't seem to find any information on how the uPy bytearray implementation differs from the CPython one? Would be useful to include the difference in the wiki
https://github.com/micropython/micropyt ... Difference
Re: some modules: PID, pulse density mod, MAX6675,...
Posted: Thu Oct 30, 2014 1:33 pm
by JonHylands
I have C code that implements via a finite state machine, a reflow oven controller here:
https://github.com/dhylands/projects/tr ... eflow-oven
Its pretty simple, and it works great - I've built 100's of boards with my oven. Shouldn't be too hard to convert to python.
Re: some modules: PID, pulse density mod, MAX6675,...
Posted: Thu Oct 30, 2014 6:00 pm
by pythoncoder
@Beau Re coefficients I agree that the FIR code is most likely to be used in an interrupt service routine. This means it's best (well, mandatory as I understand it) to avoid floats and to ensure that the results of the multiply and add don't exceed 30 bits and cause Micropython to do a heap allocation. For real world values derived from sensors this leaves plenty of leeway but the user does need to understand the issues. Such is life
Regards, Pete