Fixed #1: Unstable on/off positions

Fixed #2: Unit sleeps when adjusting positions
Fixed #3: No capacitor on input side of voltage regulator
Fixed #4: Add 3rd potentiometer for speed setting?
This commit is contained in:
Mark van Renswoude 2019-01-03 23:16:44 +01:00
parent 7be7190477
commit fa53deb9d0
4 changed files with 1040 additions and 574 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
(export (version D)
(design
(source P:\Electronics\RailroadSwitch\kicad\RailroadSwitch\RailroadSwitch.sch)
(date "1-1-2019 19:51:10")
(date "3-1-2019 19:49:40")
(tool "Eeschema (5.0.1)-3")
(sheet (number 1) (name /) (tstamps /)
(title_block
@ -76,7 +76,28 @@
(datasheet http://www.st.com/content/ccc/resource/technical/document/datasheet/41/4f/b3/b0/12/d4/47/88/CD00000444.pdf/files/CD00000444.pdf/jcr:content/translations/en.CD00000444.pdf)
(libsource (lib Regulator_Linear) (part L7805) (description "Positive 1.5A 35V Linear Regulator, Fixed Output 5V, TO-220/TO-263/TO-252"))
(sheetpath (names /) (tstamps /))
(tstamp 5C2CDA60)))
(tstamp 5C2CDA60))
(comp (ref C2)
(value 22pF)
(footprint Capacitors_SMD:C_1206)
(datasheet ~)
(libsource (lib Device) (part C) (description "Unpolarized capacitor"))
(sheetpath (names /) (tstamps /))
(tstamp 5C2E5A00))
(comp (ref RV3)
(value 10k)
(footprint Potentiometers:Potentiometer_Triwood_RM-065)
(datasheet ~)
(libsource (lib Device) (part R_POT) (description Potentiometer))
(sheetpath (names /) (tstamps /))
(tstamp 5C2EE588))
(comp (ref C3)
(value 470uF)
(footprint Capacitors_ThroughHole:CP_Radial_D6.3mm_P2.50mm)
(datasheet ~)
(libsource (lib Device) (part C) (description "Unpolarized capacitor"))
(sheetpath (names /) (tstamps /))
(tstamp 5C2EF195)))
(libparts
(libpart (lib Connector) (part Conn_01x02_Male)
(description "Generic connector, single row, 01x02, script generated (kicad-library-utils/schlib/autogen/connector/)")
@ -202,40 +223,47 @@
(library (logical Switch)
(uri "C:\\Program Files\\KiCad\\share\\kicad\\library/Switch.lib")))
(nets
(net (code 1) (name "Net-(J1-Pad3)")
(node (ref J1) (pin 3))
(node (ref U1) (pin 5)))
(net (code 2) (name GND)
(node (ref RV2) (pin 1))
(node (ref RV1) (pin 1))
(node (ref U2) (pin 2))
(node (ref C1) (pin 2))
(node (ref SW1) (pin 2))
(node (ref J2) (pin 1))
(net (code 1) (name GND)
(node (ref J1) (pin 1))
(node (ref U1) (pin 4)))
(net (code 3) (name "Net-(SW1-Pad1)")
(node (ref SW1) (pin 1))
(node (ref U1) (pin 6)))
(net (code 4) (name "Net-(RV2-Pad2)")
(node (ref U1) (pin 3))
(node (ref RV2) (pin 2)))
(net (code 5) (name "Net-(RV1-Pad2)")
(node (ref U1) (pin 7))
(node (ref RV1) (pin 2)))
(net (code 6) (name +12V)
(node (ref U2) (pin 1))
(node (ref J2) (pin 2)))
(net (code 7) (name "Net-(U1-Pad2)")
(node (ref U1) (pin 2)))
(net (code 8) (name +5V)
(node (ref C3) (pin 1))
(node (ref U1) (pin 4))
(node (ref RV2) (pin 1))
(node (ref C1) (pin 2))
(node (ref RV3) (pin 1))
(node (ref SW1) (pin 2))
(node (ref RV1) (pin 1))
(node (ref C2) (pin 2))
(node (ref U2) (pin 2))
(node (ref J2) (pin 1)))
(net (code 2) (name +5V)
(node (ref R1) (pin 1))
(node (ref C1) (pin 1))
(node (ref RV1) (pin 3))
(node (ref RV2) (pin 3))
(node (ref J1) (pin 2))
(node (ref RV3) (pin 3))
(node (ref C3) (pin 2))
(node (ref U2) (pin 3))
(node (ref R1) (pin 1))
(node (ref C1) (pin 1))
(node (ref U1) (pin 8)))
(net (code 9) (name "Net-(R1-Pad2)")
(net (code 3) (name +12V)
(node (ref J2) (pin 2))
(node (ref C2) (pin 1))
(node (ref U2) (pin 1)))
(net (code 4) (name "Net-(J1-Pad3)")
(node (ref U1) (pin 5))
(node (ref J1) (pin 3)))
(net (code 5) (name "Net-(RV3-Pad2)")
(node (ref U1) (pin 2))
(node (ref RV3) (pin 2)))
(net (code 6) (name "Net-(RV2-Pad2)")
(node (ref RV2) (pin 2))
(node (ref U1) (pin 3)))
(net (code 7) (name "Net-(R1-Pad2)")
(node (ref R1) (pin 2))
(node (ref U1) (pin 1)))))
(node (ref U1) (pin 1)))
(net (code 8) (name "Net-(RV1-Pad2)")
(node (ref U1) (pin 7))
(node (ref RV1) (pin 2)))
(net (code 9) (name "Net-(SW1-Pad1)")
(node (ref U1) (pin 6))
(node (ref SW1) (pin 1)))))

View File

@ -65,332 +65,406 @@ Wire Wire Line
$Comp
L MCU_Microchip_ATtiny:ATtiny85-20SU U1
U 1 1 5C2BB273
P 5850 3800
F 0 "U1" H 5320 3846 50 0000 R CNN
F 1 "ATtiny85" H 5320 3755 50 0000 R CNN
F 2 "Housings_SOIC:SOIJ-8_5.3x5.3mm_Pitch1.27mm" H 5850 3800 50 0001 C CIN
F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf" H 5850 3800 50 0001 C CNN
1 5850 3800
P 5300 4350
F 0 "U1" H 4770 4396 50 0000 R CNN
F 1 "ATtiny85" H 4770 4305 50 0000 R CNN
F 2 "Housings_SOIC:SOIJ-8_5.3x5.3mm_Pitch1.27mm" H 5300 4350 50 0001 C CIN
F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf" H 5300 4350 50 0001 C CNN
1 5300 4350
1 0 0 -1
$EndComp
$Comp
L Device:C C1
U 1 1 5C2C52A2
P 4450 3800
F 0 "C1" H 4565 3846 50 0000 L CNN
F 1 "100nF" H 4565 3755 50 0000 L CNN
F 2 "Capacitors_SMD:C_1206" H 4488 3650 50 0001 C CNN
F 3 "~" H 4450 3800 50 0001 C CNN
1 4450 3800
P 3900 4350
F 0 "C1" H 4015 4396 50 0000 L CNN
F 1 "100nF" H 4015 4305 50 0000 L CNN
F 2 "Capacitors_SMD:C_1206" H 3938 4200 50 0001 C CNN
F 3 "~" H 3900 4350 50 0001 C CNN
1 3900 4350
1 0 0 -1
$EndComp
Wire Wire Line
5850 3200 5850 3050
5300 3750 5300 3600
Wire Wire Line
5850 3050 4450 3050
5300 3600 3900 3600
Wire Wire Line
4450 3050 4450 3650
3900 3600 3900 4200
Wire Wire Line
5850 4400 5850 4500
5300 4950 5300 5050
Wire Wire Line
5850 4500 4450 4500
5300 5050 3900 5050
Wire Wire Line
4450 4500 4450 3950
3900 5050 3900 4500
$Comp
L Device:R R1
U 1 1 5C2C5686
P 6650 4250
F 0 "R1" H 6580 4204 50 0000 R CNN
F 1 "10k" H 6580 4295 50 0000 R CNN
F 2 "Resistors_SMD:R_0603" V 6580 4250 50 0001 C CNN
F 3 "~" H 6650 4250 50 0001 C CNN
1 6650 4250
P 6100 4800
F 0 "R1" H 6030 4754 50 0000 R CNN
F 1 "10k" H 6030 4845 50 0000 R CNN
F 2 "Resistors_SMD:R_0603" V 6030 4800 50 0001 C CNN
F 3 "~" H 6100 4800 50 0001 C CNN
1 6100 4800
-1 0 0 1
$EndComp
$Comp
L power:+5V #PWR05
U 1 1 5C2C5834
P 6650 4550
F 0 "#PWR05" H 6650 4400 50 0001 C CNN
F 1 "+5V" H 6665 4723 50 0000 C CNN
F 2 "" H 6650 4550 50 0001 C CNN
F 3 "" H 6650 4550 50 0001 C CNN
1 6650 4550
P 6100 5100
F 0 "#PWR05" H 6100 4950 50 0001 C CNN
F 1 "+5V" H 6115 5273 50 0000 C CNN
F 2 "" H 6100 5100 50 0001 C CNN
F 3 "" H 6100 5100 50 0001 C CNN
1 6100 5100
-1 0 0 1
$EndComp
Wire Wire Line
6450 4000 6650 4000
5900 4550 6100 4550
Wire Wire Line
6650 4000 6650 4100
6100 4550 6100 4650
Wire Wire Line
6650 4400 6650 4550
6100 4950 6100 5100
$Comp
L Device:R_POT RV2
U 1 1 5C2C5A17
P 7400 3900
F 0 "RV2" H 7331 3854 50 0000 R CNN
F 1 "10k" H 7331 3945 50 0000 R CNN
F 2 "Potentiometers:Potentiometer_Triwood_RM-065" H 7400 3900 50 0001 C CNN
F 3 "~" H 7400 3900 50 0001 C CNN
1 7400 3900
P 6650 4900
F 0 "RV2" H 6581 4854 50 0000 R CNN
F 1 "10k" H 6581 4945 50 0000 R CNN
F 2 "Potentiometers:Potentiometer_Triwood_RM-065" H 6650 4900 50 0001 C CNN
F 3 "~" H 6650 4900 50 0001 C CNN
1 6650 4900
-1 0 0 1
$EndComp
$Comp
L Device:R_POT RV1
U 1 1 5C2C5AE5
P 7850 3400
F 0 "RV1" H 7781 3354 50 0000 R CNN
F 1 "10k" H 7781 3445 50 0000 R CNN
F 2 "Potentiometers:Potentiometer_Triwood_RM-065" H 7850 3400 50 0001 C CNN
F 3 "~" H 7850 3400 50 0001 C CNN
1 7850 3400
P 7300 3950
F 0 "RV1" H 7231 3904 50 0000 R CNN
F 1 "10k" H 7231 3995 50 0000 R CNN
F 2 "Potentiometers:Potentiometer_Triwood_RM-065" H 7300 3950 50 0001 C CNN
F 3 "~" H 7300 3950 50 0001 C CNN
1 7300 3950
-1 0 0 1
$EndComp
$Comp
L Switch:SW_SPST SW1
U 1 1 5C2C5D71
P 7200 3150
F 0 "SW1" H 7200 3385 50 0000 C CNN
F 1 "SW_SPST" H 7200 3294 50 0000 C CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x02_Pitch2.54mm" H 7200 3150 50 0001 C CNN
F 3 "" H 7200 3150 50 0001 C CNN
1 7200 3150
P 6650 3700
F 0 "SW1" H 6650 3935 50 0000 C CNN
F 1 "SW_SPST" H 6650 3844 50 0000 C CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x02_Pitch2.54mm" H 6650 3700 50 0001 C CNN
F 3 "" H 6650 3700 50 0001 C CNN
1 6650 3700
1 0 0 -1
$EndComp
$Comp
L power:+5V #PWR04
U 1 1 5C2C60DC
P 5850 2900
F 0 "#PWR04" H 5850 2750 50 0001 C CNN
F 1 "+5V" H 5865 3073 50 0000 C CNN
F 2 "" H 5850 2900 50 0001 C CNN
F 3 "" H 5850 2900 50 0001 C CNN
1 5850 2900
P 5300 3450
F 0 "#PWR04" H 5300 3300 50 0001 C CNN
F 1 "+5V" H 5315 3623 50 0000 C CNN
F 2 "" H 5300 3450 50 0001 C CNN
F 3 "" H 5300 3450 50 0001 C CNN
1 5300 3450
1 0 0 -1
$EndComp
Wire Wire Line
5850 2900 5850 3050
Connection ~ 5850 3050
5300 3450 5300 3600
Connection ~ 5300 3600
$Comp
L power:GND #PWR06
U 1 1 5C2C61DC
P 5850 4650
F 0 "#PWR06" H 5850 4400 50 0001 C CNN
F 1 "GND" H 5855 4477 50 0000 C CNN
F 2 "" H 5850 4650 50 0001 C CNN
F 3 "" H 5850 4650 50 0001 C CNN
1 5850 4650
P 5300 5200
F 0 "#PWR06" H 5300 4950 50 0001 C CNN
F 1 "GND" H 5305 5027 50 0000 C CNN
F 2 "" H 5300 5200 50 0001 C CNN
F 3 "" H 5300 5200 50 0001 C CNN
1 5300 5200
1 0 0 -1
$EndComp
Wire Wire Line
5850 4500 5850 4650
Connection ~ 5850 4500
5300 5050 5300 5200
Connection ~ 5300 5050
$Comp
L power:+5V #PWR010
U 1 1 5C2C8DBC
P 7400 3700
F 0 "#PWR010" H 7400 3550 50 0001 C CNN
F 1 "+5V" H 7415 3873 50 0000 C CNN
F 2 "" H 7400 3700 50 0001 C CNN
F 3 "" H 7400 3700 50 0001 C CNN
1 7400 3700
P 6650 4750
F 0 "#PWR010" H 6650 4600 50 0001 C CNN
F 1 "+5V" H 6665 4923 50 0000 C CNN
F 2 "" H 6650 4750 50 0001 C CNN
F 3 "" H 6650 4750 50 0001 C CNN
1 6650 4750
1 0 0 -1
$EndComp
$Comp
L power:+5V #PWR08
U 1 1 5C2C8DE7
P 7850 3200
F 0 "#PWR08" H 7850 3050 50 0001 C CNN
F 1 "+5V" H 7865 3373 50 0000 C CNN
F 2 "" H 7850 3200 50 0001 C CNN
F 3 "" H 7850 3200 50 0001 C CNN
1 7850 3200
P 7300 3800
F 0 "#PWR08" H 7300 3650 50 0001 C CNN
F 1 "+5V" H 7315 3973 50 0000 C CNN
F 2 "" H 7300 3800 50 0001 C CNN
F 3 "" H 7300 3800 50 0001 C CNN
1 7300 3800
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR011
U 1 1 5C2C8E02
P 7400 4100
F 0 "#PWR011" H 7400 3850 50 0001 C CNN
F 1 "GND" H 7405 3927 50 0000 C CNN
F 2 "" H 7400 4100 50 0001 C CNN
F 3 "" H 7400 4100 50 0001 C CNN
1 7400 4100
P 6650 5050
F 0 "#PWR011" H 6650 4800 50 0001 C CNN
F 1 "GND" H 6655 4877 50 0000 C CNN
F 2 "" H 6650 5050 50 0001 C CNN
F 3 "" H 6650 5050 50 0001 C CNN
1 6650 5050
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR09
U 1 1 5C2C8E1D
P 7850 3600
F 0 "#PWR09" H 7850 3350 50 0001 C CNN
F 1 "GND" H 7855 3427 50 0000 C CNN
F 2 "" H 7850 3600 50 0001 C CNN
F 3 "" H 7850 3600 50 0001 C CNN
1 7850 3600
P 7300 4100
F 0 "#PWR09" H 7300 3850 50 0001 C CNN
F 1 "GND" H 7305 3927 50 0000 C CNN
F 2 "" H 7300 4100 50 0001 C CNN
F 3 "" H 7300 4100 50 0001 C CNN
1 7300 4100
1 0 0 -1
$EndComp
Wire Wire Line
7400 4050 7400 4100
7150 3950 6450 3950
Wire Wire Line
7400 3750 7400 3700
6450 3950 6450 4250
Wire Wire Line
7850 3200 7850 3250
6450 4250 5900 4250
Wire Wire Line
7850 3550 7850 3600
6450 3700 6300 3700
Wire Wire Line
7700 3400 7000 3400
6300 3700 6300 4150
Wire Wire Line
7000 3400 7000 3700
Wire Wire Line
7000 3700 6450 3700
Wire Wire Line
7250 3900 6450 3900
Wire Wire Line
7000 3150 6850 3150
Wire Wire Line
6850 3150 6850 3600
Wire Wire Line
6850 3600 6450 3600
6300 4150 5900 4150
$Comp
L power:GND #PWR07
U 1 1 5C2CAB2A
P 7450 3150
F 0 "#PWR07" H 7450 2900 50 0001 C CNN
F 1 "GND" H 7455 2977 50 0000 C CNN
F 2 "" H 7450 3150 50 0001 C CNN
F 3 "" H 7450 3150 50 0001 C CNN
1 7450 3150
P 6900 3700
F 0 "#PWR07" H 6900 3450 50 0001 C CNN
F 1 "GND" H 6905 3527 50 0000 C CNN
F 2 "" H 6900 3700 50 0001 C CNN
F 3 "" H 6900 3700 50 0001 C CNN
1 6900 3700
0 -1 -1 0
$EndComp
Wire Wire Line
7400 3150 7450 3150
6850 3700 6900 3700
Wire Wire Line
6450 3500 6750 3500
5900 4050 6200 4050
Wire Wire Line
6750 3500 6750 2750
6200 4050 6200 3300
Wire Wire Line
6750 2750 7000 2750
6200 3300 6450 3300
$Comp
L Connector:Conn_01x03_Male J1
U 1 1 5C2CB61A
P 7200 2650
F 0 "J1" H 7172 2673 50 0000 R CNN
F 1 "Servo" H 7172 2582 50 0000 R CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x03_Pitch2.54mm" H 7200 2650 50 0001 C CNN
F 3 "~" H 7200 2650 50 0001 C CNN
1 7200 2650
P 6650 3200
F 0 "J1" H 6622 3223 50 0000 R CNN
F 1 "Servo" H 6622 3132 50 0000 R CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x03_Pitch2.54mm" H 6650 3200 50 0001 C CNN
F 3 "~" H 6650 3200 50 0001 C CNN
1 6650 3200
-1 0 0 -1
$EndComp
$Comp
L Connector:Conn_01x02_Male J2
U 1 1 5C2CC12F
P 7200 1850
F 0 "J2" H 7172 1823 50 0000 R CNN
F 1 "Power" H 7172 1732 50 0000 R CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x02_Pitch2.54mm" H 7200 1850 50 0001 C CNN
F 3 "~" H 7200 1850 50 0001 C CNN
1 7200 1850
P 6650 2100
F 0 "J2" H 6622 2073 50 0000 R CNN
F 1 "Power" H 6622 1982 50 0000 R CNN
F 2 "Pin_Headers:Pin_Header_Straight_1x02_Pitch2.54mm" H 6650 2100 50 0001 C CNN
F 3 "~" H 6650 2100 50 0001 C CNN
1 6650 2100
-1 0 0 -1
$EndComp
$Comp
L power:+5V #PWR018
U 1 1 5C2CCBF6
P 6650 2650
F 0 "#PWR018" H 6650 2500 50 0001 C CNN
F 1 "+5V" H 6665 2823 50 0000 C CNN
F 2 "" H 6650 2650 50 0001 C CNN
F 3 "" H 6650 2650 50 0001 C CNN
1 6650 2650
P 5950 3200
F 0 "#PWR018" H 5950 3050 50 0001 C CNN
F 1 "+5V" H 5965 3373 50 0000 C CNN
F 2 "" H 5950 3200 50 0001 C CNN
F 3 "" H 5950 3200 50 0001 C CNN
1 5950 3200
0 -1 -1 0
$EndComp
$Comp
L power:GND #PWR017
U 1 1 5C2CCC29
P 6900 2550
F 0 "#PWR017" H 6900 2300 50 0001 C CNN
F 1 "GND" H 6905 2377 50 0000 C CNN
F 2 "" H 6900 2550 50 0001 C CNN
F 3 "" H 6900 2550 50 0001 C CNN
1 6900 2550
P 5950 2900
F 0 "#PWR017" H 5950 2650 50 0001 C CNN
F 1 "GND" H 5955 2727 50 0000 C CNN
F 2 "" H 5950 2900 50 0001 C CNN
F 3 "" H 5950 2900 50 0001 C CNN
1 5950 2900
0 1 1 0
$EndComp
Wire Wire Line
6900 2550 7000 2550
Wire Wire Line
7000 2650 6650 2650
6450 3200 6100 3200
$Comp
L power:GND #PWR014
U 1 1 5C2CD426
P 7000 1850
F 0 "#PWR014" H 7000 1600 50 0001 C CNN
F 1 "GND" H 7005 1677 50 0000 C CNN
F 2 "" H 7000 1850 50 0001 C CNN
F 3 "" H 7000 1850 50 0001 C CNN
1 7000 1850
P 6450 2100
F 0 "#PWR014" H 6450 1850 50 0001 C CNN
F 1 "GND" H 6455 1927 50 0000 C CNN
F 2 "" H 6450 2100 50 0001 C CNN
F 3 "" H 6450 2100 50 0001 C CNN
1 6450 2100
0 1 1 0
$EndComp
$Comp
L power:+12V #PWR015
U 1 1 5C2CD4CB
P 6650 1950
F 0 "#PWR015" H 6650 1800 50 0001 C CNN
F 1 "+12V" H 6665 2123 50 0000 C CNN
F 2 "" H 6650 1950 50 0001 C CNN
F 3 "" H 6650 1950 50 0001 C CNN
1 6650 1950
P 6100 2200
F 0 "#PWR015" H 6100 2050 50 0001 C CNN
F 1 "+12V" H 6115 2373 50 0000 C CNN
F 2 "" H 6100 2200 50 0001 C CNN
F 3 "" H 6100 2200 50 0001 C CNN
1 6100 2200
0 -1 -1 0
$EndComp
Wire Wire Line
6650 1950 7000 1950
6100 2200 6450 2200
$Comp
L Regulator_Linear:L7805 U2
U 1 1 5C2CDA60
P 5350 1800
F 0 "U2" H 5350 2042 50 0000 C CNN
F 1 "L7805" H 5350 1951 50 0000 C CNN
F 2 "TO_SOT_Packages_THT:TO-220-3_Horizontal" H 5375 1650 50 0001 L CIN
F 3 "http://www.st.com/content/ccc/resource/technical/document/datasheet/41/4f/b3/b0/12/d4/47/88/CD00000444.pdf/files/CD00000444.pdf/jcr:content/translations/en.CD00000444.pdf" H 5350 1750 50 0001 C CNN
1 5350 1800
P 4850 2100
F 0 "U2" H 4850 2342 50 0000 C CNN
F 1 "L7805" H 4850 2251 50 0000 C CNN
F 2 "TO_SOT_Packages_THT:TO-220-3_Horizontal" H 4875 1950 50 0001 L CIN
F 3 "http://www.st.com/content/ccc/resource/technical/document/datasheet/41/4f/b3/b0/12/d4/47/88/CD00000444.pdf/files/CD00000444.pdf/jcr:content/translations/en.CD00000444.pdf" H 4850 2050 50 0001 C CNN
1 4850 2100
1 0 0 -1
$EndComp
$Comp
L power:+12V #PWR012
U 1 1 5C2CDF5F
P 5000 1800
F 0 "#PWR012" H 5000 1650 50 0001 C CNN
F 1 "+12V" H 5015 1973 50 0000 C CNN
F 2 "" H 5000 1800 50 0001 C CNN
F 3 "" H 5000 1800 50 0001 C CNN
1 5000 1800
P 4050 2100
F 0 "#PWR012" H 4050 1950 50 0001 C CNN
F 1 "+12V" H 4065 2273 50 0000 C CNN
F 2 "" H 4050 2100 50 0001 C CNN
F 3 "" H 4050 2100 50 0001 C CNN
1 4050 2100
0 -1 -1 0
$EndComp
Wire Wire Line
5000 1800 5050 1800
4050 2100 4350 2100
$Comp
L power:GND #PWR016
U 1 1 5C2CE36A
P 5350 2150
F 0 "#PWR016" H 5350 1900 50 0001 C CNN
F 1 "GND" H 5355 1977 50 0000 C CNN
F 2 "" H 5350 2150 50 0001 C CNN
F 3 "" H 5350 2150 50 0001 C CNN
1 5350 2150
P 4850 2750
F 0 "#PWR016" H 4850 2500 50 0001 C CNN
F 1 "GND" H 4855 2577 50 0000 C CNN
F 2 "" H 4850 2750 50 0001 C CNN
F 3 "" H 4850 2750 50 0001 C CNN
1 4850 2750
1 0 0 -1
$EndComp
$Comp
L power:+5V #PWR013
U 1 1 5C2CE3A2
P 5700 1800
F 0 "#PWR013" H 5700 1650 50 0001 C CNN
F 1 "+5V" H 5715 1973 50 0000 C CNN
F 2 "" H 5700 1800 50 0001 C CNN
F 3 "" H 5700 1800 50 0001 C CNN
1 5700 1800
P 5200 2100
F 0 "#PWR013" H 5200 1950 50 0001 C CNN
F 1 "+5V" H 5215 2273 50 0000 C CNN
F 2 "" H 5200 2100 50 0001 C CNN
F 3 "" H 5200 2100 50 0001 C CNN
1 5200 2100
0 1 1 0
$EndComp
Wire Wire Line
5650 1800 5700 1800
5150 2100 5200 2100
Wire Wire Line
5350 2100 5350 2150
NoConn ~ 6450 3800
4850 2400 4850 2550
$Comp
L Device:C C2
U 1 1 5C2E5A00
P 4350 2400
F 0 "C2" H 4465 2446 50 0000 L CNN
F 1 "22pF" H 4465 2355 50 0000 L CNN
F 2 "Capacitors_SMD:C_1206" H 4388 2250 50 0001 C CNN
F 3 "~" H 4350 2400 50 0001 C CNN
1 4350 2400
1 0 0 -1
$EndComp
Wire Wire Line
4350 2250 4350 2100
Connection ~ 4350 2100
Wire Wire Line
4350 2100 4550 2100
Wire Wire Line
4350 2550 4850 2550
Connection ~ 4850 2550
Wire Wire Line
4850 2550 4850 2750
Wire Wire Line
5900 4450 6450 4450
Wire Wire Line
6450 4450 6450 4900
Wire Wire Line
6450 4900 6500 4900
$Comp
L Device:R_POT RV3
U 1 1 5C2EE588
P 7300 4900
F 0 "RV3" H 7231 4854 50 0000 R CNN
F 1 "10k" H 7231 4945 50 0000 R CNN
F 2 "Potentiometers:Potentiometer_Triwood_RM-065" H 7300 4900 50 0001 C CNN
F 3 "~" H 7300 4900 50 0001 C CNN
1 7300 4900
-1 0 0 1
$EndComp
$Comp
L power:+5V #PWR01
U 1 1 5C2EE618
P 7300 4750
F 0 "#PWR01" H 7300 4600 50 0001 C CNN
F 1 "+5V" H 7315 4923 50 0000 C CNN
F 2 "" H 7300 4750 50 0001 C CNN
F 3 "" H 7300 4750 50 0001 C CNN
1 7300 4750
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR019
U 1 1 5C2EE639
P 7300 5050
F 0 "#PWR019" H 7300 4800 50 0001 C CNN
F 1 "GND" H 7305 4877 50 0000 C CNN
F 2 "" H 7300 5050 50 0001 C CNN
F 3 "" H 7300 5050 50 0001 C CNN
1 7300 5050
1 0 0 -1
$EndComp
Wire Wire Line
5900 4350 7050 4350
Wire Wire Line
7050 4350 7050 4900
Wire Wire Line
7050 4900 7150 4900
$Comp
L Device:C C3
U 1 1 5C2EF195
P 6100 3050
F 0 "C3" H 6215 3096 50 0000 L CNN
F 1 "470uF" H 6215 3005 50 0000 L CNN
F 2 "Capacitors_ThroughHole:CP_Radial_D6.3mm_P2.50mm" H 6138 2900 50 0001 C CNN
F 3 "~" H 6100 3050 50 0001 C CNN
1 6100 3050
1 0 0 -1
$EndComp
Connection ~ 6100 3200
Wire Wire Line
6100 3200 5950 3200
Wire Wire Line
5950 2900 6100 2900
Wire Wire Line
6100 2900 6450 2900
Wire Wire Line
6450 2900 6450 3100
Connection ~ 6100 2900
$EndSCHEMATC

View File

@ -12,36 +12,42 @@
Wiring:
+---u---+
10k R to +5V -| 1 8 |- +5V
NC -| 2 7 |- "Off" potentiometer
"On" potentiometer -| 3 6 |- On/Off switch (active low)
GND -| 4 5 |- Servo PWM signal
+-------+
+---u---+
10k R to +5V -| 1 8 |- +5V
"Speed" potentiometer (RV3) -| 2 7 |- "Off" potentiometer (RV1)
"On" potentiometer (RV2) -| 3 6 |- On/Off switch (active low)
GND -| 4 5 |- Servo PWM signal
+-------+
*/
static const uint8_t PinServo = 0;
static const uint8_t PinSwitch = 1;
static const uint8_t PinOffPosition = A1;
static const uint8_t PinOnPosition = A2;
static const uint8_t PinSpeed = A3;
static const float TransitionTime = 2000;
static const float TransitionTimeMin = 1;
static const float TransitionTimeMax = 5000;
static const uint16_t SleepTime = 10000;
static const uint16_t ServoMinPulse = 544;
static const uint16_t ServoMaxPulse = 2400;
static const uint16_t ServoPulseInterval = 20;
static const uint16_t ServoStabilizeDelay = 100;
int offPosition; // 0 - 180 degrees, read from "Off" potentiometer
int onPosition; // 0 - 180 degrees, read from "On" potentiometer
float speed; // Degrees per millisecond
int speed; // 0 - 1023, read from "Speed" potentiometer
float degreesPerMilli; // Degrees per millisecond
bool startOn; // If the switch was on when it was last flipped
bool lastOn; // If the switch was on when it was last flipped
int startPosition; // The position the servo was in when the switch was flipped
unsigned long startTime; // The last time the switch was flipped
unsigned long idleTime; // The last time anything happened
bool servoEnabled; // Whether or not pulses should be sent to the servo
int servoPosition; // The desired position of the servo
@ -55,10 +61,12 @@ SoftwareSerial debug(-1,3);
// Forward declarations
void pulseServo(unsigned long currentTime);
bool updateOnOffPositions();
bool updateSettings();
inline int getNewPosition(unsigned long currentTime, int targetPosition) __attribute__((always_inline));
void sleepUntilSwitch();
float floatMap(float x, float in_min, float in_max, float out_min, float out_max);
void setup()
{
@ -72,9 +80,13 @@ void setup()
pinMode(PinSwitch, INPUT_PULLUP);
pinMode(PinServo, OUTPUT);
updateOnOffPositions();
offPosition = -1;
onPosition = -1;
speed = -1;
startOn = false;
updateSettings();
lastOn = false;
startPosition = offPosition;
servoPosition = offPosition;
@ -97,15 +109,16 @@ void loop()
bool isOn = (digitalRead(PinSwitch) == LOW);
// If the switch changed, start from the last known position
if (isOn != startOn)
if (isOn != lastOn)
{
#ifdef DEBUG
debug.println("State changed");
#endif
startOn = isOn;
lastOn = isOn;
startPosition = servoPosition;
startTime = currentTime;
idleTime = startTime;
}
int targetPosition = isOn ? onPosition : offPosition;
@ -113,45 +126,52 @@ void loop()
{
servoPosition = getNewPosition(currentTime, targetPosition);
servoEnabled = true;
idleTime = currentTime;
}
else
else if (servoEnabled)
{
// Ensure we pulsed the last position
delay(20);
pulseServo(millis());
delay(20);
currentTime = millis();
delay(ServoPulseInterval);
pulseServo(currentTime);
delay(ServoPulseInterval);
// Stop sending pulses when we reach the destination, to prevent
// power consumption and possible buzzing
servoEnabled = false;
idleTime = currentTime;
}
if (!servoEnabled)
// Don't update the settings while the servo is moving, as the
// voltage drop can cause fluctuating results
if (!servoEnabled && currentTime - idleTime >= ServoStabilizeDelay)
{
// Don't update the positions while the servo is moving, as the
// voltage drop can cause fluctuating results
if (updateOnOffPositions())
if (updateSettings())
{
// Immediately go to the new position
currentTime = millis();
servoPosition = isOn ? onPosition : offPosition;
delay(20);
pulseServo(millis());
delay(20);
delay(ServoPulseInterval);
pulseServo(currentTime);
delay(ServoPulseInterval);
idleTime = currentTime;
}
}
// Stay awake for a bit to allow changes to the on and off positions
// to take effect immediately
if (currentTime - startTime >= SleepTime)
if (currentTime - idleTime >= SleepTime)
sleepUntilSwitch();
}
void pulseServo(unsigned long currentTime)
{
if (currentTime - servoPulseTime < 20)
if (currentTime - servoPulseTime < ServoPulseInterval)
return;
int pulseWidth = map(servoPosition, 0, 180, ServoMinPulse, ServoMaxPulse);
@ -171,23 +191,27 @@ void pulseServo(unsigned long currentTime)
}
bool updateOnOffPositions()
bool updateSettings()
{
int newOffPosition = map(analogRead(PinOffPosition), 0, 1023, 0, 180);
int newOnPosition = map(analogRead(PinOnPosition), 0, 1023, 0, 180);
int newSpeed = analogRead(PinSpeed);
if (newOffPosition != offPosition || newOnPosition != onPosition)
if (newOffPosition != offPosition || newOnPosition != onPosition || newSpeed != speed)
{
offPosition = newOffPosition;
onPosition = newOnPosition;
speed = newSpeed;
speed = abs((float)(onPosition - offPosition)) / TransitionTime;
float transitionTime = floatMap(speed, 0, 1023, TransitionTimeMin, TransitionTimeMax);
degreesPerMilli = abs((float)(onPosition - offPosition)) / transitionTime;
#ifdef DEBUG
debug.println("Positions changed");
debug.print(" Off position: "); debug.println(offPosition);
debug.print(" On position : "); debug.println(onPosition);
debug.print(" Speed : "); debug.println(speed);
debug.print(" Off position : "); debug.println(offPosition);
debug.print(" On position : "); debug.println(onPosition);
debug.print(" Transition time: "); debug.println(transitionTime);
debug.print(" Degrees / milli: "); debug.println(degreesPerMilli);
#endif
return true;
@ -200,17 +224,17 @@ bool updateOnOffPositions()
int getNewPosition(unsigned long currentTime, int targetPosition)
{
int newPosition;
float timePassed = currentTime - startTime;
unsigned long timePassed = currentTime - startTime;
if (targetPosition > startPosition)
{
newPosition = startPosition + (timePassed * speed);
newPosition = startPosition + ((float)timePassed * degreesPerMilli);
if (newPosition > targetPosition)
newPosition = targetPosition;
}
else
{
newPosition = startPosition - (timePassed * speed);
newPosition = startPosition - ((float)timePassed * degreesPerMilli);
if (newPosition < targetPosition)
newPosition = targetPosition;
}
@ -266,4 +290,10 @@ void sleepUntilSwitch()
PCMSK = 0;
sleepEnd();
}
}
float floatMap(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}