-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvo_Flow.ino
89 lines (75 loc) · 3 KB
/
Evo_Flow.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* 1 Flow Control -----------------------------------------------------------
9ml per minute with the motor we have
1a flowSet
1b pulseFeed
1c addMedia
*/
/* >>>>>>>>>>>>>>>>>>>>> Constants and Variables <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
float flowMax = 40; // Max flow rate in ml/hr
float volume = 30; // The chamber volume
int pulseFreq; // hz to set to pump
unsigned long pulseDuration = 10000; // default is 10 second pulse (do not change)
float pulseVol; // volume of pulse
float totalVol = 0; // total volume added
int pulseCount = 0;
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Functions<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
// 1a flowSet -- changes the frequency and pulse duration settings
void flowSet() {
pulseFreq = int((flowMax * (3600 / 200) + 1.1148) / 0.6757) + 1; // convert max flow to Hz (10 second pulse 20 times an hour) **FROM CALIBRATION**
pulseFreq = constrain(pulseFreq, 31, 200);
if (pulseFreq == 200) { // if flow Hz is maxed, change pulse duration
pulseDuration = long(flowMax / 134.025 * 3600 / 20 * 1000); // 134 is ml/hr at 200 hz **FROM CALIBRATION**
feedFrequency = 180000;
pulseVol = flowMax / 20;
}
else if (pulseFreq == 31) { // if the flow rate is slow decrease the feed frequency
pulseDuration = 10000;
feedFrequency = long(1000 / (flowMax / 19.8319 / 10)); // 19.8319 is ml/hr at 31 Hz **FROM CALIBRATION**
pulseVol = 19.8319 / 360;
}
else { // else pulse duration should be 10 seconds and 3 minute freq
pulseDuration = 10000;
feedFrequency = 180000;
pulseVol = flowMax / 20;
}
// Debug
if (debugMode) {
Serial.print("Flow Hz = ");
Serial.println(pulseFreq);
Serial.print("Pulse Duration = ");
Serial.println(pulseDuration);
}
}
// 1b pulseFeed
void pulseFeed() {
float flowrateInstant = pulseVol * 3600 / (now() - tPulse);
pulseCount += 1;
tone(pinP1FlowWrite, pulseFreq, pulseDuration);
totalVol += pulseVol;
tPulse = now();
if (debugMode){
Serial.print("pulse parameters; pulseCount = ");
Serial.print(pulseCount);
Serial.print(", flowrateInstant = ");
Serial.println(flowrateInstant);
}
SDDataLog('f', pulseCount, flowrateInstant);
}
// 1c addMedia - adds x ml of media
void addMedia(float addMediaMl) {
long addDuration = long(addMediaMl / 0.03723 * 1000); // 0.03723 is the ml/s flow rate at 200 Hz
tone(pinP1FlowWrite, 200, addDuration);
if (tStart) {
totalVol += addMediaMl;
pulseCount += 1;
float flowrateInstant = pulseVol * 3600 / (now() - tPulse);
if (debugMode){
Serial.print("pulse parameters; pulseCount = ");
Serial.print(pulseCount);
Serial.print(", flowrateInstant = ");
Serial.println(flowrateInstant);
}
SDDataLog('f', pulseCount, flowrateInstant);
}
return;
}