Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fdf4876a2b | |||
| 0bd91af605 | |||
| 9b206db890 | |||
| 03bc800784 | |||
| 04dc3ce722 | |||
| aa291a1a62 | |||
| 11bd24c4de | |||
| 7da6388650 | |||
| 481bb49ac0 | |||
| ce5b71f2e3 | |||
| c388e1c8cd |
@ -74,7 +74,7 @@
|
||||
"ssh_key": ""
|
||||
},
|
||||
"meta": {
|
||||
"filename": "0004-DenshaBekutoru.kicad_prl",
|
||||
"filename": "0004-DenshaBekutoru_v0.1.kicad_prl",
|
||||
"version": 3
|
||||
},
|
||||
"project": {
|
||||
@ -239,7 +239,7 @@
|
||||
"pinned_symbol_libs": []
|
||||
},
|
||||
"meta": {
|
||||
"filename": "0004-DenshaBekutoru.kicad_pro",
|
||||
"filename": "0004-DenshaBekutoru_v0.1.kicad_pro",
|
||||
"version": 1
|
||||
},
|
||||
"net_settings": {
|
||||
@ -372,7 +372,7 @@
|
||||
},
|
||||
"net_format_name": "Spice Model",
|
||||
"page_layout_descr_file": "",
|
||||
"plot_directory": "/home/tgohle/Desktop/git/ToGo-Lab/0004-DenshaBekutoru/KiCad/0004-DenshaBekutoru/",
|
||||
"plot_directory": "/home/tgohle/Desktop/git/ToGo-Lab/0004-DenshaBekutoru/KiCad/0004-DenshaBekutoru_v0.1/",
|
||||
"spice_current_sheet_as_root": false,
|
||||
"spice_external_command": "spice \"%I\"",
|
||||
"spice_model_current_sheet_as_root": true,
|
||||
|
After Width: | Height: | Size: 210 KiB |
|
After Width: | Height: | Size: 246 KiB |
BIN
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_PCB_v0.2.pdf
Normal file
BIN
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_PCB_v0.2.png
Normal file
|
After Width: | Height: | Size: 164 KiB |
39
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_spice.txt
Normal file
@ -0,0 +1,39 @@
|
||||
*
|
||||
|
||||
.subckt 0004-DenshaBekutoru
|
||||
|
||||
|
||||
.model __D2 D
|
||||
.model __D1 D
|
||||
R3 Net-_D10-A_ VCC 220
|
||||
D10 __D10
|
||||
C5 VCC GND 100n
|
||||
U4 __U4
|
||||
C4 VCC GND 4.7u
|
||||
U3 __U3
|
||||
R4 Net-_D11-A_ VCC 220
|
||||
D11 __D11
|
||||
R5 Net-_U3-_RESET/PB5_ VCC 10k
|
||||
R6 Net-_D4-A_ Net-_D6-K_ 220
|
||||
D6 __D6
|
||||
D5 __D5
|
||||
R7 Net-_D6-A_ Net-_D4-K_ 220
|
||||
D4 __D4
|
||||
C3 Net-_D3-K_ GND 100n
|
||||
U1 __U1
|
||||
C2 Net-_D3-K_ GND 47u
|
||||
D3 __D3
|
||||
U2 __U2
|
||||
D2 Net-_D2-A_ Net-_D2-K_ __D2
|
||||
C1 Net-_U3-_RESET/PB5_ GND 100n
|
||||
SW1 __SW1
|
||||
R8 Net-_D8-A_ Net-_D5-K_ 220
|
||||
D7 __D7
|
||||
D8 __D8
|
||||
D9 __D9
|
||||
R1 Net-_D2-A_ Net-_D1-K_ 1.8k
|
||||
R2 Net-_D1-A_ Net-_D2-K_ 1.8k
|
||||
D1 Net-_D1-A_ Net-_D1-K_ __D1
|
||||
J1 __J1
|
||||
|
||||
.ends
|
||||
37
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_v0.2
Normal file
@ -0,0 +1,37 @@
|
||||
*
|
||||
|
||||
.subckt 0004-DenshaBekutoru_v0.2
|
||||
|
||||
|
||||
.model __D1 D
|
||||
.model __D2 D
|
||||
J6 __J6
|
||||
J5 __J5
|
||||
D10 __D10
|
||||
R3 Net-_A1-Vcc_ Net-_D10-A_ 220
|
||||
R1 Net-_D2-A_ Net-_D1-K_ 1.8k
|
||||
U2 __U2
|
||||
D1 Net-_D1-A_ Net-_D1-K_ __D1
|
||||
U1 __U1
|
||||
C4 Net-_D3-K_ GND 4.7u
|
||||
C5 Net-_D3-K_ GND 100n
|
||||
D3 __D3
|
||||
RV1 __RV1
|
||||
D11 __D11
|
||||
R4 Net-_D11-A_ Net-_A1-Vcc_ 220
|
||||
J8 __J8
|
||||
R9 GND Net-_J8-Pin_1_ 10k
|
||||
R2 Net-_D1-A_ Net-_D2-K_ 1.8k
|
||||
J1 __J1
|
||||
D2 Net-_D2-A_ Net-_D2-K_ __D2
|
||||
A1 __A1
|
||||
R5 Net-_J3-Pin_2_ Net-_A1-PadD9_ 220
|
||||
J7 __J7
|
||||
J3 __J3
|
||||
J2 __J2
|
||||
J4 __J4
|
||||
R6 Net-_J3-Pin_3_ Net-_A1-PadD9_ 220
|
||||
R7 Net-_J3-Pin_4_ Net-_A1-D3_INT1_ 220
|
||||
R8 Net-_J3-Pin_5_ Net-_A1-D3_INT1_ 220
|
||||
|
||||
.ends
|
||||
@ -0,0 +1,32 @@
|
||||
ERC report (2026-01-25T14:36:13+0100, Encoding UTF8)
|
||||
|
||||
***** Sheet /
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(10000.00 mils, 3950.00 mils): Symbol D7 Pin 1 [K, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(10000.00 mils, 3650.00 mils): Symbol D7 Pin 2 [A, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(9500.00 mils, 3950.00 mils): Symbol D6 Pin 1 [K, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(9500.00 mils, 3650.00 mils): Symbol D6 Pin 2 [A, Passive, Line]
|
||||
[power_pin_not_driven]: Input Power pin not driven by any Output Power pins
|
||||
; error (excluded)
|
||||
@(5650.00 mils, 3350.00 mils): Symbol A1 Pin Vcc1 [Vcc, Power input, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(8500.00 mils, 3950.00 mils): Symbol D4 Pin 1 [K, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(8500.00 mils, 3650.00 mils): Symbol D4 Pin 2 [A, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(9000.00 mils, 3950.00 mils): Symbol D5 Pin 1 [K, Passive, Line]
|
||||
[pin_not_connected]: Pin not connected
|
||||
; error (excluded)
|
||||
@(9000.00 mils, 3650.00 mils): Symbol D5 Pin 2 [A, Passive, Line]
|
||||
|
||||
** ERC messages: 9 Errors 9 Warnings 0
|
||||
15642
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_v0.2.kicad_pcb
Normal file
@ -0,0 +1,83 @@
|
||||
{
|
||||
"board": {
|
||||
"active_layer": 37,
|
||||
"active_layer_preset": "All Layers",
|
||||
"auto_track_width": true,
|
||||
"hidden_netclasses": [],
|
||||
"hidden_nets": [],
|
||||
"high_contrast_mode": 0,
|
||||
"net_color_mode": 1,
|
||||
"opacity": {
|
||||
"images": 0.6,
|
||||
"pads": 1.0,
|
||||
"tracks": 1.0,
|
||||
"vias": 1.0,
|
||||
"zones": 0.6
|
||||
},
|
||||
"selection_filter": {
|
||||
"dimensions": true,
|
||||
"footprints": true,
|
||||
"graphics": true,
|
||||
"keepouts": true,
|
||||
"lockedItems": false,
|
||||
"otherItems": true,
|
||||
"pads": true,
|
||||
"text": true,
|
||||
"tracks": true,
|
||||
"vias": true,
|
||||
"zones": true
|
||||
},
|
||||
"visible_items": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25,
|
||||
26,
|
||||
27,
|
||||
28,
|
||||
29,
|
||||
30,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
36,
|
||||
39,
|
||||
40
|
||||
],
|
||||
"visible_layers": "fffffff_ffffffff",
|
||||
"zone_display_mode": 0
|
||||
},
|
||||
"git": {
|
||||
"repo_password": "",
|
||||
"repo_type": "",
|
||||
"repo_username": "",
|
||||
"ssh_key": ""
|
||||
},
|
||||
"meta": {
|
||||
"filename": "0004-DenshaBekutoru_v0.2.kicad_prl",
|
||||
"version": 3
|
||||
},
|
||||
"project": {
|
||||
"files": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,607 @@
|
||||
{
|
||||
"board": {
|
||||
"3dviewports": [],
|
||||
"design_settings": {
|
||||
"defaults": {
|
||||
"apply_defaults_to_fp_fields": false,
|
||||
"apply_defaults_to_fp_shapes": false,
|
||||
"apply_defaults_to_fp_text": false,
|
||||
"board_outline_line_width": 0.05,
|
||||
"copper_line_width": 0.2,
|
||||
"copper_text_italic": false,
|
||||
"copper_text_size_h": 1.5,
|
||||
"copper_text_size_v": 1.5,
|
||||
"copper_text_thickness": 0.3,
|
||||
"copper_text_upright": false,
|
||||
"courtyard_line_width": 0.05,
|
||||
"dimension_precision": 4,
|
||||
"dimension_units": 3,
|
||||
"dimensions": {
|
||||
"arrow_length": 1270000,
|
||||
"extension_offset": 500000,
|
||||
"keep_text_aligned": true,
|
||||
"suppress_zeroes": false,
|
||||
"text_position": 0,
|
||||
"units_format": 1
|
||||
},
|
||||
"fab_line_width": 0.1,
|
||||
"fab_text_italic": false,
|
||||
"fab_text_size_h": 1.0,
|
||||
"fab_text_size_v": 1.0,
|
||||
"fab_text_thickness": 0.15,
|
||||
"fab_text_upright": false,
|
||||
"other_line_width": 0.1,
|
||||
"other_text_italic": false,
|
||||
"other_text_size_h": 1.0,
|
||||
"other_text_size_v": 1.0,
|
||||
"other_text_thickness": 0.15,
|
||||
"other_text_upright": false,
|
||||
"pads": {
|
||||
"drill": 0.762,
|
||||
"height": 1.524,
|
||||
"width": 1.524
|
||||
},
|
||||
"silk_line_width": 0.1,
|
||||
"silk_text_italic": false,
|
||||
"silk_text_size_h": 1.0,
|
||||
"silk_text_size_v": 1.0,
|
||||
"silk_text_thickness": 0.1,
|
||||
"silk_text_upright": false,
|
||||
"zones": {
|
||||
"min_clearance": 0.5
|
||||
}
|
||||
},
|
||||
"diff_pair_dimensions": [
|
||||
{
|
||||
"gap": 0.0,
|
||||
"via_gap": 0.0,
|
||||
"width": 0.0
|
||||
}
|
||||
],
|
||||
"drc_exclusions": [],
|
||||
"meta": {
|
||||
"version": 2
|
||||
},
|
||||
"rule_severities": {
|
||||
"annular_width": "error",
|
||||
"clearance": "error",
|
||||
"connection_width": "warning",
|
||||
"copper_edge_clearance": "error",
|
||||
"copper_sliver": "warning",
|
||||
"courtyards_overlap": "error",
|
||||
"diff_pair_gap_out_of_range": "error",
|
||||
"diff_pair_uncoupled_length_too_long": "error",
|
||||
"drill_out_of_range": "error",
|
||||
"duplicate_footprints": "warning",
|
||||
"extra_footprint": "warning",
|
||||
"footprint": "error",
|
||||
"footprint_symbol_mismatch": "warning",
|
||||
"footprint_type_mismatch": "ignore",
|
||||
"hole_clearance": "error",
|
||||
"hole_near_hole": "error",
|
||||
"holes_co_located": "warning",
|
||||
"invalid_outline": "error",
|
||||
"isolated_copper": "warning",
|
||||
"item_on_disabled_layer": "error",
|
||||
"items_not_allowed": "error",
|
||||
"length_out_of_range": "error",
|
||||
"lib_footprint_issues": "warning",
|
||||
"lib_footprint_mismatch": "warning",
|
||||
"malformed_courtyard": "error",
|
||||
"microvia_drill_out_of_range": "error",
|
||||
"missing_courtyard": "ignore",
|
||||
"missing_footprint": "warning",
|
||||
"net_conflict": "warning",
|
||||
"npth_inside_courtyard": "ignore",
|
||||
"padstack": "warning",
|
||||
"pth_inside_courtyard": "ignore",
|
||||
"shorting_items": "error",
|
||||
"silk_edge_clearance": "warning",
|
||||
"silk_over_copper": "warning",
|
||||
"silk_overlap": "warning",
|
||||
"skew_out_of_range": "error",
|
||||
"solder_mask_bridge": "error",
|
||||
"starved_thermal": "error",
|
||||
"text_height": "warning",
|
||||
"text_thickness": "warning",
|
||||
"through_hole_pad_without_hole": "error",
|
||||
"too_many_vias": "error",
|
||||
"track_dangling": "warning",
|
||||
"track_width": "error",
|
||||
"tracks_crossing": "error",
|
||||
"unconnected_items": "error",
|
||||
"unresolved_variable": "error",
|
||||
"via_dangling": "warning",
|
||||
"zones_intersect": "error"
|
||||
},
|
||||
"rules": {
|
||||
"max_error": 0.005,
|
||||
"min_clearance": 0.0,
|
||||
"min_connection": 0.0,
|
||||
"min_copper_edge_clearance": 0.5,
|
||||
"min_hole_clearance": 0.25,
|
||||
"min_hole_to_hole": 0.25,
|
||||
"min_microvia_diameter": 0.2,
|
||||
"min_microvia_drill": 0.1,
|
||||
"min_resolved_spokes": 2,
|
||||
"min_silk_clearance": 0.0,
|
||||
"min_text_height": 0.8,
|
||||
"min_text_thickness": 0.08,
|
||||
"min_through_hole_diameter": 0.3,
|
||||
"min_track_width": 0.25,
|
||||
"min_via_annular_width": 0.1,
|
||||
"min_via_diameter": 0.5,
|
||||
"solder_mask_to_copper_clearance": 0.0,
|
||||
"use_height_for_length_calcs": true
|
||||
},
|
||||
"teardrop_options": [
|
||||
{
|
||||
"td_onpadsmd": true,
|
||||
"td_onroundshapesonly": false,
|
||||
"td_ontrackend": false,
|
||||
"td_onviapad": true
|
||||
}
|
||||
],
|
||||
"teardrop_parameters": [
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_round_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_rect_shape",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
},
|
||||
{
|
||||
"td_allow_use_two_tracks": true,
|
||||
"td_curve_segcount": 0,
|
||||
"td_height_ratio": 1.0,
|
||||
"td_length_ratio": 0.5,
|
||||
"td_maxheight": 2.0,
|
||||
"td_maxlen": 1.0,
|
||||
"td_on_pad_in_zone": false,
|
||||
"td_target_name": "td_track_end",
|
||||
"td_width_to_size_filter_ratio": 0.9
|
||||
}
|
||||
],
|
||||
"track_widths": [
|
||||
0.0
|
||||
],
|
||||
"tuning_pattern_settings": {
|
||||
"diff_pair_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 1.0
|
||||
},
|
||||
"diff_pair_skew_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 0.6
|
||||
},
|
||||
"single_track_defaults": {
|
||||
"corner_radius_percentage": 80,
|
||||
"corner_style": 1,
|
||||
"max_amplitude": 1.0,
|
||||
"min_amplitude": 0.2,
|
||||
"single_sided": false,
|
||||
"spacing": 0.6
|
||||
}
|
||||
},
|
||||
"via_dimensions": [
|
||||
{
|
||||
"diameter": 0.0,
|
||||
"drill": 0.0
|
||||
}
|
||||
],
|
||||
"zones_allow_external_fillets": false
|
||||
},
|
||||
"ipc2581": {
|
||||
"dist": "",
|
||||
"distpn": "",
|
||||
"internal_id": "",
|
||||
"mfg": "",
|
||||
"mpn": ""
|
||||
},
|
||||
"layer_presets": [],
|
||||
"viewports": []
|
||||
},
|
||||
"boards": [],
|
||||
"cvpcb": {
|
||||
"equivalence_files": []
|
||||
},
|
||||
"erc": {
|
||||
"erc_exclusions": [
|
||||
"pin_not_connected|2159000|1003300|75d7e973-8e06-4017-adef-8a7540fd15a0|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2159000|927100|b8d4dc81-b5c9-4b93-9376-0a9b9fc45175|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2286000|1003300|708ddeaa-1814-44d3-ae53-df03e7136210|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2286000|927100|e0f17062-911b-4fb8-9627-be8ce017775c|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2413000|1003300|c87497e0-f1a5-4cac-8154-452d26879be6|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2413000|927100|8209804a-7539-4743-bfca-aff943649ca9|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2540000|1003300|6d0ce029-b541-49e3-83e1-74431b2de240|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"pin_not_connected|2540000|927100|252bd632-84ad-409c-ab54-696d48f55782|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|",
|
||||
"power_pin_not_driven|1435100|850900|c21116e5-546b-4c55-ac12-ee16de044258|00000000-0000-0000-0000-000000000000|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|/f227a2cd-5cbd-41a5-87f8-a5c1515170aa|"
|
||||
],
|
||||
"meta": {
|
||||
"version": 0
|
||||
},
|
||||
"pin_map": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
0,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
2
|
||||
],
|
||||
[
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2
|
||||
]
|
||||
],
|
||||
"rule_severities": {
|
||||
"bus_definition_conflict": "error",
|
||||
"bus_entry_needed": "error",
|
||||
"bus_to_bus_conflict": "error",
|
||||
"bus_to_net_conflict": "error",
|
||||
"conflicting_netclasses": "error",
|
||||
"different_unit_footprint": "error",
|
||||
"different_unit_net": "error",
|
||||
"duplicate_reference": "error",
|
||||
"duplicate_sheet_names": "error",
|
||||
"endpoint_off_grid": "warning",
|
||||
"extra_units": "error",
|
||||
"global_label_dangling": "warning",
|
||||
"hier_label_mismatch": "error",
|
||||
"label_dangling": "error",
|
||||
"lib_symbol_issues": "warning",
|
||||
"missing_bidi_pin": "warning",
|
||||
"missing_input_pin": "warning",
|
||||
"missing_power_pin": "error",
|
||||
"missing_unit": "warning",
|
||||
"multiple_net_names": "warning",
|
||||
"net_not_bus_member": "warning",
|
||||
"no_connect_connected": "warning",
|
||||
"no_connect_dangling": "warning",
|
||||
"pin_not_connected": "error",
|
||||
"pin_not_driven": "error",
|
||||
"pin_to_pin": "error",
|
||||
"power_pin_not_driven": "error",
|
||||
"similar_labels": "warning",
|
||||
"simulation_model_issue": "ignore",
|
||||
"unannotated": "error",
|
||||
"unit_value_mismatch": "error",
|
||||
"unresolved_variable": "error",
|
||||
"wire_dangling": "error"
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"pinned_footprint_libs": [],
|
||||
"pinned_symbol_libs": []
|
||||
},
|
||||
"meta": {
|
||||
"filename": "0004-DenshaBekutoru_v0.2.kicad_pro",
|
||||
"version": 1
|
||||
},
|
||||
"net_settings": {
|
||||
"classes": [
|
||||
{
|
||||
"bus_width": 12,
|
||||
"clearance": 0.2,
|
||||
"diff_pair_gap": 0.25,
|
||||
"diff_pair_via_gap": 0.25,
|
||||
"diff_pair_width": 0.2,
|
||||
"line_style": 0,
|
||||
"microvia_diameter": 0.3,
|
||||
"microvia_drill": 0.1,
|
||||
"name": "Default",
|
||||
"pcb_color": "rgba(0, 0, 0, 0.000)",
|
||||
"schematic_color": "rgba(0, 0, 0, 0.000)",
|
||||
"track_width": 0.2,
|
||||
"via_diameter": 0.6,
|
||||
"via_drill": 0.3,
|
||||
"wire_width": 6
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"version": 3
|
||||
},
|
||||
"net_colors": null,
|
||||
"netclass_assignments": null,
|
||||
"netclass_patterns": []
|
||||
},
|
||||
"pcbnew": {
|
||||
"last_paths": {
|
||||
"gencad": "",
|
||||
"idf": "",
|
||||
"netlist": "../../../../../../",
|
||||
"plot": "/home/tgohle/Desktop/git/ToGo-Lab/0004-DenshaBekutoru/KiCad/0004-DenshaBekutoru_PCB_v0.2/",
|
||||
"pos_files": "",
|
||||
"specctra_dsn": "",
|
||||
"step": "",
|
||||
"svg": "",
|
||||
"vrml": ""
|
||||
},
|
||||
"page_layout_descr_file": ""
|
||||
},
|
||||
"schematic": {
|
||||
"annotate_start_num": 0,
|
||||
"bom_export_filename": "",
|
||||
"bom_fmt_presets": [],
|
||||
"bom_fmt_settings": {
|
||||
"field_delimiter": ",",
|
||||
"keep_line_breaks": false,
|
||||
"keep_tabs": false,
|
||||
"name": "CSV",
|
||||
"ref_delimiter": ",",
|
||||
"ref_range_delimiter": "",
|
||||
"string_delimiter": "\""
|
||||
},
|
||||
"bom_presets": [],
|
||||
"bom_settings": {
|
||||
"exclude_dnp": false,
|
||||
"fields_ordered": [
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Reference",
|
||||
"name": "Reference",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "Value",
|
||||
"name": "Value",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Datasheet",
|
||||
"name": "Datasheet",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Footprint",
|
||||
"name": "Footprint",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Qty",
|
||||
"name": "${QUANTITY}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": true,
|
||||
"label": "DNP",
|
||||
"name": "${DNP}",
|
||||
"show": true
|
||||
}
|
||||
],
|
||||
"filter_string": "",
|
||||
"group_symbols": true,
|
||||
"name": "Grouped By Value",
|
||||
"sort_asc": true,
|
||||
"sort_field": "Reference"
|
||||
},
|
||||
"connection_grid_size": 50.0,
|
||||
"drawing": {
|
||||
"dashed_lines_dash_length_ratio": 12.0,
|
||||
"dashed_lines_gap_length_ratio": 3.0,
|
||||
"default_line_thickness": 6.0,
|
||||
"default_text_size": 50.0,
|
||||
"field_names": [],
|
||||
"intersheets_ref_own_page": false,
|
||||
"intersheets_ref_prefix": "",
|
||||
"intersheets_ref_short": false,
|
||||
"intersheets_ref_show": false,
|
||||
"intersheets_ref_suffix": "",
|
||||
"junction_size_choice": 3,
|
||||
"label_size_ratio": 0.375,
|
||||
"operating_point_overlay_i_precision": 3,
|
||||
"operating_point_overlay_i_range": "~A",
|
||||
"operating_point_overlay_v_precision": 3,
|
||||
"operating_point_overlay_v_range": "~V",
|
||||
"overbar_offset_ratio": 1.23,
|
||||
"pin_symbol_size": 25.0,
|
||||
"text_offset_ratio": 0.15
|
||||
},
|
||||
"legacy_lib_dir": "",
|
||||
"legacy_lib_list": [],
|
||||
"meta": {
|
||||
"version": 1
|
||||
},
|
||||
"net_format_name": "Spice Model",
|
||||
"page_layout_descr_file": "",
|
||||
"plot_directory": "./",
|
||||
"spice_current_sheet_as_root": false,
|
||||
"spice_external_command": "spice \"%I\"",
|
||||
"spice_model_current_sheet_as_root": true,
|
||||
"spice_save_all_currents": false,
|
||||
"spice_save_all_dissipations": false,
|
||||
"spice_save_all_voltages": false,
|
||||
"subpart_first_id": 65,
|
||||
"subpart_id_separator": 0
|
||||
},
|
||||
"sheets": [
|
||||
[
|
||||
"f227a2cd-5cbd-41a5-87f8-a5c1515170aa",
|
||||
"Root"
|
||||
]
|
||||
],
|
||||
"text_variables": {}
|
||||
}
|
||||
8938
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_v0.2.kicad_sch
Normal file
BIN
KiCad/0004-DenshaBekutoru_v0.2/0004-DenshaBekutoru_v0.2.pdf
Normal file
253
KiCad/0004-DenshaBekutoru_v0.2/fp-info-cache
Normal file
@ -0,0 +1,253 @@
|
||||
61050822101653
|
||||
arduino-library
|
||||
Arduino_101_Shield
|
||||
https://docs.arduino.cc/retired/boards/arduino-101-619
|
||||
|
||||
0
|
||||
38
|
||||
38
|
||||
arduino-library
|
||||
Arduino_Due_Shield
|
||||
https://docs.arduino.cc/hardware/due
|
||||
|
||||
0
|
||||
92
|
||||
91
|
||||
arduino-library
|
||||
Arduino_Giga_R1_WiFi_Shield
|
||||
https://docs.arduino.cc/hardware/giga-r1-wifi
|
||||
|
||||
0
|
||||
92
|
||||
91
|
||||
arduino-library
|
||||
Arduino_Leonardo_Shield
|
||||
https://docs.arduino.cc/hardware/leonardo
|
||||
|
||||
0
|
||||
38
|
||||
37
|
||||
arduino-library
|
||||
Arduino_M0_Pro_Shield
|
||||
https://docs.arduino.cc/retired/boards/arduino-m0-pro
|
||||
|
||||
0
|
||||
38
|
||||
37
|
||||
arduino-library
|
||||
Arduino_MKR_1000_WiFi_Socket
|
||||
https://docs.arduino.cc/hardware/mkr-1000-wifi
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_MKR_FOX_1200_Socket
|
||||
https://docs.arduino.cc/hardware/mkr-fox-1200
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_MKR_Vidor_4000_Socket
|
||||
https://docs.arduino.cc/hardware/mkr-vidor-4000
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_MKR_WiFi_1010_Socket
|
||||
https://docs.arduino.cc/hardware/mkr-wifi-1010
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_MKR_Zero_Socket
|
||||
https://docs.arduino.cc/hardware/mkr-zero
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_Mega2560_R3_Shield
|
||||
https://docs.arduino.cc/hardware/mega-2560
|
||||
|
||||
0
|
||||
92
|
||||
91
|
||||
arduino-library
|
||||
Arduino_Micro_Socket
|
||||
https://docs.arduino.cc/hardware/micro
|
||||
|
||||
0
|
||||
34
|
||||
32
|
||||
arduino-library
|
||||
Arduino_Mini_Socket
|
||||
https://docs.arduino.cc/retired/boards/arduino-mini-05
|
||||
|
||||
0
|
||||
35
|
||||
35
|
||||
arduino-library
|
||||
Arduino_Mini_Socket_NoSPH
|
||||
https://docs.arduino.cc/retired/boards/arduino-mini-05
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_33_IoT_Socket
|
||||
https://docs.arduino.cc/hardware/nano-33-iot
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_33_IoT_Tile
|
||||
https://docs.arduino.cc/hardware/nano-33-iot
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_ESP32_Socket
|
||||
https://docs.arduino.cc/hardware/nano-esp32
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_ESP32_Tile
|
||||
https://docs.arduino.cc/hardware/nano-esp32
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_Every_Socket
|
||||
https://docs.arduino.cc/hardware/nano-every
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_Every_Tile
|
||||
https://docs.arduino.cc/hardware/nano-every
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nano_Socket
|
||||
https://docs.arduino.cc/hardware/nano
|
||||
|
||||
0
|
||||
30
|
||||
30
|
||||
arduino-library
|
||||
Arduino_Nicla_Vision_Socket
|
||||
https://docs.arduino.cc/hardware/nicla-vision
|
||||
|
||||
0
|
||||
19
|
||||
18
|
||||
arduino-library
|
||||
Arduino_Nicla_Vision_Tile
|
||||
https://docs.arduino.cc/hardware/nicla-vision
|
||||
|
||||
0
|
||||
19
|
||||
18
|
||||
arduino-library
|
||||
Arduino_Nicla_Voice_Socket
|
||||
https://docs.arduino.cc/hardware/nicla-voice
|
||||
|
||||
0
|
||||
19
|
||||
17
|
||||
arduino-library
|
||||
Arduino_Nicla_Voice_Tile
|
||||
https://docs.arduino.cc/hardware/nicla-voice
|
||||
|
||||
0
|
||||
19
|
||||
17
|
||||
arduino-library
|
||||
Arduino_Pro_Mini_Socket
|
||||
https://docs.arduino.cc/retired/boards/arduino-pro-mini
|
||||
|
||||
0
|
||||
34
|
||||
34
|
||||
arduino-library
|
||||
Arduino_Pro_Mini_Socket_NoSPH
|
||||
https://docs.arduino.cc/retired/boards/arduino-pro-mini
|
||||
|
||||
0
|
||||
28
|
||||
28
|
||||
arduino-library
|
||||
Arduino_Pro_Mini_Socket_NoSPH_V2
|
||||
https://docs.arduino.cc/retired/boards/arduino-pro-mini
|
||||
|
||||
0
|
||||
29
|
||||
29
|
||||
arduino-library
|
||||
Arduino_Uno_R2_Shield
|
||||
https://startingelectronics.org/articles/arduino/uno-r3-r2-differences/
|
||||
|
||||
0
|
||||
34
|
||||
34
|
||||
arduino-library
|
||||
Arduino_Uno_R3_Shield
|
||||
https://docs.arduino.cc/hardware/uno-rev3
|
||||
|
||||
0
|
||||
38
|
||||
37
|
||||
arduino-library
|
||||
Arduino_Uno_R4_Minima_Shield
|
||||
https://docs.arduino.cc/hardware/uno-r4-minima
|
||||
|
||||
0
|
||||
38
|
||||
38
|
||||
arduino-library
|
||||
Arduino_Uno_R4_WiFi_Shield
|
||||
https://docs.arduino.cc/hardware/uno-r4-wifi
|
||||
|
||||
0
|
||||
47
|
||||
46
|
||||
arduino-library
|
||||
Arduino_Zero_Shield
|
||||
https://docs.arduino.cc/hardware/zero
|
||||
|
||||
0
|
||||
38
|
||||
38
|
||||
arduino-library
|
||||
Clone_Mega2560_Pro_Socket
|
||||
https://docs.arduino.cc/hardware/mega-2560
|
||||
|
||||
0
|
||||
86
|
||||
86
|
||||
arduino-library
|
||||
Clone_Pro_Mini_Socket
|
||||
https://www.addicore.com/Pro-Mini-p/ad249.htm
|
||||
|
||||
0
|
||||
35
|
||||
35
|
||||
arduino-library
|
||||
Clone_Pro_Mini_Socket_NoSPH
|
||||
https://www.addicore.com/Pro-Mini-p/ad249.htm
|
||||
|
||||
0
|
||||
29
|
||||
29
|
||||
31
KiCad/0004-DenshaBekutoru_v0.2/report.txt
Normal file
@ -0,0 +1,31 @@
|
||||
Info: Processing symbol 'J7:Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_Vertical'.
|
||||
Info: Processing symbol 'U2:Package_DIP:DIP-4_W7.62mm'.
|
||||
Info: Processing symbol 'U1:Package_DIP:DIP-4_W7.62mm'.
|
||||
Info: Processing symbol 'RV1:Potentiometer_THT:Potentiometer_Piher_PT-10-V10_Vertical'.
|
||||
Info: Processing symbol 'R9:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P1.90mm_Vertical'.
|
||||
Info: Processing symbol 'R8:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P1.90mm_Vertical'.
|
||||
Info: Processing symbol 'R7:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P1.90mm_Vertical'.
|
||||
Info: Processing symbol 'R6:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P1.90mm_Vertical'.
|
||||
Info: Processing symbol 'R5:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P1.90mm_Vertical'.
|
||||
Info: Processing symbol 'R4:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P5.08mm_Horizontal'.
|
||||
Info: Processing symbol 'R3:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P5.08mm_Horizontal'.
|
||||
Info: Processing symbol 'R2:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P5.08mm_Horizontal'.
|
||||
Info: Processing symbol 'R1:Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P5.08mm_Horizontal'.
|
||||
Info: Processing symbol 'J8:Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical'.
|
||||
Info: Processing symbol 'A1:arduino-library:Arduino_Pro_Mini_Socket_NoSPH_V2'.
|
||||
Info: Processing symbol 'J6:Connector_JST:JST_PH_B3B-PH-K_1x03_P2.00mm_Vertical'.
|
||||
Info: Processing symbol 'J5:Connector_JST:JST_PH_B3B-PH-K_1x03_P2.00mm_Vertical'.
|
||||
Info: Processing symbol 'J4:Connector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_Vertical'.
|
||||
Info: Processing symbol 'J3:Connector_PinSocket_2.54mm:PinSocket_1x05_P2.54mm_Horizontal'.
|
||||
Info: Processing symbol 'J2:Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_Vertical'.
|
||||
Info: Processing symbol 'J1:Connector_PinHeader_2.54mm:PinHeader_1x04_P2.54mm_Horizontal'.
|
||||
Info: Processing symbol 'D5:LED_THT:LED_D1.8mm_W3.3mm_H2.4mm'.
|
||||
Info: Processing symbol 'D4:LED_THT:LED_D1.8mm_W3.3mm_H2.4mm'.
|
||||
Info: Processing symbol 'D3:Diode_THT:D_DO-41_SOD81_P10.16mm_Horizontal'.
|
||||
Info: Processing symbol 'D2:Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal'.
|
||||
Info: Processing symbol 'D1:Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal'.
|
||||
Info: Processing symbol 'C5:Capacitor_THT:C_Disc_D3.0mm_W1.6mm_P2.50mm'.
|
||||
Info: Processing symbol 'C4:Capacitor_THT:CP_Axial_L10.0mm_D6.0mm_P15.00mm_Horizontal'.
|
||||
|
||||
|
||||
Info: Total warnings: 0, errors: 0.
|
||||
BIN
StripBoard/0004-DenshaBekutoru_SB_BW_View.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
StripBoard/0004-DenshaBekutoru_SB_Overview.jpg
Normal file
|
After Width: | Height: | Size: 162 KiB |
|
Before Width: | Height: | Size: 162 KiB |
|
Before Width: | Height: | Size: 70 KiB |
217
firmware/ArduinoTest/Def_InOut_PrepLogic/Def_InOut_PrepLogic.ino
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
0004_DenshaBekutoru – Optocoupler Averaging Test
|
||||
Target dev board (later): Arduino Pro Mini 5V / 16 MHz (ATmega328P)
|
||||
|
||||
Measures average voltage on:
|
||||
- A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
- A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
Boot calibration:
|
||||
- assumes "no movement" at startup
|
||||
- measures V1/V2 AverageRepeat times
|
||||
- computes di = |V1 - V2| each time
|
||||
- VdiffBaseline = median(di)
|
||||
- VdiffThreshold = max(VdiffBaseline * VdiffThresholdMargin, VdiffThresholdMinVolts)
|
||||
*/
|
||||
|
||||
const unsigned long SAMPLE_WINDOW_MS = 100; // averaging window per measurement
|
||||
const unsigned long SAMPLE_DELAY_US = 500; // delay between ADC samples (~2 kHz)
|
||||
|
||||
const uint8_t ADC_PIN_1 = A2; // Pro Mini A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
const uint8_t ADC_PIN_2 = A3; // Pro Mini A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
// LEDs for direction indication (avoid D0/D1)
|
||||
const uint8_t LED_DIR1_PIN = 2; // D2
|
||||
const uint8_t LED_DIR2_PIN = 3; // D3
|
||||
|
||||
// Serial output control (0 = no output, 1 = output)
|
||||
bool SerialOutputAllow = true;
|
||||
|
||||
// ---- Calibration parameters ----
|
||||
const uint16_t AverageRepeat = 100; // number of init measurements
|
||||
const float VdiffThresholdMargin = 1.50f; // multiplier (e.g., 1.5 = +50% margin)
|
||||
const float VdiffThresholdMinVolts = 0.03f; // floor in volts (optional but practical)
|
||||
|
||||
// Globals: latest measured averaged voltages
|
||||
float v1 = 0.0f;
|
||||
float v2 = 0.0f;
|
||||
|
||||
// Calibration globals
|
||||
float VdiffBaseline = 0.0f; // median(|V1-V2|) measured at boot (no movement)
|
||||
float VdiffThreshold = 0.0f; // final threshold used for direction decision
|
||||
|
||||
// Direction encoding requirement:
|
||||
// 0 = no direction
|
||||
// 2 = direction 1 (maps to LED pin D2)
|
||||
// 3 = direction 2 (maps to LED pin D3)
|
||||
byte direction = 0;
|
||||
|
||||
static inline float absf(float x) { return (x >= 0.0f) ? x : -x; }
|
||||
static inline float maxf(float a, float b) { return (a > b) ? a : b; }
|
||||
|
||||
static void applyDirectionOutputs()
|
||||
{
|
||||
digitalWrite(LED_DIR1_PIN, LOW);
|
||||
digitalWrite(LED_DIR2_PIN, LOW);
|
||||
|
||||
if (direction == LED_DIR1_PIN) {
|
||||
digitalWrite(LED_DIR1_PIN, HIGH);
|
||||
} else if (direction == LED_DIR2_PIN) {
|
||||
digitalWrite(LED_DIR2_PIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// Measure averaged voltages (updates globals v1/v2)
|
||||
static void measureAveragedVoltages()
|
||||
{
|
||||
unsigned long startTime = millis();
|
||||
|
||||
unsigned long sum1 = 0;
|
||||
unsigned long sum2 = 0;
|
||||
unsigned long samples = 0;
|
||||
|
||||
while (millis() - startTime < SAMPLE_WINDOW_MS) {
|
||||
sum1 += analogRead(ADC_PIN_1);
|
||||
sum2 += analogRead(ADC_PIN_2);
|
||||
samples++;
|
||||
delayMicroseconds(SAMPLE_DELAY_US);
|
||||
}
|
||||
|
||||
float avg1 = (float)sum1 / samples;
|
||||
float avg2 = (float)sum2 / samples;
|
||||
|
||||
// Convert ADC value to voltage (default analog reference = Vcc ~ 5V)
|
||||
v1 = avg1 * (5.0f / 1023.0f);
|
||||
v2 = avg2 * (5.0f / 1023.0f);
|
||||
}
|
||||
|
||||
static void sortFloatArray(float *a, uint16_t n)
|
||||
{
|
||||
// Insertion sort (n=100 is small, OK)
|
||||
for (uint16_t i = 1; i < n; i++) {
|
||||
float key = a[i];
|
||||
int16_t j = (int16_t)i - 1;
|
||||
while (j >= 0 && a[j] > key) {
|
||||
a[j + 1] = a[j];
|
||||
j--;
|
||||
}
|
||||
a[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
static float medianOfSortedFloatArray(const float *a, uint16_t n)
|
||||
{
|
||||
if (n == 0) return 0.0f;
|
||||
if (n & 1) {
|
||||
return a[n / 2];
|
||||
} else {
|
||||
return (a[(n / 2) - 1] + a[n / 2]) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
// Calibrate baseline + threshold once at boot/reset
|
||||
// Parameter must be only AverageRepeat (per your requirement).
|
||||
static void calibrateVdiffThreshold(uint16_t averageRepeat)
|
||||
{
|
||||
if (averageRepeat < 1) averageRepeat = 1;
|
||||
if (averageRepeat > 200) averageRepeat = 200; // RAM safety cap
|
||||
|
||||
float diffs[200];
|
||||
|
||||
for (uint16_t i = 0; i < averageRepeat; i++) {
|
||||
measureAveragedVoltages();
|
||||
diffs[i] = absf(v1 - v2); // baseline mismatch sample
|
||||
}
|
||||
|
||||
sortFloatArray(diffs, averageRepeat);
|
||||
VdiffBaseline = medianOfSortedFloatArray(diffs, averageRepeat);
|
||||
|
||||
// Final threshold with margin + floor
|
||||
VdiffThreshold = maxf(VdiffBaseline * VdiffThresholdMargin, VdiffThresholdMinVolts);
|
||||
}
|
||||
|
||||
static void updateDirectionFromVoltages()
|
||||
{
|
||||
float diff = v1 - v2;
|
||||
float absDiff = absf(diff);
|
||||
|
||||
if (absDiff <= VdiffThreshold) {
|
||||
direction = 0;
|
||||
} else {
|
||||
// Mapping choice:
|
||||
// v1 lower than v2 -> direction 1 (D2)
|
||||
// v2 lower than v1 -> direction 2 (D3)
|
||||
direction = (diff < 0.0f) ? LED_DIR1_PIN : LED_DIR2_PIN;
|
||||
}
|
||||
}
|
||||
|
||||
static void serialPrintAll()
|
||||
{
|
||||
if (!SerialOutputAllow) return;
|
||||
|
||||
Serial.print("A2 for PB3 XTAL1, Pin2: ");
|
||||
Serial.print(v1, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("A3 for PB4 XTAL2, Pin3: ");
|
||||
Serial.print(v2, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("|V1-V2|: ");
|
||||
Serial.print(absf(v1 - v2), 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffBaseline: ");
|
||||
Serial.print(VdiffBaseline, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThresholdMargin: ");
|
||||
Serial.print(VdiffThresholdMargin, 2);
|
||||
Serial.print(" x | ");
|
||||
|
||||
Serial.print("VdiffThresholdMinVolts: ");
|
||||
Serial.print(VdiffThresholdMinVolts, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThreshold: ");
|
||||
Serial.print(VdiffThreshold, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("direction: ");
|
||||
Serial.println(direction);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(ADC_PIN_1, INPUT);
|
||||
pinMode(ADC_PIN_2, INPUT);
|
||||
|
||||
pinMode(LED_DIR1_PIN, OUTPUT);
|
||||
pinMode(LED_DIR2_PIN, OUTPUT);
|
||||
|
||||
calibrateVdiffThreshold(AverageRepeat);
|
||||
|
||||
// One measurement for initial output + outputs
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
if (SerialOutputAllow) {
|
||||
Serial.println("=== DenshaBekutoru Optocoupler Average Test (Arduino Pro Mini 5V/16MHz) ===");
|
||||
Serial.print("AverageRepeat: ");
|
||||
Serial.println(AverageRepeat);
|
||||
}
|
||||
|
||||
serialPrintAll();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
serialPrintAll();
|
||||
|
||||
delay(300);
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
0004_DenshaBekutoru ? Optocoupler Averaging Test (UNO)
|
||||
|
||||
Measures average voltage on:
|
||||
- A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
- A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
Integration window is configurable via SAMPLE_WINDOW_MS.
|
||||
|
||||
by tgohle, last edit 20260111
|
||||
|
||||
*/
|
||||
|
||||
const unsigned long SAMPLE_WINDOW_MS = 100; // change here
|
||||
const unsigned long SAMPLE_DELAY_US = 500; // delay between ADC samples
|
||||
|
||||
const uint8_t ADC_PIN_1 = A2; // UNO A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
const uint8_t ADC_PIN_2 = A3; // UNO A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(ADC_PIN_1, INPUT);
|
||||
pinMode(ADC_PIN_2, INPUT);
|
||||
|
||||
Serial.println("=== DenshaBekutoru Optocoupler Average Test ===");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
unsigned long startTime = millis();
|
||||
|
||||
unsigned long sum1 = 0;
|
||||
unsigned long sum2 = 0;
|
||||
unsigned long samples = 0;
|
||||
|
||||
while (millis() - startTime < SAMPLE_WINDOW_MS) {
|
||||
sum1 += analogRead(ADC_PIN_1);
|
||||
sum2 += analogRead(ADC_PIN_2);
|
||||
samples++;
|
||||
delayMicroseconds(SAMPLE_DELAY_US);
|
||||
}
|
||||
|
||||
float avg1 = (float)sum1 / samples;
|
||||
float avg2 = (float)sum2 / samples;
|
||||
|
||||
float v1 = avg1 * (5.0 / 1023.0);
|
||||
float v2 = avg2 * (5.0 / 1023.0);
|
||||
|
||||
Serial.print("A2 for PB3 XTAL1, Pin2: ");
|
||||
Serial.print(v1, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("A3 for PB4 XTAL2, Pin3: ");
|
||||
Serial.print(v2, 3);
|
||||
Serial.println(" V");
|
||||
|
||||
delay(300);
|
||||
}
|
||||
@ -0,0 +1,292 @@
|
||||
/*
|
||||
0004_DenshaBekutoru – Version 0.1 Test
|
||||
Target dev board (later): Arduino Pro Mini 5V / 16 MHz (ATmega328P)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
State machine (direction memory)
|
||||
----------------------------------------------------------------------------
|
||||
Inputs derived from v1, v2, VdiffThreshold:
|
||||
|
||||
N (Neutral): |v1 - v2| <= VdiffThreshold
|
||||
D1 (v1>>v2): (v1 - v2) > VdiffThreshold
|
||||
D2 (v2>>v1): (v2 - v1) > VdiffThreshold
|
||||
|
||||
State encoding:
|
||||
0 = NONE
|
||||
2 = DIR1
|
||||
3 = DIR2
|
||||
|
||||
Transition table:
|
||||
|
||||
Current \ Input | N (neutral) | D1 (v1>>v2) | D2 (v2>>v1)
|
||||
-----------------------------------------------------------------
|
||||
0 (NONE) | 0 | 2 | 3
|
||||
2 (DIR1) | 2 | 2 | 3
|
||||
3 (DIR2) | 3 | 2 | 3
|
||||
|
||||
Mermaid (documentation)
|
||||
-----------------------
|
||||
stateDiagram-v2
|
||||
[*] --> NONE
|
||||
state "0 : NONE" as NONE
|
||||
state "2 : DIR1 (v1>>v2)" as DIR1
|
||||
state "3 : DIR2 (v2>>v1)" as DIR2
|
||||
|
||||
NONE --> NONE : |v1 - v2| <= T
|
||||
NONE --> DIR1 : v1 - v2 > T
|
||||
NONE --> DIR2 : v2 - v1 > T
|
||||
|
||||
DIR1 --> DIR1 : |v1 - v2| <= T
|
||||
DIR1 --> DIR1 : v1 - v2 > T
|
||||
DIR1 --> DIR2 : v2 - v1 > T
|
||||
|
||||
DIR2 --> DIR2 : |v1 - v2| <= T
|
||||
DIR2 --> DIR2 : v2 - v1 > T
|
||||
DIR2 --> DIR1 : v1 - v2 > T
|
||||
*/
|
||||
|
||||
const unsigned long SAMPLE_WINDOW_MS = 100; // averaging window per measurement
|
||||
const unsigned long SAMPLE_DELAY_US = 500; // delay between ADC samples (~2 kHz)
|
||||
|
||||
const uint8_t ADC_PIN_1 = A2; // Pro Mini A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
const uint8_t ADC_PIN_2 = A3; // Pro Mini A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
// Direction LEDs (avoid D0/D1 because you may want RX/TX later)
|
||||
const uint8_t LED_DIR1_PIN = 2; // D2
|
||||
const uint8_t LED_DIR2_PIN = 3; // D3
|
||||
|
||||
const unsigned int LED_BLINK_ON_MS = 150;
|
||||
const unsigned int LED_BLINK_OFF_MS = 150;
|
||||
|
||||
// Serial output control (0 = no output, 1 = output)
|
||||
bool SerialOutputAllow = true;
|
||||
|
||||
// ---- Calibration parameters ----
|
||||
const uint16_t AverageRepeat = 100; // number of init measurements
|
||||
const float VdiffThresholdMargin = 1.50f; // multiplier (e.g., 1.5 = +50% margin)
|
||||
const float VdiffThresholdMinVolts = 0.03f; // floor in volts
|
||||
|
||||
// Globals: latest measured averaged voltages
|
||||
float v1 = 0.0f;
|
||||
float v2 = 0.0f;
|
||||
|
||||
// Calibration globals
|
||||
float VdiffBaseline = 0.0f; // median(|V1-V2|) measured at boot (no movement)
|
||||
float VdiffThreshold = 0.0f; // final threshold used for direction decision
|
||||
|
||||
// Direction encoding:
|
||||
// 0 = NONE, 2 = DIR1, 3 = DIR2
|
||||
byte direction = 0;
|
||||
|
||||
static inline float absf(float x) { return (x >= 0.0f) ? x : -x; }
|
||||
static inline float maxf(float a, float b) { return (a > b) ? a : b; }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// LED helpers
|
||||
// -----------------------------------------------------------------------------
|
||||
static void blinkLED(uint8_t pin, uint8_t times)
|
||||
{
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(pin, HIGH);
|
||||
delay(LED_BLINK_ON_MS);
|
||||
digitalWrite(pin, LOW);
|
||||
delay(LED_BLINK_OFF_MS);
|
||||
}
|
||||
}
|
||||
|
||||
static void initBlinkSequence()
|
||||
{
|
||||
// LED at Output 2 blinks 2 times
|
||||
blinkLED(LED_DIR1_PIN, 2);
|
||||
|
||||
// LED at Output 3 blinks 3 times
|
||||
blinkLED(LED_DIR2_PIN, 3);
|
||||
}
|
||||
|
||||
static void applyDirectionOutputs()
|
||||
{
|
||||
digitalWrite(LED_DIR1_PIN, LOW);
|
||||
digitalWrite(LED_DIR2_PIN, LOW);
|
||||
|
||||
if (direction == 2) {
|
||||
digitalWrite(LED_DIR1_PIN, HIGH);
|
||||
} else if (direction == 3) {
|
||||
digitalWrite(LED_DIR2_PIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Measurement
|
||||
// -----------------------------------------------------------------------------
|
||||
static void measureAveragedVoltages()
|
||||
{
|
||||
unsigned long startTime = millis();
|
||||
|
||||
unsigned long sum1 = 0;
|
||||
unsigned long sum2 = 0;
|
||||
unsigned long samples = 0;
|
||||
|
||||
while (millis() - startTime < SAMPLE_WINDOW_MS) {
|
||||
sum1 += analogRead(ADC_PIN_1);
|
||||
sum2 += analogRead(ADC_PIN_2);
|
||||
samples++;
|
||||
delayMicroseconds(SAMPLE_DELAY_US);
|
||||
}
|
||||
|
||||
float avg1 = (float)sum1 / samples;
|
||||
float avg2 = (float)sum2 / samples;
|
||||
|
||||
// Convert ADC value to voltage (default analog reference = Vcc ~ 5V)
|
||||
v1 = avg1 * (5.0f / 1023.0f);
|
||||
v2 = avg2 * (5.0f / 1023.0f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Median helpers (for calibration)
|
||||
// -----------------------------------------------------------------------------
|
||||
static void sortFloatArray(float *a, uint16_t n)
|
||||
{
|
||||
// Insertion sort (n=100 is small, OK)
|
||||
for (uint16_t i = 1; i < n; i++) {
|
||||
float key = a[i];
|
||||
int16_t j = (int16_t)i - 1;
|
||||
while (j >= 0 && a[j] > key) {
|
||||
a[j + 1] = a[j];
|
||||
j--;
|
||||
}
|
||||
a[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
static float medianOfSortedFloatArray(const float *a, uint16_t n)
|
||||
{
|
||||
if (n == 0) return 0.0f;
|
||||
if (n & 1) {
|
||||
return a[n / 2];
|
||||
} else {
|
||||
return (a[(n / 2) - 1] + a[n / 2]) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
// Calibrate baseline + threshold once at boot/reset
|
||||
// Parameter must be only AverageRepeat.
|
||||
static void calibrateVdiffThreshold(uint16_t averageRepeat)
|
||||
{
|
||||
if (averageRepeat < 1) averageRepeat = 1;
|
||||
if (averageRepeat > 200) averageRepeat = 200; // RAM safety cap
|
||||
|
||||
float diffs[200];
|
||||
|
||||
for (uint16_t i = 0; i < averageRepeat; i++) {
|
||||
measureAveragedVoltages();
|
||||
diffs[i] = absf(v1 - v2); // baseline mismatch sample
|
||||
}
|
||||
|
||||
sortFloatArray(diffs, averageRepeat);
|
||||
VdiffBaseline = medianOfSortedFloatArray(diffs, averageRepeat);
|
||||
|
||||
// Final threshold with margin + floor
|
||||
VdiffThreshold = maxf(VdiffBaseline * VdiffThresholdMargin, VdiffThresholdMinVolts);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// State machine
|
||||
// -----------------------------------------------------------------------------
|
||||
static void updateDirectionFromVoltages()
|
||||
{
|
||||
const float diff = v1 - v2;
|
||||
const float absDiff = absf(diff);
|
||||
|
||||
// Neutral region: hold direction
|
||||
if (absDiff <= VdiffThreshold) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear dominance: set direction deterministically
|
||||
// diff > 0 => v1 >> v2 => DIR1 (2)
|
||||
// diff < 0 => v2 >> v1 => DIR2 (3)
|
||||
direction = (diff > 0.0f) ? (byte)2 : (byte)3;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Serial output
|
||||
// -----------------------------------------------------------------------------
|
||||
static void serialPrintAll()
|
||||
{
|
||||
if (!SerialOutputAllow) return;
|
||||
|
||||
Serial.print("A2 for PB3 XTAL1, Pin2: ");
|
||||
Serial.print(v1, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("A3 for PB4 XTAL2, Pin3: ");
|
||||
Serial.print(v2, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("|V1-V2|: ");
|
||||
Serial.print(absf(v1 - v2), 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffBaseline: ");
|
||||
Serial.print(VdiffBaseline, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThresholdMargin: ");
|
||||
Serial.print(VdiffThresholdMargin, 2);
|
||||
Serial.print(" x | ");
|
||||
|
||||
Serial.print("VdiffThresholdMinVolts: ");
|
||||
Serial.print(VdiffThresholdMinVolts, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThreshold: ");
|
||||
Serial.print(VdiffThreshold, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("direction: ");
|
||||
Serial.println(direction);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Arduino entry points
|
||||
// -----------------------------------------------------------------------------
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(ADC_PIN_1, INPUT);
|
||||
pinMode(ADC_PIN_2, INPUT);
|
||||
|
||||
pinMode(LED_DIR1_PIN, OUTPUT);
|
||||
pinMode(LED_DIR2_PIN, OUTPUT);
|
||||
|
||||
// Initial calibration (assumes no movement)
|
||||
calibrateVdiffThreshold(AverageRepeat);
|
||||
|
||||
// Init blink sequence: 2x on D2, 3x on D3
|
||||
initBlinkSequence();
|
||||
|
||||
// One measurement for initial display + initial direction
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
if (SerialOutputAllow) {
|
||||
Serial.println("=== DenshaBekutoru 0004 – Version 0.1 Test (Arduino Uno Test) ===");
|
||||
Serial.println(" ~~~ InitStart ~~~");
|
||||
Serial.print(" AverageRepeat: ");
|
||||
Serial.println(AverageRepeat);
|
||||
Serial.println(" ~~~ InitEnd ~~~");
|
||||
}
|
||||
|
||||
serialPrintAll();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
serialPrintAll();
|
||||
|
||||
delay(300);
|
||||
}
|
||||
@ -0,0 +1,286 @@
|
||||
/*
|
||||
0004_DenshaBekutoru – 1st working Example
|
||||
Target dev board: Arduino Pro Mini 5V / 16 MHz (ATmega328P)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
State machine (direction memory) + Hysteresis (Version A)
|
||||
----------------------------------------------------------------------------
|
||||
We use two thresholds:
|
||||
T_hold (smaller): below -> treat as neutral and HOLD state
|
||||
T_enter (larger): above -> allow direction change (set by sign)
|
||||
|
||||
Behavior:
|
||||
If |diff| <= T_hold : hold direction
|
||||
If |diff| >= T_enter: set direction by sign
|
||||
Else (between) : hold direction
|
||||
|
||||
Presets (implemented as multipliers of the calibrated VdiffThreshold):
|
||||
T_hold = 1.0 * VdiffThreshold
|
||||
T_enter = 2.0 * VdiffThreshold
|
||||
|
||||
Inputs derived from v1, v2:
|
||||
diff = v1 - v2
|
||||
*/
|
||||
|
||||
const unsigned long SAMPLE_WINDOW_MS = 100; // averaging window per measurement
|
||||
const unsigned long SAMPLE_DELAY_US = 500; // delay between ADC samples (~2 kHz)
|
||||
|
||||
const uint8_t ADC_PIN_1 = A2; // Pro Mini A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
const uint8_t ADC_PIN_2 = A3; // Pro Mini A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
// Direction LEDs (avoid D0/D1 because you may want RX/TX later)
|
||||
const uint8_t LED_DIR1_PIN = 2; // D2
|
||||
const uint8_t LED_DIR2_PIN = 3; // D3
|
||||
|
||||
const unsigned int LED_BLINK_ON_MS = 150;
|
||||
const unsigned int LED_BLINK_OFF_MS = 150;
|
||||
|
||||
// Serial output control (0 = no output, 1 = output)
|
||||
bool SerialOutputAllow = true;
|
||||
|
||||
// ---- Calibration parameters ----
|
||||
const uint16_t AverageRepeat = 100; // number of init measurements
|
||||
const float VdiffThresholdMargin = 1.50f; // multiplier (e.g., 1.5 = +50% margin)
|
||||
const float VdiffThresholdMinVolts = 0.03f; // floor in volts
|
||||
|
||||
// ---- Hysteresis presets (multipliers of VdiffThreshold) ----
|
||||
const float THOLD_MULT = 1.0f; // T_hold = THOLD_MULT * VdiffThreshold
|
||||
const float TENTER_MULT = 2.0f; // T_enter = TENTER_MULT * VdiffThreshold
|
||||
|
||||
// Globals: latest measured averaged voltages
|
||||
float v1 = 0.0f;
|
||||
float v2 = 0.0f;
|
||||
|
||||
// Calibration globals
|
||||
float VdiffBaseline = 0.0f; // median(|V1-V2|) measured at boot (no movement)
|
||||
float VdiffThreshold = 0.0f; // calibrated base threshold (used to derive T_hold/T_enter)
|
||||
|
||||
// Hysteresis thresholds (derived once after calibration)
|
||||
float T_hold = 0.0f;
|
||||
float T_enter = 0.0f;
|
||||
|
||||
// Direction encoding:
|
||||
// 0 = NONE, 2 = DIR1, 3 = DIR2
|
||||
byte direction = 0;
|
||||
|
||||
static inline float absf(float x) { return (x >= 0.0f) ? x : -x; }
|
||||
static inline float maxf(float a, float b) { return (a > b) ? a : b; }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// LED helpers
|
||||
// -----------------------------------------------------------------------------
|
||||
static void blinkLED(uint8_t pin, uint8_t times)
|
||||
{
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(pin, HIGH);
|
||||
delay(LED_BLINK_ON_MS);
|
||||
digitalWrite(pin, LOW);
|
||||
delay(LED_BLINK_OFF_MS);
|
||||
}
|
||||
}
|
||||
|
||||
static void initBlinkSequence()
|
||||
{
|
||||
// LED at Output 2 blinks 2 times
|
||||
blinkLED(LED_DIR1_PIN, 2);
|
||||
|
||||
// LED at Output 3 blinks 3 times
|
||||
blinkLED(LED_DIR2_PIN, 3);
|
||||
}
|
||||
|
||||
static void applyDirectionOutputs()
|
||||
{
|
||||
digitalWrite(LED_DIR1_PIN, LOW);
|
||||
digitalWrite(LED_DIR2_PIN, LOW);
|
||||
|
||||
if (direction == 2) {
|
||||
digitalWrite(LED_DIR1_PIN, HIGH);
|
||||
} else if (direction == 3) {
|
||||
digitalWrite(LED_DIR2_PIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Measurement
|
||||
// -----------------------------------------------------------------------------
|
||||
static void measureAveragedVoltages()
|
||||
{
|
||||
unsigned long startTime = millis();
|
||||
|
||||
unsigned long sum1 = 0;
|
||||
unsigned long sum2 = 0;
|
||||
unsigned long samples = 0;
|
||||
|
||||
while (millis() - startTime < SAMPLE_WINDOW_MS) {
|
||||
sum1 += analogRead(ADC_PIN_1);
|
||||
sum2 += analogRead(ADC_PIN_2);
|
||||
samples++;
|
||||
delayMicroseconds(SAMPLE_DELAY_US);
|
||||
}
|
||||
|
||||
float avg1 = (float)sum1 / samples;
|
||||
float avg2 = (float)sum2 / samples;
|
||||
|
||||
// Convert ADC value to voltage (default analog reference = Vcc ~ 5V)
|
||||
v1 = avg1 * (5.0f / 1023.0f);
|
||||
v2 = avg2 * (5.0f / 1023.0f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Median helpers (for calibration)
|
||||
// -----------------------------------------------------------------------------
|
||||
static void sortFloatArray(float *a, uint16_t n)
|
||||
{
|
||||
// Insertion sort (n=100 is small, OK)
|
||||
for (uint16_t i = 1; i < n; i++) {
|
||||
float key = a[i];
|
||||
int16_t j = (int16_t)i - 1;
|
||||
while (j >= 0 && a[j] > key) {
|
||||
a[j + 1] = a[j];
|
||||
j--;
|
||||
}
|
||||
a[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
static float medianOfSortedFloatArray(const float *a, uint16_t n)
|
||||
{
|
||||
if (n == 0) return 0.0f;
|
||||
if (n & 1) {
|
||||
return a[n / 2];
|
||||
} else {
|
||||
return (a[(n / 2) - 1] + a[n / 2]) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
// Calibrate baseline + VdiffThreshold once at boot/reset
|
||||
static void calibrateVdiffThreshold(uint16_t averageRepeat)
|
||||
{
|
||||
if (averageRepeat < 1) averageRepeat = 1;
|
||||
if (averageRepeat > 200) averageRepeat = 200; // RAM safety cap
|
||||
|
||||
float diffs[200];
|
||||
|
||||
for (uint16_t i = 0; i < averageRepeat; i++) {
|
||||
measureAveragedVoltages();
|
||||
diffs[i] = absf(v1 - v2); // baseline mismatch sample
|
||||
}
|
||||
|
||||
sortFloatArray(diffs, averageRepeat);
|
||||
VdiffBaseline = medianOfSortedFloatArray(diffs, averageRepeat);
|
||||
|
||||
// Calibrated base threshold with margin + floor
|
||||
VdiffThreshold = maxf(VdiffBaseline * VdiffThresholdMargin, VdiffThresholdMinVolts);
|
||||
|
||||
// Derive hysteresis thresholds (Version A)
|
||||
T_hold = THOLD_MULT * VdiffThreshold;
|
||||
T_enter = TENTER_MULT * VdiffThreshold;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// State machine with hysteresis (Version A)
|
||||
// -----------------------------------------------------------------------------
|
||||
static void updateDirectionFromVoltages()
|
||||
{
|
||||
const float diff = v1 - v2;
|
||||
const float absDiff = absf(diff);
|
||||
|
||||
// 1) Neutral region: HOLD
|
||||
if (absDiff <= T_hold) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2) Strong region: allow direction change
|
||||
if (absDiff >= T_enter) {
|
||||
direction = (diff > 0.0f) ? (byte)2 : (byte)3;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3) Deadband between T_hold and T_enter: HOLD
|
||||
return;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Serial output
|
||||
// -----------------------------------------------------------------------------
|
||||
static void serialPrintAll()
|
||||
{
|
||||
if (!SerialOutputAllow) return;
|
||||
|
||||
Serial.print("A2 for PB3 XTAL1, Pin2: ");
|
||||
Serial.print(v1, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("A3 for PB4 XTAL2, Pin3: ");
|
||||
Serial.print(v2, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("|V1-V2|: ");
|
||||
Serial.print(absf(v1 - v2), 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffBaseline: ");
|
||||
Serial.print(VdiffBaseline, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThreshold: ");
|
||||
Serial.print(VdiffThreshold, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("T_hold: ");
|
||||
Serial.print(T_hold, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("T_enter: ");
|
||||
Serial.print(T_enter, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("direction: ");
|
||||
Serial.println(direction);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Arduino entry points
|
||||
// -----------------------------------------------------------------------------
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(ADC_PIN_1, INPUT);
|
||||
pinMode(ADC_PIN_2, INPUT);
|
||||
|
||||
pinMode(LED_DIR1_PIN, OUTPUT);
|
||||
pinMode(LED_DIR2_PIN, OUTPUT);
|
||||
|
||||
// Initial calibration (assumes no movement)
|
||||
calibrateVdiffThreshold(AverageRepeat);
|
||||
|
||||
// Init blink sequence: 2x on D2, 3x on D3
|
||||
initBlinkSequence();
|
||||
|
||||
// One measurement for initial display + initial direction
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
if (SerialOutputAllow) {
|
||||
Serial.println("=== DenshaBekutoru Optocoupler Average Test (Arduino Pro Mini 5V/16MHz) ===");
|
||||
Serial.print("AverageRepeat: ");
|
||||
Serial.println(AverageRepeat);
|
||||
Serial.print("THOLD_MULT: ");
|
||||
Serial.print(THOLD_MULT, 2);
|
||||
Serial.print(" TENTER_MULT: ");
|
||||
Serial.println(TENTER_MULT, 2);
|
||||
}
|
||||
|
||||
serialPrintAll();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
applyDirectionOutputs();
|
||||
|
||||
serialPrintAll();
|
||||
|
||||
delay(300);
|
||||
}
|
||||
@ -0,0 +1,231 @@
|
||||
/*
|
||||
0004_DenshaBekutoru – State Machine implemented
|
||||
Target dev board (later): Arduino Pro Mini 5V / 16 MHz (ATmega328P)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
State machine (direction memory)
|
||||
----------------------------------------------------------------------------
|
||||
Inputs derived from v1, v2, VdiffThreshold:
|
||||
|
||||
N (Neutral): |v1 - v2| <= VdiffThreshold
|
||||
D1 (v1>>v2): (v1 - v2) > VdiffThreshold
|
||||
D2 (v2>>v1): (v2 - v1) > VdiffThreshold
|
||||
|
||||
State encoding (kept transfer-friendly, and compatible with earlier pin-mapping):
|
||||
0 = NONE
|
||||
2 = DIR1
|
||||
3 = DIR2
|
||||
|
||||
Transition table:
|
||||
|
||||
Current \ Input | N (neutral) | D1 (v1>>v2) | D2 (v2>>v1)
|
||||
-----------------------------------------------------------------
|
||||
0 (NONE) | 0 | 2 | 3
|
||||
2 (DIR1) | 2 | 2 | 3
|
||||
3 (DIR2) | 3 | 2 | 3
|
||||
|
||||
Mermaid (documentation)
|
||||
-----------------------
|
||||
stateDiagram-v2
|
||||
[*] --> NONE
|
||||
state "0 : NONE" as NONE
|
||||
state "2 : DIR1 (v1>>v2)" as DIR1
|
||||
state "3 : DIR2 (v2>>v1)" as DIR2
|
||||
|
||||
NONE --> NONE : |v1 - v2| <= T
|
||||
NONE --> DIR1 : v1 - v2 > T
|
||||
NONE --> DIR2 : v2 - v1 > T
|
||||
|
||||
DIR1 --> DIR1 : |v1 - v2| <= T
|
||||
DIR1 --> DIR1 : v1 - v2 > T
|
||||
DIR1 --> DIR2 : v2 - v1 > T
|
||||
|
||||
DIR2 --> DIR2 : |v1 - v2| <= T
|
||||
DIR2 --> DIR2 : v2 - v1 > T
|
||||
DIR2 --> DIR1 : v1 - v2 > T
|
||||
*/
|
||||
|
||||
const unsigned long SAMPLE_WINDOW_MS = 100; // averaging window per measurement
|
||||
const unsigned long SAMPLE_DELAY_US = 500; // delay between ADC samples (~2 kHz)
|
||||
|
||||
const uint8_t ADC_PIN_1 = A2; // Pro Mini A2 -> later ATtiny85 PB3 (XTAL1, Pin 2)
|
||||
const uint8_t ADC_PIN_2 = A3; // Pro Mini A3 -> later ATtiny85 PB4 (XTAL2, Pin 3)
|
||||
|
||||
// Serial output control (0 = no output, 1 = output)
|
||||
bool SerialOutputAllow = true;
|
||||
|
||||
// ---- Calibration parameters ----
|
||||
const uint16_t AverageRepeat = 100; // number of init measurements
|
||||
const float VdiffThresholdMargin = 1.50f; // multiplier (e.g., 1.5 = +50% margin)
|
||||
const float VdiffThresholdMinVolts = 0.03f; // floor in volts (optional but practical)
|
||||
|
||||
// Globals: latest measured averaged voltages
|
||||
float v1 = 0.0f;
|
||||
float v2 = 0.0f;
|
||||
|
||||
// Calibration globals
|
||||
float VdiffBaseline = 0.0f; // median(|V1-V2|) measured at boot (no movement)
|
||||
float VdiffThreshold = 0.0f; // final threshold used for direction decision
|
||||
|
||||
// Direction encoding:
|
||||
// 0 = NONE, 2 = DIR1, 3 = DIR2
|
||||
byte direction = 0;
|
||||
|
||||
static inline float absf(float x) { return (x >= 0.0f) ? x : -x; }
|
||||
static inline float maxf(float a, float b) { return (a > b) ? a : b; }
|
||||
|
||||
// Measure averaged voltages (updates globals v1/v2)
|
||||
static void measureAveragedVoltages()
|
||||
{
|
||||
unsigned long startTime = millis();
|
||||
|
||||
unsigned long sum1 = 0;
|
||||
unsigned long sum2 = 0;
|
||||
unsigned long samples = 0;
|
||||
|
||||
while (millis() - startTime < SAMPLE_WINDOW_MS) {
|
||||
sum1 += analogRead(ADC_PIN_1);
|
||||
sum2 += analogRead(ADC_PIN_2);
|
||||
samples++;
|
||||
delayMicroseconds(SAMPLE_DELAY_US);
|
||||
}
|
||||
|
||||
float avg1 = (float)sum1 / samples;
|
||||
float avg2 = (float)sum2 / samples;
|
||||
|
||||
// Convert ADC value to voltage (default analog reference = Vcc ~ 5V)
|
||||
v1 = avg1 * (5.0f / 1023.0f);
|
||||
v2 = avg2 * (5.0f / 1023.0f);
|
||||
}
|
||||
|
||||
static void sortFloatArray(float *a, uint16_t n)
|
||||
{
|
||||
// Insertion sort (n=100 is small, OK)
|
||||
for (uint16_t i = 1; i < n; i++) {
|
||||
float key = a[i];
|
||||
int16_t j = (int16_t)i - 1;
|
||||
while (j >= 0 && a[j] > key) {
|
||||
a[j + 1] = a[j];
|
||||
j--;
|
||||
}
|
||||
a[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
static float medianOfSortedFloatArray(const float *a, uint16_t n)
|
||||
{
|
||||
if (n == 0) return 0.0f;
|
||||
if (n & 1) {
|
||||
return a[n / 2];
|
||||
} else {
|
||||
return (a[(n / 2) - 1] + a[n / 2]) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
// Calibrate baseline + threshold once at boot/reset
|
||||
// Parameter must be only AverageRepeat (per your requirement).
|
||||
static void calibrateVdiffThreshold(uint16_t averageRepeat)
|
||||
{
|
||||
if (averageRepeat < 1) averageRepeat = 1;
|
||||
if (averageRepeat > 200) averageRepeat = 200; // RAM safety cap
|
||||
|
||||
float diffs[200];
|
||||
|
||||
for (uint16_t i = 0; i < averageRepeat; i++) {
|
||||
measureAveragedVoltages();
|
||||
diffs[i] = absf(v1 - v2); // baseline mismatch sample
|
||||
}
|
||||
|
||||
sortFloatArray(diffs, averageRepeat);
|
||||
VdiffBaseline = medianOfSortedFloatArray(diffs, averageRepeat);
|
||||
|
||||
// Final threshold with margin + floor
|
||||
VdiffThreshold = maxf(VdiffBaseline * VdiffThresholdMargin, VdiffThresholdMinVolts);
|
||||
}
|
||||
|
||||
// Implements the state machine table above
|
||||
static void updateDirectionFromVoltages()
|
||||
{
|
||||
const float diff = v1 - v2;
|
||||
const float absDiff = absf(diff);
|
||||
|
||||
// Neutral region: hold direction (only NONE stays NONE)
|
||||
if (absDiff <= VdiffThreshold) {
|
||||
// direction remains unchanged (0 stays 0; 2 stays 2; 3 stays 3)
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear dominance: set direction deterministically
|
||||
// diff > 0 => v1 >> v2 => DIR1 (2)
|
||||
// diff < 0 => v2 >> v1 => DIR2 (3)
|
||||
direction = (diff > 0.0f) ? (byte)2 : (byte)3;
|
||||
}
|
||||
|
||||
static void serialPrintAll()
|
||||
{
|
||||
if (!SerialOutputAllow) return;
|
||||
|
||||
Serial.print("A2 for PB3 XTAL1, Pin2: ");
|
||||
Serial.print(v1, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("A3 for PB4 XTAL2, Pin3: ");
|
||||
Serial.print(v2, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("|V1-V2|: ");
|
||||
Serial.print(absf(v1 - v2), 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffBaseline: ");
|
||||
Serial.print(VdiffBaseline, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThresholdMargin: ");
|
||||
Serial.print(VdiffThresholdMargin, 2);
|
||||
Serial.print(" x | ");
|
||||
|
||||
Serial.print("VdiffThresholdMinVolts: ");
|
||||
Serial.print(VdiffThresholdMinVolts, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("VdiffThreshold: ");
|
||||
Serial.print(VdiffThreshold, 3);
|
||||
Serial.print(" V | ");
|
||||
|
||||
Serial.print("direction: ");
|
||||
Serial.println(direction);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(ADC_PIN_1, INPUT);
|
||||
pinMode(ADC_PIN_2, INPUT);
|
||||
|
||||
// Initial calibration: compute VdiffThreshold once after boot/reset
|
||||
calibrateVdiffThreshold(AverageRepeat);
|
||||
|
||||
// One measurement for initial display
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
|
||||
if (SerialOutputAllow) {
|
||||
Serial.println("=== DenshaBekutoru State Machine and Variable Output (Arduino Pro Mini 5V/16MHz) ===");
|
||||
Serial.println("~~~ Init ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
Serial.print("AverageRepeat: ");
|
||||
Serial.println(AverageRepeat);
|
||||
Serial.println("~~~ Init ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
}
|
||||
|
||||
serialPrintAll();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measureAveragedVoltages();
|
||||
updateDirectionFromVoltages();
|
||||
|
||||
serialPrintAll();
|
||||
|
||||
delay(300);
|
||||
}
|
||||