Files
microchip-application-pec93…/pec930_sdk-v1.0.1/Examples/comp/comp_src_io
2026-04-03 00:03:29 +08:00
..
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00
2026-04-03 00:03:29 +08:00

comp_src_io

This example is used to run comparator with sources from I/O

  • VinP (Input-plus type of the Comparator) support 4 I/O sources

    I/O 0 ~ 4 type

    • PEC930
      • I/O 0: PA8
      • I/O 1: PA11
      • I/O 2: PA14
      • I/O 3: PA15
  • VinM (Input-minus type of the Comparator) only support 1 I/O source

    • COMP_0: PA6
    • COMP_1: PA12

Use interrupt/polling mode

// at main.c
/**
 *  + Use polling mode when CONIFG_USE_COMP_INTERRUPT = 0
 *  + Use interrupt mode when CONIFG_USE_COMP_INTERRUPT = 1
 */
#define CONIFG_USE_COMP_INTERRUPT           0

Select the target COMP module

// at main.c
/**
 *  Use COMP0 or COMP1
 *  ps. Use the COMP0 when unmark
 *      Use the COMP1 when mark
 */
#define CONFIG_USE_COMP0

Select the target I/O type of VinP

// at main.c
/**
 *  Select the target I/O type of VinP
 *  + Use I/O 0 as VinP if CONIFG_TERGET_COMP_VinP_IO_IDX is 0
 *  + Use I/O 1 as VinP if CONIFG_TERGET_COMP_VinP_IO_IDX is 1
 *  + Use I/O 2 as VinP if CONIFG_TERGET_COMP_VinP_IO_IDX is 2
 *  + Use I/O 3 as VinP if CONIFG_TERGET_COMP_VinP_IO_IDX is 3
 */
#define CONIFG_TERGET_COMP_VinP_IO_IDX      0

Select the interrupt types

  • COMP triggers the rising event when VinP > VinM
  • COMP triggers the falling event when VinP < VinM
// at main.c
/**
 *  Configure status flags of COMP
 *  + COMP_IE_Falling
 *  + COMP_IE_Rising
 */
#define CONFIG_COMP_WATCH_STATE         (COMP_IE_Rising | COMP_IE_Falling)

Operation flow

  • Step 1. Connect the I/O of VinP (CONIFG_TERGET_COMP_VinP_IO_IDX) and VinM with an external device (e.g. power support) which provide difference voltage
  • Step 2. Respectively, set the specific voltage to external device (e.g. power support) to link the I/O of VinP and VinM
  • Step 3. Modify the VinP voltage of external device (e.g. power support)
  • Step 4. Observe the message has match the relation of VinP and VinM or not

Log

Use serial port with baudrate 115200, 8bit, no parity check.

  • Polling mode

    modify VinP voltage with external device

    Dec 19 2025 16:19:55
    COMP0 compares the voltage from I/O
       COMP Vin+ = PA8
       COMP Vin- = PA6
      The target status (Rising/Falling) of COMP
    
      @COMP Event
      Get (Rising edge) Vin+ > Vin-
    
      @COMP Event
      Get (Falling edge) Vin+ < Vin-
    
      @COMP Event
      Get (Rising edge) Vin+ > Vin-
    
      @COMP Event
      Get (Falling edge) Vin+ < Vin-
    
      @COMP Event
      Get (Rising edge) Vin+ > Vin-
    
  • Interrupt mode

    modify VinP voltage with external device

    • Rising and Falling events

      Dec 19 2025 15:27:53
      COMP0 compares the voltage from I/O
         COMP Vin+ = PA8
         COMP Vin- = PA6
        The target status (Rising/Falling) of COMP
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
        @COMP Event
        Get (Falling edge) Vin+ < Vin-
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
        @COMP Event
        Get (Falling edge) Vin+ < Vin-
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
    • Rising event

      Dec 19 2025 16:16:33
      COMP0 compares the voltage from I/O
         COMP Vin+ = PA8
         COMP Vin- = PA6
        The target status (Rising/-) of COMP
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
        @COMP Event
        Get (Rising edge) Vin+ > Vin-
      
    • Falling event

      Dec 19 2025 16:18:40
      COMP0 compares the voltage from I/O
         COMP Vin+ = PA8
         COMP Vin- = PA6
        The target status (-/Falling) of COMP
      
        @COMP Event
        Get (Falling edge) Vin+ < Vin-
      
        @COMP Event
        Get (Falling edge) Vin+ < Vin-
      
        @COMP Event
        Get (Falling edge) Vin+ < Vin-