I could not expand your project, would you do the following?
(1) Select the project in Workspace Explorer
(2) Build > clean <theProject>
(3) Project > Archive Workspace/Project...
(4) Attach the result <theProject>.zip to your post
Thank you for the updated attachment!
I downloaded you project and I could open it this time.
As the project has much more than the comparator,
I excerpted only the comparator related part.
When I tested this, yes the output of Comp_1 was always 1 when echo pin (P0) is open.
Then I took a look at the config of echo
The echo input is High impedance analog and the initial drive state is set to 0.
But since the physical pin is open (not connected) the value of the input is
at the mercy of the environment and/or board configuration.
When I measured the voltage at P0 with my cheap multi-meter,
it read about 2.0V, no wonder the comparator reports high.
Needless to say, when I connect P0 to GND with a jumper wire, the comparator reported low.
So if you want to have some certain value from the comparator,
the echo pin must be connected to GND or some other signal.
Hi, thanks for the quick replies.
The echo pin is actually connected to one of the pins of ultrasonic receiver, while the other is connected to ground but even then the comparator still constantly outputs a logic high unless i set the vref to 4v which is much higher than the noise i measured. And even when i disconnect my echo from the comparator in the schematic, the comparator still outputs a logic high when there is no input on vin.
And also when i printed my echo pin input state when comparator is logic high it shows my echo pin is 0, how could a comparator output 1 when both vin amd vref is 0
> The echo pin is actually connected to one of the pins of ultrasonic receiver,
Now, the story is totally different!
So I used my resistor ladder to test the behavior of your circuit,
when reference was 1.020v, the comparator generated 1 even for 0.3V input,
but generated 0 when input is 0V.
Then I modified the schematic as below to see the output of PGA_1
When echo (= vin) was 0.5V, Vout was 2.4v or so!
So I looked in the configuration of PGA_1
Yes, you set the Gain = 4, which is 4x of input voltage will be output.
So I changed the Gain = 1
Now Vout_1 was within 0.1V different from the actual input.
So, I hope that with this configuration,
you will get more reasonable reaction from the comparator. (Fingers crossed)
P.S. Oops, in my attached project, the Range of VDAC8_1 was still 0-4.08V.
Please change it to 0-1.02 if you need it.