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
some modules: PID, pulse density mod, MAX6675,...
Re: some modules: PID, pulse density mod, MAX6675,...
Cool - I've been thinking of making a reflow oven using micropython as the temperature controller.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: some modules: PID, pulse density mod, MAX6675,...
@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
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
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: some modules: PID, pulse density mod, MAX6675,...
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
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
- JonHylands
- Posts: 69
- Joined: Sun Dec 29, 2013 1:33 am
Re: some modules: PID, pulse density mod, MAX6675,...
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.
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.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: some modules: PID, pulse density mod, MAX6675,...
@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
Regards, Pete
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.