• Advertisement

The Accidental Controller

This forum is the place to post and find information about electric controls.

The Accidental Controller

Postby Bing » Tue Jun 19, 2018 7:48 pm

This is my initiation into programming a microcontroller for my still. It was the furthest thing from my mind when my cousin J came for a visit last year. He is an EE and before careers and family we spent a lot of time together. After 40 years he is still one of the kindest people you are likely to meet. He really wanted to build something for my still and I said sure.

The assembly is a main board and a slave board. It has four RTD channels and four relays (2-16amp and 2- 3 amp). There is also a connection for a 50amp relay for the heat element. It has a 4x20 display and 8 little switches. There is also a little auxiliary load cell board that connects between an Oxo digital scale and the main board. I am waiting on a couple items from digikey before I can finish the electrical connections.

J has done all the low level programming in C and with a few tweaks and mods it seems to work ok on the bench. My job is to write the code for its functionality. Although I know next to nothing about electronics and programming and only a little about physics and chemistry, I have been studying and am hopeful I can fill in the gaps between J’s code and Maritimers algorithms. Oh yeah, and J knows nothing about distilling. We make a great pair! That’s it for now. Here are some pics

Cheers

Dang- can only upload 3 pictures
Attachments
control.jpg
The hole is where the controller will be placed
scale.jpg
This little board connects to the load cell of the scale
boards.jpg
The main and slave boards
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Maritimer » Thu Jun 21, 2018 5:04 am

That's a mighty still I see in the background.

What kind of microcontroller are you using? Can you post the manual that comes with it?

Are you familiar with flow charts and state diagrams? I like to use Gliffy Diagrams. It's a free app available from http://www.gliffy.com .

As a beginner programmer, you'll be tempted by bottom-up programming, that is, writing little pieces of code that work and then pulling them together into a program. After you do that for a while, you'll begin to appreciate that top-down produces better programs.

In top-down, you work from an overview perspective and then fill in the little pieces of code.

So let's start at the top of the top--fantasize about using your still after it has been instrumented.

You can think of the microcontroller as a little gremlin operating your still. It can watch out for dangerous conditions; remember which procedures it used and apply them to the next run; or maintain a model of the still, always updating conditions and reacting to them.

A fantasy, please.
User avatar
Maritimer
 
Posts: 95
Joined: Tue Mar 18, 2014 1:35 pm
Location: Nova Scotia, Canada
Equipment type: 2" VM, pot still for stripping, digitally-controlled-power power supply, flow switch on coolant

Re: The Accidental Controller

Postby Bing » Thu Jun 21, 2018 10:09 am

:D :D :D

It is MatLab''s pic24fj128gc010
www.microchip.com/sitesearch/search/All/pic24fj128gc010
I will be using Microchip IDE as well.

I am a little familiar with flowcharts. I started a couple crude ones. State diagrams are a similar graphic of process rather than program flow? I will investigate Gliffy. Thanks.

Bottom-up programming is exactly where I gravitate. Baby steps. But the notion of building your castles in the sky and then underpinning them is an appealing and yet intimidating one.

My fantasy view I think, with a pot still and thump, is rather simple. I have a strip process and a spirit process- and possibly a column process.
The strip process will run at full power and shut down automatically (2 states? On and off). Will it shut down by time? By proof? By weight? I’m not sure.

The spirit process will have power controlled to maintain a takeoff rate determined by weight over time. And shut down automatically as well. 16-18 ml/min seem to be a sweet spot for me. Clearly dynamics of wash composition are in play here. Intuitively it seems to me that collecting by weight, adjusted for composition, over time, is a good idea.

I haven’t given much thought to a column process. I have the makings of a 3” ccvm on my bench but it is dormant for now.

Collect and export data for graphical display. This was my first and only plan before the scale idea. I wanted to understand (and visualize) the process.

Regulating coolant isn’t a concern for me because I have a recirculating system.

A bit on the calculations (and fantasy):
In my career as a surveyor, including some high order work, I always started with an error budget, so to speak. It was an axiom that no measurement is exact, you never know what the true measurement is, and what effect will individual error have on your overall scheme. I’m not sure if that kind of analysis has a place in my software but to have an solution that quantifies a range of truth at a given confidence level comports with my sensibilities (whew!).
But in simplest terms, I think it important get a feel for how much influence a given measuring error has on the downstream calculations.

Cheers
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Bing » Thu Jun 21, 2018 12:11 pm

That is MicroChip- not MatLab :doh:
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Maritimer » Fri Jun 22, 2018 12:35 pm

That certainly looks like a very capable microcontroller. With 128k of program memory and 8k of ram, you'd have a hard time running out of room in that baby.

Is this the board you have: http://ww1.microchip.com/downloads/en/D ... 02172a.pdf ?

If you want to use my algorithms, you'll need four temperature sensors: boiler, ambient, coolant in, and coolant out (also vapor temperature, but that can be related to boiling temperature). Since you have a recirculating system, can we assume that the coolant flow is constant?

With constant coolant flow and knowledge of the composition of the wash, power can be adjusted in a feedback loop to set the temperature difference between coolant in and coolant out of the condenser, determining the product mass rate.

I appreciate your concern for measurement error. If you send your coolant temperatures to two 12-bit analog-to-digital converters (ADCs) and subtract the integers that the analog voltages are converted to, you'll get lousy resolution. But use an analog differential amplifier across two 1% temperature sensors with offset and gain trims and you'll be able to use the full range of the ADC.

On the other hand, what would the errors be when using scales? And how would the product be measured? If you use the scales, you'll be measuring the differential--the rate of change of total weight--a notoriously noisy signal. Small changes within a large range.

Interfacing with your power controller might be a problem if it the kind that uses resistance to set the power.

I've only used a pot still for stripping. Would there ever be a need for different heating regimes? There it is! Zymurgy Bob's Making Fine Spirits. Yes, some power adjustments required.

BTW, how are you set up for electronics?
User avatar
Maritimer
 
Posts: 95
Joined: Tue Mar 18, 2014 1:35 pm
Location: Nova Scotia, Canada
Equipment type: 2" VM, pot still for stripping, digitally-controlled-power power supply, flow switch on coolant

Re: The Accidental Controller

Postby Zymurgy Bob » Fri Jun 22, 2018 1:15 pm

Woohoo for the analog differential amps! Analog hardware is not dead . . . yet.
Zymurgy Bob, a simple potstiller http://www.kelleybarts.com/zymurgy-bob- ... e-spirits/

You can make whisky in a reflux still, you can make vodka in a potstill,
and you can eat chicken noodle soup with a crescent wrench. But...
User avatar
Zymurgy Bob
 
Posts: 2790
Joined: Sat May 30, 2009 3:03 pm
Location: Upper-left US
Equipment type: 60L unpacked 20"x2", propane, with Liebig

Re: The Accidental Controller

Postby Bing » Fri Jun 22, 2018 6:56 pm

Hi M

The board is a one-off designed by Cousin J. He provided the scheme and had them printed. I think our cost was $30 for10 (min order). And that included shipping from China! He then soldered in all components. After bench testing he added a few more.

Four temp sensors is what I have and coolant flow is constant. I hope to incorporate all of your algorithms by some point. My knowledge of the hardware is almost embarrassing but I will find out about the temp sensors. J did have a concern about signal noise with clock and data lines out of the load cell amp so they'll use shielded cable.

I just remembered that Kareljte (sp?) hacked a digital scale for his use. I don't recall how he used it in his scheme.

The power is run through a Crydom 10PCV24xx control relay controlled by the microcontroller. All I know about the power is that’s it’s an unsigned 16 bit number. Seems large to me.

Managing power thru a feedback loop based on temps and flow is a method that I believe you have shown to be sound. How the scale will perform remains to be seen. I am keen to see how they compare. I have some ideas but not afraid to abandon them either

I think the Gliffy diagramming editor is the cats pajamas. I input and updated my flowchart to a more top down approach today. And will continue to build on it. Thanks!

I looked at definitions and examples of state diagrams. I’m not hearing in that key yet :?

Maritimer wrote:BTW, how are you set up for electronics?

I'm not sure what you're asking

Thanks again for feedback and advice

Regards
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Maritimer » Sat Jun 23, 2018 12:03 pm

It's very reassuring to put a voltmeter on a differential temperature sensor and see a number: that's what your condenser is doing, quantitatively.

By How are you set up for electronics? I mean do you have a multimeter, soldering iron, breadboard, parts, etc? Are you willing to spend a couple of hundred dollars for tools and supplies so that you'll be able to construct boxes with electrical components, connectors, switches, etc? At some point, you'll wire up some circuit boards.

The Crydom 10PCV24xx looks good. Sounds like there is a 16-bit register for its control. That number has to be turned into an analog voltage to control the Crydom. Easy to do with a pulse width modulated (PWM) signal, some resistors and capacitors, maybe an op-amp.

I control power using zero-crossing solid state relays (SSRs) https://media.digikey.com/pdf/Data%20Sh ... 216S02.pdf . This is the integrated circuit component, itself. The Crydom unit is something like this but put into a package. Maybe Crydom has a zero-crossing product. Anyway, what you have is perfect.

Glad to see you're having fun with the Gliffy diagrams.

I use state diagrams when designing digital circuits. You're in one state, say 0100 and you get an input signal telling you to go to 1100. So you jump to state 1100 and depending on which input signals arrive next, you could go to state 1001 or 0001 and so on.

Think of boiling, equilibrating , and collecting fores, etc as states. Certain conditions must exist to go from one state to another. But there are other conditions that are bad and the next logical state may have to be delayed. With the state diagram to illustrate the code, you get a very visual idea of what the program is doing.

Could you post your Gliffy flowchart?
User avatar
Maritimer
 
Posts: 95
Joined: Tue Mar 18, 2014 1:35 pm
Location: Nova Scotia, Canada
Equipment type: 2" VM, pot still for stripping, digitally-controlled-power power supply, flow switch on coolant

Re: The Accidental Controller

Postby Bing » Sat Jun 23, 2018 2:38 pm

Condenser as a voltmeter is a very nice analogy :)

I have basic tools, hobby solder iron and a multimeter. What I have now will keep me busy for a while.

The board has MAX31865 rtd-to-digital converters. They have built in open or short circuit detection. It was Edwin Croissant who hacked the scale, not Kareltje. He also programmed it to display ml/min; presumably for feedback on power control? I'm not arguing the merits of a method of power control. But it is intriguing to me :)

Still reading on state... maybe getting it. A state is a while loop. Defined in the program and called into play when triggered by input. Until a new input trigger- then its another while loop. Do state diagrams drive flowcharts? Or are they parallel thinking? I'm not seeing how a state diagram can identify a problem. A small example maybe? Thank you.

My gliffy is a first stab. And it has a missing connection. But it does show a top down flow to a strip and spirit process.

Cheers
Attachments
Flowchart.jpg
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Bing » Sat Jun 23, 2018 6:08 pm

And this is how it might look if the spirit leg heat were controlled by coolant temps
Attachments
control h2o.jpg
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Bing » Sun Jun 24, 2018 11:13 am

Bing wrote:Do state diagrams drive flowcharts? Or are they parallel thinking? I'm not seeing how a state diagram can identify a problem. A small example maybe? Thank you.


I found it! Had it all along. Too many loose papers :roll:
Attachments
State Diagram.jpg
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Maritimer » Mon Jun 25, 2018 5:59 am

Hi Bing,

Yesterday I wrote Mathematica code to linearize the Crydom controller. This morning I was going to turn it into C code but the file isn't there. Something is wrong with my computer. Looks like the memory card is developing Alzheimer's.

You can save the Gliffy diagrams as .png and .jpg images. Maybe we should exchange the files themselves. Might have to zip them, though.

That state diagram you found was done in Word. It took forever. Check out the finer points of Gliffy. You can put arrows on the lines, put colors in the boxes, etc.

No doubt you've heard of PID. PID stands for Proportional, Integral, Derivative. Here's a Wiki article: https://en.wikipedia.org/wiki/PID_controller . For thermal systems, the D isn't used. Your flow chart would seem to be an I (Integral) scheme, assuming by 'advance' and 'reduce' you mean to increment or decrement some value that is controlling the Crydom. That will work but it takes a while to get to the operating value. That's where the P (proportional) comes in. The P is some fraction of the error (the difference between the set point and current operating point) that is added to (or subtracted from) the value that is controlling the Crydom.

Let's discuss the overall design of the program. Cousin J has set you up so that you have the main function to work with. Everything (except interrupts) is called from within the main function.

After some setup stuff, you will enter a FOREVER loop. The program runs round and round the loop checking temperatures, the power to the boiler and error conditions. I like to go to different states as various conditions arise. Each state has conditions that apply.

As an exercise, maybe you could do a Gliffy diagram of the PI controller, complete with a FOREVER loop, arrows on the lines, and whatever else you can come up with. Post the diagram as a .png or .jpg. Check out snap to grid, too.

M
User avatar
Maritimer
 
Posts: 95
Joined: Tue Mar 18, 2014 1:35 pm
Location: Nova Scotia, Canada
Equipment type: 2" VM, pot still for stripping, digitally-controlled-power power supply, flow switch on coolant

Re: The Accidental Controller

Postby Bing » Mon Jun 25, 2018 3:43 pm

Oh dear- lost effort can be dispiriting; particularly if the effort accrues to the benefit of others :cry:

As a trial member of gliffy, a number of options aren't available to me yet. After 14 days it will ripen into a free version. Right now export is grayed out. I had turned off snap when the adjacent shapes don't line up. Oblique linework bothers me like a hangnail :) . Now I use snap and a squiggly line. Everything orthagonal, scale too small to see squiggle :) I think the selection tool is a little weak. Shifting a bunch of shapes requires individual selection. I tried to 'fence' them etc. Maybe its the trial version.

In my broad brush approach, reduce and advance heat aren't unit incremented ; more like an iteration but undefined so far.
I've been studying your method for using power in a loop scheme that SETS temp difference across the condenser. Cool stuff, really. I have read read of PID but need to learn more. PID, as I recall, seemed to have been met with some derision on another forum I visit. Different context?

OK overall program design. Let me chew on that a bit. And I have more reading and some gliffy exercices to do. :) Some of this is heavy lifting so I have to read more than once.

Regards
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA

Re: The Accidental Controller

Postby Maritimer » Wed Jun 27, 2018 8:21 am

Hi Bing,

Isn't it great having new stuff to learn! We haven't even mentioned C.

Yes, the context of the PID derision is in controlling the temperature of the wash. You will be controlling product rate by controlling the power delivered to the wash.

Incrementing and decrementing can be done with any number. Unit incrementing and decrementing use the ++ and -- operators. To increment with arbitrary values, you use the x+=5 notation, meaning that 5 is added to x. You could also say x=x+5.

I don't remember getting Gliffy. There was something unusual, though. I've always wondered why such a valuable resource is free.

There's something wrong with my Mathematica. It's not saving and it's corrupting the directories. I'll have to get a new version but not here in the country where the download speed maximum is 5 Mbits per second. Right now it's 0.6 Mbps Mathematica is well over 11 GB = 40.7407 hours. Maybe my friend in Halifax has high speed.

M
User avatar
Maritimer
 
Posts: 95
Joined: Tue Mar 18, 2014 1:35 pm
Location: Nova Scotia, Canada
Equipment type: 2" VM, pot still for stripping, digitally-controlled-power power supply, flow switch on coolant

Re: The Accidental Controller

Postby Bing » Wed Jun 27, 2018 6:32 pm

Hi Maritimer

I'm enjoying this :)

Latest flowchart as uploaded pics showing a forever loop. It only leaves the loop conditionally. The idea of ‘visiting states’ is sensible to me and I hope I show that properly. The display functions I’m showing seem weak but wanted to include something. I won’t have a file available until the end of next week and I hope arrows on the connections. The ones you see are pencil. Now using colors (don’t use a color printer) and I’m able to select elements by fence. I will continue to develop the flowchart in the meantime.

I’ve been studying J’s code as it exists along with the C documentation. The 4x20 display doesn’t use the standard printf and scanf functions (as I’m sure you know)…slogging through. J has included the table of conversions. I think the displays will be where I will spend the most time working on the C code.

On the overall program design, I have made a lot of notes. Then I backed off and reduced them to outline.
Powering up the 4x20 display I’ll see:
Setup
Strip
Spirit
Column

On setup I’ll enter the necessary variables. Alternatively compute them all. Selecting strip or spirit modes will also allow data entry from the screen, but more importantly display some data in real time. Refresh rate? Both strip and spirit screen will display changes to power or collection rate while in process. The display is an easy place to be overambitious it seems. I can always add stuff.

One last note: Maritimer, when you write let’s have a discussion on program design, I hope that is read as an open discussion. I’m aware that my project is unique and does not lend itself easily to other operations and experience. This is good learning for me. If you’re are following this I hope you are learning something too.

M- are you in the valley?

Edit- Just noticed...temps could get up to boil without the cooling system coming on :shock: To be fixed.
Attachments
Flowchart2a.jpg
Flowchart2.jpg
Bing
 
Posts: 11
Joined: Wed Apr 04, 2018 7:05 pm
Location: Ohio USA


Return to Electric Controls

Who is online

Users browsing this forum: No registered users and 2 guests