Comparator module initializing (pic16f877a)

Thread Starter

Wlillian

Joined Sep 8, 2021
26
In fact this is what the actual circuit is supposed to look like
But in the actual circuit, it gives only low signals for the comparator outputs whenthe input to C2 is bove the reference while C1 is below it, but gives a high output for C2 and a low for C1 when input to C1 is above the reference and that to C2 is below the reference.
 

click_here

Joined Sep 22, 2020
548
Your schematic show a pull down resistor, not a pull up.

But in the actual circuit, it gives only low signals for the comparator outputs whenthe input to C2 is bove the reference while C1 is below it, but gives a high output for C2 and a low for C1 when input to C1 is above the reference and that to C2 is below the reference.
Are you talking about the the RA4/5 output pins, or the CMCON.CxOUT bits?

And is it still working if you don't invert the outputs?
 

Thread Starter

Wlillian

Joined Sep 8, 2021
26
Your schematic show a pull down resistor, not a pull up.


Are you talking about the the RA4/5 output pins, or the CMCON.CxOUT bits?

And is it still working if you don't invert the outputs?
I was meaning RA4/5. But I thought they are the Comparator outputs.
Even if I don't invert it is still giving the same outputs and another challenge is that I don't know why the stepper motor is not rotating. The code and schematic are shown below.
 

Attachments

click_here

Joined Sep 22, 2020
548
If you can't get your leds to light up correctly with your simple example, why would the PORTB outputs work with your next circuit?

Don't set bits CMCON.CxINV individually like that because you immediately write over it with
Code:
CMCON=0x05;
If you want to set the INV bits, just change your code to this...
Code:
CMCON=0b00110101;
// or
CMCON=0x35;
 

Thread Starter

Wlillian

Joined Sep 8, 2021
26
If you can't get your leds to light up correctly with your simple example, why would the PORTB outputs work with your next circuit?

Don't set bits CMCON.CxINV individually like that because you immediately write over it with
Code:
CMCON=0x05;
If you want to set the INV bits, just change your code to this...
Code:
CMCON=0b00110101;
// or
CMCON=0x35;
Thank you, CMCON gives the right output at the port B thus it continues to indicates the signals at RA4/5 as low signals when the input of C1 is above the reference voltage while that at C2 is below.
I would like to inquire about what is preventing the stepper motor from rotating.
 
Top