-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_iot_blinds.py
More file actions
343 lines (287 loc) · 13.3 KB
/
test_iot_blinds.py
File metadata and controls
343 lines (287 loc) · 13.3 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import unittest
from typing_extensions import override
from edg import *
from .util import run_test_board
class IotRollerBlindsConnector(Block):
def __init__(self) -> None:
super().__init__()
self.gnd = self.Port(Ground(), [Common])
self.pwr = self.Port(VoltageSink.from_gnd(self.gnd, voltage_limits=(4.5, 25) * Volt), [Power])
self.enca = self.Port(DigitalSource.low_from_supply(self.gnd))
self.encb = self.Port(DigitalSource.low_from_supply(self.gnd))
self.motor2 = self.Port(DigitalSink(current_draw=(0, 0.5) * Amp))
self.motor1 = self.Port(DigitalSink(current_draw=(0, 0.5) * Amp))
self.conn = self.Block(JstXh(length=6)).connected(
{
"4": self.gnd,
"1": self.pwr,
"2": self.enca,
"3": self.encb,
"5": self.motor2,
"6": self.motor1,
}
)
class PowerInConnector(Connector):
def __init__(self) -> None:
super().__init__()
self.gnd = self.Port(Ground(), [Common])
self.pwr = self.Port(VoltageSource(voltage_out=(10, 25) * Volt, current_limits=(0, 1) * Amp))
self.conn = self.Block(JstPh()).connected({"1": self.gnd, "2": self.pwr})
class PowerOutConnector(Connector):
def __init__(self) -> None:
super().__init__()
self.gnd = self.Port(Ground())
self.pwr = self.Port(VoltageSink())
self.conn = self.Block(JstPh()).connected({"1": self.gnd, "2": self.pwr})
class IotRollerBlinds(JlcBoardTop):
"""IoT roller blinds driver with up-to-20v input and ESP32-C3
Device has a 6-pin JST XH 2.50 connector, pinned as:
1 (dot) Vdd - UHS41 hall effect ICs, 4.5-24v
2 enc a
3 enc b
4 GND
5 motor 2 - TP25-12v/6000, xiaomiteng
6 motor 1
Motor takes ~12v (stall ~500mA, no-load ~300mA, min start 4v @ 150mA)
"""
@override
def contents(self) -> None:
super().contents()
self.pwr = self.Block(PowerInConnector())
self.pwr_out = self.Block(PowerOutConnector())
self.conn = self.Block(IotRollerBlindsConnector())
self.vin_raw = self.connect(self.pwr.pwr, self.pwr_out.pwr)
self.gnd = self.connect(self.pwr.gnd, self.pwr_out.gnd, self.conn.gnd)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.pwr.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.fuse, self.ferrite, self.tp_vin), _ = self.chain(
self.vin_raw,
self.Block(SeriesPowerFuse(trip_current=(500, 1000) * mAmp)),
self.Block(SeriesPowerFerriteBead()),
self.Block(VoltageTestPoint()),
)
self.vin = self.connect(self.ferrite.pwr_out, self.conn.pwr)
(self.reg_3v3, self.tp_3v3, self.prot_3v3), _ = self.chain(
self.vin,
imp.Block(VoltageRegulator(output_voltage=3.3 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
imp.Block(ProtectionZenerDiode(voltage=(3.45, 3.9) * Volt)),
)
self.v3v3 = self.connect(self.reg_3v3.pwr_out)
# 3V3 DOMAIN
with self.implicit_connect(
ImplicitConnect(self.v3v3, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
self.mcu.with_mixin(IoControllerWifi())
# debugging LEDs
(self.ledr,), _ = self.chain(imp.Block(IndicatorSinkLed(Led.Red)), self.mcu.gpio.request("led"))
(self.vin_sense,), _ = self.chain(
self.vin,
imp.Block(VoltageSenseDivider(full_scale_voltage=2.2 * Volt(tol=0.1), impedance=(1, 10) * kOhm)),
self.mcu.adc.request("vin_sense"),
)
self.connect(self.conn.enca, self.mcu.gpio.request("enca"))
self.connect(self.conn.encb, self.mcu.gpio.request("encb"))
# generic expansion
(
self.qwiic_pull,
self.qwiic,
), _ = self.chain(self.mcu.i2c.request("qwiic"), imp.Block(I2cPullup()), imp.Block(QwiicTarget()))
# 12V DOMAIN
with self.implicit_connect(
ImplicitConnect(self.vin, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.drv = imp.Block(Drv8870(current_trip=500 * mAmp(tol=0.1)))
self.connect(self.drv.vref, self.v3v3)
self.connect(self.mcu.gpio.request("motor1"), self.drv.in1)
self.connect(self.mcu.gpio.request("motor2"), self.drv.in2)
self.connect(self.drv.out1, self.conn.motor2)
self.connect(self.drv.out2, self.conn.motor1)
self._block_diagram_grouping = self.Metadata(
{
"pwr": "pwr, pwr_out, tp_gnd, fuse, tp_vin, reg_3v3, prot_3v3, tp_3v3, vin_sense",
"mcu": "mcu, ledr, als, qwiic, qwiic_pull",
"app": "conn, drv",
}
)
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Esp32c3_Wroom02),
(["reg_3v3"], Tps54202h),
(["drv", "vm_cap1", "cap"], AluminumCapacitor),
],
instance_values=[
(["refdes_prefix"], "B"), # unique refdes for panelization
(
["mcu", "pin_assigns"],
[
"led=_GPIO9_STRAP", # force using the strapping / boot mode pin
"vin_sense=3", # 4 as sent to fabrication before ADC2 removed from model, blue-wire to 3
"motor1=15",
"motor2=14",
"enca=13",
"encb=10",
"qwiic.sda=6",
"qwiic.scl=5",
],
),
(["mcu", "programming"], "uart-auto"),
(["reg_3v3", "power_path", "inductor", "manual_frequency_rating"], Range(0, 9e6)),
(["drv", "isen_res", "res", "footprint_spec"], "Resistor_SMD:R_1206_3216Metric"),
(["drv", "isen_res", "res", "require_basic_part"], False),
(["reg_3v3", "power_path", "in_cap", "cap", "voltage_margin"], 1.0),
# 15uH inductors are more common
(["reg_3v3", "power_path", "inductor", "inductance"], Range.from_tolerance(15e-6, 0.2)),
],
class_refinements=[
(EspProgrammingHeader, EspProgrammingTc2030),
(TestPoint, CompactKeystone5015),
],
class_values=[
(CompactKeystone5015, ["lcsc_part"], "C5199798"),
],
)
class MotorConnector(Block):
def __init__(self) -> None:
super().__init__()
self.motor1 = self.Port(DigitalSink(current_draw=(0, 0.5) * Amp))
self.motor2 = self.Port(DigitalSink(current_draw=(0, 0.5) * Amp))
self.conn = self.Block(Picoblade(length=2)).connected(
{
"1": self.motor1,
"2": self.motor2,
}
)
class IotCurtainCrawler(JlcBoardTop):
"""IoT curtain crawler, drives a motor and has hall sensors integrated on the board, next to the motor.
Motor: LS16PQQ-030 -183.5
~2.7v min starting voltage; 40mA open current, 200mA stall current @ 4.0v, ~500mA @ 10v
Note, motor driver appears to be fed off a booster, a chip labeled B6283y, which may be a SDB628 booster
with a feedback voltage of 0.6v. Feedback resistor divider produces 121.4mV for a 2.000V input, a ~10v target.
Motor is a 2-pin PicoBlade 1.25mm connector, Molex_PicoBlade_53398-0271_1x02-1MP_P1.25mm_Vertical
Hall sensor is SOT-23 type, marked "6201"
"""
@override
def contents(self) -> None:
super().contents()
self.pwr = self.Block(PowerInConnector())
self.pwr_out = self.Block(PowerOutConnector())
self.vin_raw = self.connect(self.pwr.pwr, self.pwr_out.pwr)
self.gnd = self.connect(self.pwr.gnd, self.pwr_out.gnd)
self.tp_gnd = self.Block(GroundTestPoint()).connected(self.pwr.gnd)
# POWER
with self.implicit_connect(
ImplicitConnect(self.gnd, [Common]),
) as imp:
(self.fuse, self.ferrite, self.tp_vin), _ = self.chain(
self.vin_raw,
self.Block(SeriesPowerFuse(trip_current=(300, 600) * mAmp)),
self.Block(SeriesPowerFerriteBead()),
self.Block(VoltageTestPoint()),
)
self.vin = self.connect(self.ferrite.pwr_out)
(self.reg_3v3, self.tp_3v3, self.prot_3v3), _ = self.chain(
self.vin,
imp.Block(VoltageRegulator(output_voltage=3.3 * Volt(tol=0.05))),
self.Block(VoltageTestPoint()),
imp.Block(ProtectionZenerDiode(voltage=(3.45, 3.9) * Volt)),
)
self.v3v3 = self.connect(self.reg_3v3.pwr_out)
# 3V3 DOMAIN
with self.implicit_connect(
ImplicitConnect(self.v3v3, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.mcu = imp.Block(IoController())
self.mcu.with_mixin(IoControllerWifi())
# debugging LEDs
(self.ledr,), _ = self.chain(imp.Block(IndicatorSinkLed(Led.Red)), self.mcu.gpio.request("led"))
(self.vin_sense,), _ = self.chain(
self.vin,
imp.Block(VoltageSenseDivider(full_scale_voltage=2.2 * Volt(tol=0.1), impedance=(1, 10) * kOhm)),
self.mcu.adc.request("vin_sense"),
)
(self.enca,), _ = self.chain(imp.Block(Ah1806()), self.mcu.gpio.request("enca"))
(self.encb,), _ = self.chain(imp.Block(Ah1806()), self.mcu.gpio.request("encb"))
self.i2c = self.mcu.i2c.request("i2c")
(self.i2c_pull, self.i2c_tp), self.i2c_chain = self.chain(
self.i2c, imp.Block(I2cPullup()), imp.Block(I2cTestPoint("i2c"))
)
self.als = imp.Block(Bh1750())
self.connect(self.i2c, self.als.i2c)
(self.sw,), _ = self.chain(imp.Block(DigitalSwitch()), self.mcu.gpio.request("sw"))
# generic expansion
(self.qwiic,), _ = self.chain(self.i2c, imp.Block(QwiicTarget()))
# 12V DOMAIN
with self.implicit_connect(
ImplicitConnect(self.vin, [Power]),
ImplicitConnect(self.gnd, [Common]),
) as imp:
self.motor = self.Block(MotorConnector())
self.drv = imp.Block(Drv8870(current_trip=550 * mAmp(tol=0.1)))
self.connect(self.drv.vref, self.v3v3)
self.connect(self.mcu.gpio.request("motor1"), self.drv.in1)
self.connect(self.mcu.gpio.request("motor2"), self.drv.in2)
self.connect(self.drv.out1, self.motor.motor1)
self.connect(self.drv.out2, self.motor.motor2)
self._block_diagram_grouping = self.Metadata(
{
"pwr": "pwr, pwr_out, fuse, tp_vin, reg_3v3, prot_3v3, vin_sense",
"mcu": "mcu, ledr, i2c_pull, als, qwiic",
"app": "motor, drv, enca, encb",
}
)
@override
def refinements(self) -> Refinements:
return super().refinements() + Refinements(
instance_refinements=[
(["mcu"], Esp32c3_Wroom02),
(["reg_3v3"], Tps54202h),
(["drv", "vm_cap1", "cap"], AluminumCapacitor),
],
instance_values=[
(["refdes_prefix"], "R"), # unique refdes for panelization
(
["mcu", "pin_assigns"],
[
"led=_GPIO9_STRAP", # force using the strapping / boot mode pin
"vin_sense=17", # 4 as sent to fabrication before ADC2 removed from model, blue-wire to 17
"motor1=14",
"motor2=15",
"enca=13",
"encb=10",
"i2c.sda=5",
"i2c.scl=6",
"sw=3",
],
),
(["mcu", "programming"], "uart-auto"),
(["reg_3v3", "power_path", "inductor", "manual_frequency_rating"], Range(0, 9e6)),
(["drv", "isen_res", "res", "footprint_spec"], "Resistor_SMD:R_1206_3216Metric"),
(["drv", "isen_res", "res", "require_basic_part"], False),
(["reg_3v3", "power_path", "in_cap", "cap", "voltage_margin"], 1.0),
# 15uH inductors are more common
(["reg_3v3", "power_path", "inductor", "inductance"], Range.from_tolerance(15e-6, 0.2)),
],
class_refinements=[
(EspProgrammingHeader, EspProgrammingTc2030),
(TestPoint, CompactKeystone5015),
],
class_values=[
(CompactKeystone5015, ["lcsc_part"], "C5199798"),
],
)
class IotRollerBlindsTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(IotRollerBlinds)
class IotCurtainCrawlerTestCase(unittest.TestCase):
def test_design(self) -> None:
run_test_board(IotCurtainCrawler)