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:




    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,



    Edit: long piece of code removed, see correct code in Karol's response below.

  • 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: