* Z:\home\khalils\Downloads\files\data\raw_asc\151321439b45_02-opto-with-comparator.asc
* Generated by LTspice 26.0.1 for Windows.
* # python code for positive feedback resistor calculation\n# http://www.labbookpages.co.uk/electronics/resNetworks/comparator.html\nprint ('Positive feedback resistor')\n \nvthu = 4.8\nRu = 10e3\nRl = 22e3\nvref = 5.0\nvout_max = 3.3\n \nnum = (Ru*vout_max) - ((vthu/Rl)*(Ru+Rl))\nden = ((vthu/Rl)*(Ru+Rl)-vref)\n \nRfb = num/den\n \nprint(f'Rfb = {Rfb}') # Rfb = 16647.853211009176
* Library below included based on ModelFile attribute of instance XU2 (C:\users\khalils\AppData\Local\LTspice\lib\sym\OpAmps\ADA4665.asy)
* Library below included based on ModelFile attribute of instance XU1 (C:\users\khalils\AppData\Local\LTspice\lib\sym\Optos\PC817A.asy)
D3 N005 opto_a 1N4007
R2 N005 ac2 47k
R11 N003 div 16k
V2 vcc 0 5
D2 N002 opto_a 1N4007
D5 opto_k N005 1N4007
R7 N003 N004 1k
C1 0 ac2 1n V=2k
R6 0 div 22k
C2 N001 0 2.2n
XU1 opto_a opto_k zero 0 PC817 Igain=1m ;pnba A)K)C)E
R1 N002 ac1 47k
R4 zero N001 100k
D1 opto_k opto_a 1N4007
R3 zero vcc 10k
R8 N004 0 47k
R9 out vcc 10k
V1 ac1 ac2 SINE(0 318 50)
R10 N003 0 1k
R5 div vcc 10k
Q1 out N004 0 0 2N3904
XU2 div N001 vcc 0 N003 ADA4665 ;pnba In+)In-)V+)V-)OUT
D4 opto_k N002 1N4007
.model D D
.lib C:\users\khalils\AppData\Local\LTspice\lib\cmp\standard.dio
.model NPN NPN
.model PNP PNP
.lib C:\users\khalils\AppData\Local\LTspice\lib\cmp\standard.bjt
.tran 50m
.lib ADI.lib
.lib PC817.sub
.backanno
.end

* LTspice schematic (.asc):
Version 4
SHEET 1 2644 680
WIRE 992 32 928 32
WIRE 1168 32 992 32
WIRE 1296 32 1168 32
WIRE 1584 32 1296 32
WIRE 1584 48 1584 32
WIRE 928 80 928 32
WIRE 1168 80 1168 32
WIRE 560 144 496 144
WIRE 608 144 560 144
WIRE 1584 144 1584 128
WIRE 1616 144 1584 144
WIRE 496 160 496 144
WIRE 560 160 560 144
WIRE 1584 160 1584 144
WIRE 1296 176 1296 32
WIRE 608 192 608 144
WIRE 656 192 608 192
WIRE 672 192 656 192
WIRE 704 192 672 192
WIRE 928 192 928 160
WIRE 928 192 896 192
WIRE 976 192 928 192
WIRE 1008 192 976 192
WIRE 1104 192 1088 192
WIRE 1264 192 1104 192
WIRE 240 208 192 208
WIRE 288 208 240 208
WIRE 416 208 368 208
WIRE 672 208 672 192
WIRE 1344 208 1328 208
WIRE 1376 208 1344 208
WIRE 1392 208 1376 208
WIRE 1488 208 1472 208
WIRE 1520 208 1488 208
WIRE 1168 224 1168 160
WIRE 1200 224 1168 224
WIRE 1232 224 1200 224
WIRE 1264 224 1232 224
WIRE 416 240 416 208
WIRE 496 240 496 224
WIRE 496 240 416 240
WIRE 1376 240 1376 208
WIRE 1488 240 1488 208
WIRE 560 256 560 224
WIRE 560 256 416 256
WIRE 1104 256 1104 192
WIRE 1168 256 1168 224
WIRE 496 272 496 240
WIRE 560 272 560 256
WIRE 1296 272 1296 240
WIRE 240 288 192 288
WIRE 256 288 240 288
WIRE 288 288 256 288
WIRE 416 288 416 256
WIRE 416 288 368 288
WIRE 656 288 608 288
WIRE 672 288 672 272
WIRE 672 288 656 288
WIRE 704 288 672 288
WIRE 928 288 896 288
WIRE 992 304 992 272
WIRE 1376 336 1376 320
WIRE 1488 336 1488 320
WIRE 1584 336 1584 256
WIRE 496 352 496 336
WIRE 560 352 560 336
WIRE 560 352 496 352
WIRE 608 352 608 288
WIRE 608 352 560 352
WIRE 1104 352 1104 320
WIRE 1168 352 1168 336
WIRE 1232 352 1232 224
WIRE 1248 352 1232 352
WIRE 1344 352 1344 208
WIRE 1344 352 1328 352
WIRE 256 384 256 288
WIRE 752 384 256 384
WIRE 928 384 928 288
WIRE 928 384 816 384
WIRE 928 416 928 384
WIRE 992 416 992 384
SYMBOL res 1600 144 R180
WINDOW 0 36 76 Left 2
WINDOW 3 36 40 Left 1
SYMATTR InstName R9
SYMATTR Value 10k
SYMBOL res 1184 176 R180
WINDOW 0 36 76 Left 2
WINDOW 3 36 40 Left 1
SYMATTR InstName R5
SYMATTR Value 10k
SYMBOL res 1472 224 R0
WINDOW 3 36 76 Left 1
SYMATTR InstName R8
SYMATTR Value 47k
SYMBOL res 992 208 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 0 56 VBottom 1
SYMATTR InstName R4
SYMATTR Value 100k
SYMBOL voltage 992 288 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V2
SYMATTR Value 5
SYMBOL diode 688 272 R180
WINDOW 0 24 64 Left 2
WINDOW 3 38 30 Left 1
SYMATTR InstName D1
SYMATTR Value 1N4007
SYMBOL voltage 192 192 R0
WINDOW 0 39 38 Left 2
WINDOW 3 -15 121 Left 1
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V1
SYMATTR Value SINE(0 318 50)
SYMBOL diode 512 336 R180
WINDOW 0 24 64 Left 2
WINDOW 3 -14 -7 VRight 1
SYMATTR InstName D4
SYMATTR Value 1N4007
SYMBOL Optos\\PC817A 800 240 R0
SYMATTR InstName U1
SYMBOL npn 1520 160 R0
WINDOW 3 56 68 Left 1
SYMATTR InstName Q1
SYMATTR Value 2N3904
SYMBOL diode 512 224 R180
WINDOW 0 24 64 Left 2
WINDOW 3 -15 -8 VRight 1
SYMATTR InstName D2
SYMATTR Value 1N4007
SYMBOL res 384 192 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 1
SYMATTR InstName R1
SYMATTR Value 47k
SYMBOL cap 1088 256 R0
WINDOW 3 24 56 Left 1
SYMATTR InstName C2
SYMATTR Value 2.2n
SYMBOL res 384 272 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 1
SYMATTR InstName R2
SYMATTR Value 47k
SYMBOL OpAmps\\ADA4665 1296 144 R0
WINDOW 0 14 -19 Left 2
WINDOW 3 12 6 Left 2
SYMATTR InstName U2
SYMBOL res 944 176 R180
WINDOW 0 36 76 Left 2
WINDOW 3 36 40 Left 1
SYMATTR InstName R3
SYMATTR Value 10k
SYMBOL res 1344 336 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 1
SYMATTR InstName R11
SYMATTR Value 16k
SYMBOL cap 816 368 R90
WINDOW 0 8 8 VBottom 2
WINDOW 3 20 10 VTop 2
SYMATTR InstName C1
SYMATTR Value 1n
SYMATTR SpiceLine V=2k
SYMBOL diode 576 336 R180
WINDOW 0 24 64 Left 2
WINDOW 3 -14 -6 VRight 1
SYMATTR InstName D5
SYMATTR Value 1N4007
SYMBOL res 1376 224 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 0 56 VBottom 1
SYMATTR InstName R7
SYMATTR Value 1k
SYMBOL res 1360 224 R0
WINDOW 3 36 76 Left 1
SYMATTR InstName R10
SYMATTR Value 1k
SYMBOL res 1184 352 R180
WINDOW 0 -40 66 Left 2
WINDOW 3 -40 45 Left 1
SYMATTR InstName R6
SYMATTR Value 22k
SYMBOL diode 576 224 R180
WINDOW 0 24 64 Left 2
WINDOW 3 -12 50 VLeft 1
SYMATTR InstName D3
SYMATTR Value 1N4007
FLAG 992 272 vcc
FLAG 992 416 0
FLAG 928 416 0
FLAG 992 32 vcc
FLAG 976 192 zero
FLAG 240 208 ac1
FLAG 240 288 ac2
FLAG 656 192 opto_a
FLAG 656 288 opto_k
FLAG 1168 352 0
FLAG 1296 272 0
FLAG 1616 144 out
FLAG 1200 224 div
FLAG 1488 336 0
FLAG 1584 336 0
FLAG 1376 336 0
FLAG 1104 352 0
TEXT 208 128 Left 2 !.tran 50m
TEXT 1688 16 Left 2 ;# python code for positive feedback resistor calculation\n# http://www.labbookpages.co.uk/electronics/resNetworks/comparator.html\nprint ('Positive feedback resistor')\n \nvthu = 4.8\nRu   = 10e3\nRl   = 22e3\nvref = 5.0\nvout_max = 3.3\n \nnum = (Ru*vout_max) - ((vthu/Rl)*(Ru+Rl))\nden = ((vthu/Rl)*(Ru+Rl)-vref)\n \nRfb = num/den\n \nprint(f'Rfb = {Rfb}') # Rfb = 16647.853211009176