* Z:\home\khalils\Downloads\files\data\raw_asc\6a53f3699621_Compsys305.asc
* Generated by LTspice 26.0.1 for Windows.
* Phototransistor Circuit & Filter circuit
* Voltage Divder Circuit
* Comparator1
* RC filter to convert PWM wave into DC wave
* DC wave to digital Output
* open drain configuration
* The output of comparator 339N is the collector of the bjt... so connect it with a open drain circuit with 5v supply solve the problem, and provide reliable input to the GPIO input pin
R1 N002 0 50k
V2 V5 0 5
R8 V5 GPIO 1k
V3 Vsin 0 SINE(0 1.27 100)
R2 Vfiltered 0 100k
XLM324 Vdc V_halfVolt V5 0 Vout LM324 ;pnba In+)In-)V+)V-)OUT
C1 Vfiltered N002 150nf
R4 V_halfVolt 0 30k
XU2 N003 V_halfVolt V5 0 Vsch LM324 ;pnba In+)In-)V+)V-)OUT
V1 N001 0 5
C2 Vdc 0 150nf
R3 V5 V_halfVolt 270k
R5 Vdc Vsch 100k
I1 N001 N002 SINE(88uA 2uA 100)
D1 Vsin N003 D
.model D D
.lib C:\users\khalils\AppData\Local\LTspice\lib\cmp\standard.dio
.tran 0 1 0 0.1ms
.lib LM324.lib
.backanno
.end

* LTspice schematic (.asc):
Version 4
SHEET 1 4220 680
WIRE -400 -224 -752 -224
WIRE 96 -224 -16 -224
WIRE 96 -208 96 -224
WIRE -1312 -176 -1360 -176
WIRE -752 -160 -752 -224
WIRE -16 -160 -16 -224
WIRE 1040 -160 1040 -192
WIRE -400 -144 -400 -224
WIRE 960 -144 944 -144
WIRE 1008 -144 960 -144
WIRE 1712 -144 1536 -144
WIRE 1888 -144 1792 -144
WIRE 1920 -144 1888 -144
WIRE 2672 -144 2672 -192
WIRE -752 -128 -752 -160
WIRE 1264 -128 1072 -128
WIRE 2640 -128 2592 -128
WIRE 96 -112 96 -128
WIRE 224 -112 96 -112
WIRE 368 -112 288 -112
WIRE 496 -112 368 -112
WIRE 848 -112 784 -112
WIRE 1008 -112 912 -112
WIRE 2848 -112 2704 -112
WIRE 3344 -112 3344 -192
WIRE -1360 -96 -1360 -176
WIRE 1888 -96 1888 -144
WIRE 2640 -96 2352 -96
WIRE 96 -80 96 -112
WIRE 368 -80 368 -112
WIRE 1040 -48 1040 -96
WIRE 2672 -48 2672 -80
WIRE -400 -32 -400 -64
WIRE -304 -32 -400 -32
WIRE 3440 -32 3344 -32
WIRE -400 -16 -400 -32
WIRE 1888 0 1888 -32
WIRE -16 32 -16 -80
WIRE 32 32 -16 32
WIRE 96 32 96 0
WIRE 96 32 32 32
WIRE 368 32 368 0
WIRE 368 32 96 32
WIRE -1360 48 -1360 -16
WIRE 32 64 32 32
WIRE -752 80 -752 -48
WIRE -400 80 -400 64
WIRE -400 80 -752 80
WIRE -752 128 -752 80
SYMBOL OpAmps\\opamp2 1040 -192 R0
SYMATTR InstName U2
SYMATTR Value LM324
SYMBOL voltage -1360 -112 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V3
SYMATTR Value SINE(0 1.27 100)
SYMBOL diode 848 -96 R270
WINDOW 0 32 32 VTop 2
WINDOW 3 0 32 VBottom 2
SYMATTR InstName D1
SYMBOL res 1808 -160 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R5
SYMATTR Value 100k
SYMBOL res 3328 -128 R0
SYMATTR InstName R8
SYMATTR Value 1k
SYMBOL res -416 -32 R0
SYMATTR InstName R4
SYMATTR Value 30k
SYMBOL res -416 -160 R0
SYMATTR InstName R3
SYMATTR Value 270k
SYMBOL cap 288 -128 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C1
SYMATTR Value 150nf
SYMBOL current 96 -208 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName I1
SYMATTR Value SINE(88uA 2uA 100)
SYMBOL OpAmps\\opamp2 2672 -176 R0
WINDOW 3 16 60 Left 2
SYMATTR Value LM324
SYMATTR InstName LM324
SYMBOL res 80 -96 R0
SYMATTR InstName R1
SYMATTR Value 50k
SYMBOL cap 1872 -96 R0
SYMATTR InstName C2
SYMATTR Value 150nf
SYMBOL res 352 -96 R0
SYMATTR InstName R2
SYMATTR Value 100k
SYMBOL voltage -16 -176 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V1
SYMATTR Value 5
SYMBOL voltage -752 -144 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V2
SYMATTR Value 5
FLAG 32 64 0
FLAG 496 -112 Vfiltered
FLAG -752 128 0
FLAG 1040 -48 0
FLAG 784 -112 Vsin
FLAG 1264 -128 Vsch
FLAG 1040 -192 V5
FLAG -752 -160 V5
FLAG 960 -144 V_halfVolt
FLAG -304 -32 V_halfVolt
FLAG -1360 48 0
FLAG -1312 -176 Vsin
FLAG 1888 0 0
FLAG 1536 -144 Vsch
FLAG 1920 -144 Vdc
FLAG 2672 -192 V5
FLAG 2672 -48 0
FLAG 2848 -112 Vout
FLAG 2592 -128 V_halfVolt
FLAG 2352 -96 Vdc
FLAG 3344 -192 V5
FLAG 3440 -32 GPIO
FLAG 3344 48 0
FLAG 3344 16 Vout_bjt
TEXT -48 88 Left 2 !.tran 0 1 0 0.1ms
TEXT 40 -296 Left 2 ;Phototransistor Circuit & Filter circuit
TEXT -656 -304 Left 2 ;Voltage Divder Circuit
TEXT -88 336 Left 2 !.lib LM324.lib
TEXT 880 -256 Left 2 ;Comparator1
TEXT 1544 -272 Left 2 ;RC filter to convert PWM wave into DC wave
TEXT 2496 -264 Left 2 ;DC wave to digital Output
TEXT 3248 -256 Left 2 ;open drain configuration
TEXT 2136 168 Left 2 ;The output of comparator 339N is the collector of the bjt... so connect it with a open drain circuit with 5v supply solve the problem, and provide reliable input to the GPIO input pin