How do I set a driver for the Analog Comparitor in e2 studio?

I see there is a comparitor function in the S3A7 manual, but do not find a driver for it in e2 studio.  There is a section in the pin configuration peripherals for configuring the AnalogCMP.  Am I missing something? Is this function yet to be added?

  • Hi Pete,

    Currently there is no HAL driver for Analog Comparator in SSP, Renesas will possibly add the driver in the next major SSP release. For now you should access ACMPHS or ACMPLS registers directly, for example:

    // Low Power Analog Comparator
    // High-Speed Analog Comparator Channel 0
    R_ACMPHS0->CMPCTL_b.COE = 1;
    // High-Speed Analog Comparator Channel 1
    R_ACMPHS1->CMPCTL_b.COE = 1;

  • In reply to adboc:

    Hi adboc,

    I don't see driver for high speed analog comparator in SSC 6.2.1 with SSP 1.5.0-rc1. I can see HAL driver in components tab, and can add it to my project, however. Is analog comparator support still unfinished in SSP? Where can I find examples on ACMPHS usage? I need to compare analog signal to DAC output.

    Best regards,
  • In reply to Eighth:

    Hi Eighth-
    Make sure you have an MCU selected that supports the analog comparator- like the S1JA. Also- note that the S1JA needs to use the IAR compiler based on the description on the SSP 1.5.0 Important Notices section. Follow instructions to link the IAR compiler to e2 studio.

    Kits with the S1JA on it should be available within a couple of months, when the device is released.

  • In reply to Eighth:

    Hi Eighth,

    Analog comparator drivers are currently for S1JA only, hence you're not able to add them on the "Threads" tab.

    I'm attaching a basic example for low power comparator using manual configuration:


  • In reply to Renesas Karol:

    Hi Karol,

    Thank you! I'll be grateful for a bit more help on my case.

    I use custom board with S5D9 (R7FS5D97E3A01CFP) chip, IAR 8.21, SSC 6.2.1 and SSP 1.5.0-rc1.

    I need to detect short impulse of analog signal on pin P006. I planning to do it using ACMPHS with reference voltage from DAC. After detection of this impulse I need to perform ADC measurements on some other pins.

    My proof-of-concept code:


    ssp_err_t err;

    void comp_hs_int_isr(void);
    SSP_VECTOR_DEFINE_CHAN(comp_hs_int_isr, COMP_HS, INT, 5);

    void init(void)
      const uint16_t threshold = 2120;

      err = g_adc0.p_api->open(g_adc0.p_ctrl, g_adc0.p_cfg);
      err = g_adc0.p_api->scanCfg(g_adc0.p_ctrl, g_adc0.p_channel_cfg);
      err = g_dac0.p_api->open(g_dac0.p_ctrl, g_dac0.p_cfg);
      err = g_dac0.p_api->write(g_dac0.p_ctrl, threshold);
      err = g_dac0.p_api->start(g_dac0.p_ctrl);
      /* These variables are used to set the ISR in the ICU & NVIC */
      ssp_feature_t       ssp_feature = {{(ssp_ip_t) 0}};
      fmi_event_info_t    event_info  = {(IRQn_Type) 0U};

      /* Enable the HS COMP interrupt */ = 5;
      ssp_feature.unit    = 0U;      = SSP_IP_COMP_HS;

      /* Get the interrupt vector offset */
      err = g_fmi_on_fmi.eventInfoGet(&ssp_feature, SSP_SIGNAL_COMP_HS_INT, &event_info);

      /* Clear and enable the interrupt */
      err = R_BSP_ModuleStart(&ssp_feature);

      /* Set input */
      R_ACMPHS5->CMPSEL0 = 4; // Use IVCMP2

      /* Set reference */
      R_ACMPHS5->CMPSEL1 = 8; // Use VREF3 (DA0)
      R_ACMPHS5->CPIOC = 0; // Disable internal Vref and comparator output
      R_ACMPHS5->CMPCTL = 2 + 8 + 32 + 64; // filter 2^5, rising edge, no output
      NVIC_SetPriority(event_info.irq, 8);    /* Specify the interrupt priority 0 - 15 */
      R_ACMPHS5->CMPCTL |= 128; // enabled


    void comp_hs_int_isr(void)
      uint32_t uPeak;
      uint32_t peak;
      uint16_t buf;
      /* Save context if RTOS is used */

      /* Clear pending IRQ to make sure it doesn't fire again after exiting */

      uPeak = 0;
      peak = 0;
      for (uint32_t i = 0; i < 32; i++)
        err = g_adc0.p_api->scanStart(g_adc0.p_ctrl);
        while ((err = g_adc0.p_api->scanStatusGet(g_adc0.p_ctrl)) != SSP_SUCCESS);
        g_adc0.p_api->read(g_adc0.p_ctrl, ADC_REG_CHANNEL_3, &buf);
        uPeak += buf;
        g_adc0.p_api->read(g_adc0.p_ctrl, ADC_REG_CHANNEL_6, &buf);
        peak += buf;
      uPeak /= 32;
      peak /= 32;

      /* Restore context if RTOS is used */


    Code does not working as I expected. ISR invoked exactly two times at the start of the program and never after that, no matter what voltage on P006 is. What is wrong?


    Best regards,


  • In reply to Eighth:

    Hi Eighth-
    You might find it helpful to use Visual Expressions to observe the analog voltages in your project. A good example of how to do this is available in this Knowledge Base article. It also uses the Analog Comparator (the low power version however) so that might also help you check on some initialization settings.

    (Link fixed per below comment) 


  • In reply to WarrenM:

    Hi Warren,

    I'm sorry but it seems like you linked wrong article. Did you mean ? I'll check it out, thank you. However, examples on ACMPHS (and even better, pairing with DAC and timers) would be a lot more helpful.

    Best regards,


  • In reply to Eighth:

    Hello Eighth,

    I may have spotted some issues that cause the malfunction of this peripheral:
    * You're setting interrupt priority level after it's enabled.
    * IRQ is enabled in the NVIC after peripheral is enabled.
    * Your application is performing extensive ISR processing (while(1) blocking) - you can use comparator interrupt as a trigger to start ADC conversion and ADC scan end interrupt in turn could trigger a transfer of the results to your designated area in memory.

    I'm attaching a working example for ACMPHS on S5D9-based PK-S5 board: