-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathOutputs.ino
More file actions
185 lines (156 loc) · 4.64 KB
/
Copy pathOutputs.ino
File metadata and controls
185 lines (156 loc) · 4.64 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Written by Peter Easton
// Released under the MIT license
// Build a reflow oven: https://whizoo.com
// There are 6 outputs on Controleo3:
// Outputs 1 through 5
// - Go to the screw terminals
// - Control n-channel MOSFETs, which switch 4.5V (5V less schottky diode)
// - MOSFET's can handle currents up to 240mA
// - Protected by 240 Ohm resistors, so current is limited to 19mA per output
// - Output 1 = PA15 (Arduino = D5)
// - Output 2 = PB30 (Arduino = not available)
// - Output 3 = PB17 (Arduino = not available)
// - Output 4 = PB09 (Arduino = A2)
// - Output 5 = PB08 (Arduino = A1)
// Output 6
// - Is just a bare pin broken out to the middle of the PCB
// - 3.3V because it is a microcontroller pin
// - No input protection and no MOSFET
// - Can be used as a digital input, if necessary using pinMode(SCK, INPUT) and digitalRead(SCK)
// - Output 6 = PB11 (Arduino = SCK)
//
// On the board (and in the build guide) the outputs are 1 through 6. In software they are 0 through 5.
volatile uint32_t *portAOut, *portAMode, *portBOut, *portBMode;
static boolean outputState[NUMBER_OF_OUTPUTS];
// Initialize the registers controlling the outputs, and turn them off
void initOutputs() {
// Get pointer to the registers
portAOut = portOutputRegister(digitalPinToPort(5));
portAMode = portModeRegister(digitalPinToPort(5));
portBOut = portOutputRegister(digitalPinToPort(A2));
portBMode = portModeRegister(digitalPinToPort(A2));
// Set all I/O modes to outputs
*portAMode |= SETBIT15;
*portBMode |= (SETBIT08 + SETBIT09 + SETBIT11 + SETBIT17 + SETBIT30);
// Set all outputs low (turn off relays)
for (int i=0; i<=NUMBER_OF_OUTPUTS; i++)
setOutput(i, LOW);
}
// Turn an output on or off
void setOutput(uint8_t outputNumber, boolean state) {
// Make sure it is a valid output
if (outputNumber > NUMBER_OF_OUTPUTS) {
SerialUSB.println("setOutput: outputNumber is not in range!");
return;
}
// Save the new state
outputState[outputNumber] = state;
switch (outputNumber) {
case 0:
if (state == LOW)
*portAOut &= CLEARBIT15;
else
*portAOut |= SETBIT15;
break;
case 1:
if (state == LOW)
*portBOut &= CLEARBIT30;
else
*portBOut |= SETBIT30;
break;
case 2:
if (state == LOW)
*portBOut &= CLEARBIT17;
else
*portBOut |= SETBIT17;
break;
case 3:
if (state == LOW)
*portBOut &= CLEARBIT09;
else
*portBOut |= SETBIT09;
break;
case 4:
if (state == LOW)
*portBOut &= CLEARBIT08;
else
*portBOut |= SETBIT08;
break;
case 5:
if (state == LOW)
*portBOut &= CLEARBIT11;
else
*portBOut |= SETBIT11;
break;
}
}
// Get the current state of an output
boolean getOutput(uint8_t outputNumber)
{
// Make sure it is a valid output
if (outputNumber > NUMBER_OF_OUTPUTS) {
SerialUSB.println("getOutput: outputNumber is not in range!");
return false;
}
return outputState[outputNumber];
}
// Turn elements and fans on or off in one go
void setOvenOutputs(boolean elementsOn, boolean convectionFanOn, boolean coolingFanOn)
{
for (uint8_t i=0; i< NUMBER_OF_OUTPUTS; i++) {
switch (prefs.outputType[i]) {
case TYPE_UNUSED:
break;
case TYPE_CONVECTION_FAN:
setOutput(i, convectionFanOn);
break;
case TYPE_COOLING_FAN:
setOutput(i, coolingFanOn);
break;
default:
// This can only be used to turn the elements off
if (!elementsOn)
setOutput(i, LOW);
break;
}
}
}
// Turn the convection fan on or off
void turnConvectionFanOn(boolean on)
{
for (uint8_t i=0; i< NUMBER_OF_OUTPUTS; i++) {
if (prefs.outputType[i] == TYPE_CONVECTION_FAN)
setOutput(i, on);
}
}
// Turn the cooling fan on or off
void turnCoolingFanOn(boolean on)
{
for (uint8_t i=0; i< NUMBER_OF_OUTPUTS; i++) {
if (prefs.outputType[i] == TYPE_COOLING_FAN)
setOutput(i, on);
}
}
// Check to see if outputs are configured. Prevent bake/reflow if not
// At least one element must be a heating element
boolean areOutputsConfigured()
{
uint8_t numberConfigured = 0;
for (uint8_t i=0; i< NUMBER_OF_OUTPUTS; i++) {
if (isHeatingElement(prefs.outputType[i]))
numberConfigured++;
}
if (numberConfigured >=1)
return true;
return false;
}
// See how many outputs are used
uint8_t numOutputsConfigured()
{
uint8_t numberConfigured = 0;
for (uint8_t i=0; i< NUMBER_OF_OUTPUTS; i++) {
if (prefs.outputType[i] != TYPE_UNUSED)
numberConfigured++;
}
return numberConfigured;
}