Adruino PID and Hall Effect Flowmeter interrupts. Programmers Needed!?

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

GoeHaarden

The best advice is unsolicited
Joined
Feb 1, 2017
Messages
1,323
Reaction score
738
I'm going to preface this with the fact that I work in medicine, and my programming background consists of googlefoo. I'm have learned a lot here and other forums, but I know my programming is not near as efficient as the pros out there...so I need help.

So, I'm currently trying to expand my arduino RIMS controller to incorporate a flow meter(s) to eventually automate sparging speed/control. As well as add a low flow safety to my RIMS element. My setup currently consists of an Ardunio MEGA running a PID algorithm with DS18B20 temp sensors. I have a serial touch screen as well. My PID algorithm calls an interrupt every 15ms, and the hall effect flowmeter uses interrupt pulses to count flow. You can probably already predict my dilemma. When the PID is running, the interrupts interferes with the flowmeter count and my flow calculations are skewed. Now I haven't hardwired anything yet, and I've just been doing breadboard testing. I can clearly see the inconsistencies in flow when the PID is running.

I have thought about adding an arduino MINI to control the flowmeters, and send the data to MEGA via serial communication. I've only been able to send integers and not doubles via serial, but I save accuracy by multiplying by 10 on the slave then dividing by 10 on the master. However, I have noticed that the serial data can get backed up which causes errors. So, I kind of abandoned this approach for now....

So, my question is has anyone else implemented something like this? There has to be a better way to do this other than serial communication. Or should I keep trying to perfect it with serial data? It just doesn't seem like the best way...

Thanks for any and all help...
 
Given that our temperatures don't change very fast, you can use the time library to check everything once a second. In your main loop check if a second has gone by. Once it has call a function to measure the temp and use the updated temp to update the PID. It looks like the code you linked is already using the milliseconds from the time library to control the duty cycle of the output, so probable dont need to change that at all. As @BrunDog mentioned there is no need to use interrupts for slow moving PID control.
 
Given that our temperatures don't change very fast, you can use the time library to check everything once a second. In your main loop check if a second has gone by. Once it has call a function to measure the temp and use the updated temp to update the PID. It looks like the code you linked is already using the milliseconds from the time library to control the duty cycle of the output, so probable dont need to change that at all. As @BrunDog mentioned there is no need to use interrupts for slow moving PID control.

My main loop returns a lot faster than 1 second. Without an interrupt, wouldn't checking for temp change be dependent on the main loop cycle anyways? Should I just get rid of the timer interrupt, since wort is flowing, and run the element 100% when the PID is running.

So just call this in main loop instead without putting it in an interrupt?

Code:
[*]void DriveOutput()
[*]{
[*]long now = millis();
[*]// Set the output
[*]// "on time" is proportional to the PID output
[*]if(now - windowStartTime>WindowSize)
[*]{ //time to shift the Relay Window
[*]windowStartTime += WindowSize;
[*]}
[*]if((onTime > 100) && (onTime > (now - windowStartTime)))
[*]{
[*]digitalWrite(RelayPin,HIGH);
[*]}
[*]else
[*]{
[*]digitalWrite(RelayPin,LOW);
[*]}
[*]}
 
Every time you enter the main loop, check to see if 1000 milliseconds have past. If they have then call your functions to update the temp and PID, if not skip past that and go straight to the output duty cycle code.
 
Back
Top