16 Eylül 2017 Cumartesi

Comparator and Fixed Voltage Reference

Comparator function of PIC can compare a voltage at one comparator port to other comparator port. We can create external reference voltages using diodes, zener etc. Other option is to use internal Fixed Voltage Reference (FVR).

Proteus: we will use RA0 (C12IN0-) comparator port for input voltage using a resistor POT. PIC18f24K20 has internal 1.2V fixed voltage reference that we will compare to RA0 port voltage. If the input voltage is above 1.2V, LED will light.


MCC:  add CMP1 and FVR peripherals. start with FVR setting, just enable no other option. Enable comparator, select CVREF (internal 1.2V) as positive input and CIN0- negative input at comparator options. select RC1 as output pin to connect the LED. Select RA0 as CIN0- port for input voltage.     



XC8: we add an if statement inside the while(1) loop. If comparator status is "1",  means that RA0 voltage is above 1.2V, set the LED high, else low. That's so simple.

    while (1)
    {
        // Add your application code
        if (CMP1_GetOutputStatus()){
            IO_RC1_SetHigh();
        } 
        else {
            IO_RC1_SetLow();
        }
            
        
    }


Hiç yorum yok:

Yorum Gönder