<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Using comparator functions in Zephyr and NRF Connect</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77741/using-comparator-functions-in-zephyr-and-nrf-connect</link><description>Although my Googling skills are not the best I have, so far, been unable to find any examples or driver documentation for the comparator peripheral of the nRF52840 for the nRF Connect SDK. Everything I have found is centred around the nRF5 SDK. 
 One</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 22 Jul 2021 09:55:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77741/using-comparator-functions-in-zephyr-and-nrf-connect" /><item><title>RE: Using comparator functions in Zephyr and NRF Connect</title><link>https://devzone.nordicsemi.com/thread/321291?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 09:55:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed30fbeb-0325-438a-b50b-5de6a032b005</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is part of the nrfx drivers, so you can find the documentation for the functions here:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/comp/hal.html"&gt;COMP HAL&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can find NRF_COMP_Type in some of the files under &lt;em&gt;&amp;lt;NCS_root&amp;gt;&lt;/em&gt;/modules/hal/nordic/nrfx/mdk, such as nrf52840.h.&lt;/p&gt;
&lt;p&gt;Unfortunately, there are no examples of the functions you mention being in use in NCS besides what is in the HAL module, but in the file&amp;nbsp;&lt;em&gt;&amp;lt;NCS_root&amp;gt;&lt;/em&gt;/modules/hal/nordic/nrfx/drivers/src/nrfx_comp.c you can see them being used there. Most of them are only used in the function that initializes the COMP driver,&amp;nbsp;nrfx_comp_init():&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_err_t nrfx_comp_init(nrfx_comp_config_t const * p_config,
                          nrfx_comp_event_handler_t  event_handler)
{

...

    nrf_comp_ref_set(NRF_COMP, p_config-&amp;gt;reference);

    //If external source is chosen, write to appropriate register.
    if (p_config-&amp;gt;reference == COMP_REFSEL_REFSEL_ARef)
    {
        nrf_comp_ext_ref_set(NRF_COMP, p_config-&amp;gt;ext_ref);
    }
    
    nrf_comp_th_set(NRF_COMP, p_config-&amp;gt;threshold);
    nrf_comp_main_mode_set(NRF_COMP, p_config-&amp;gt;main_mode);
    nrf_comp_speed_mode_set(NRF_COMP, p_config-&amp;gt;speed_mode);
    nrf_comp_hysteresis_set(NRF_COMP, p_config-&amp;gt;hyst);
    
    ...
    
    nrf_comp_input_select(NRF_COMP, p_config-&amp;gt;input);

    nrf_comp_enable(NRF_COMP);
    
    ...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As you can see, they simply use NRF_COMP as the first parameter, &lt;span&gt;NRF_COMP_Type&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;em&gt;&lt;span&gt;p_reg&lt;/span&gt;&lt;/em&gt;, and the second parameter, which depends on the function, comes from p_config. You can find these COMP configurations,&amp;nbsp;nrfx_comp_config_t, in &lt;em&gt;&amp;lt;NCS_root&amp;gt;&lt;/em&gt;/modules/hal/nordic/nrfx/drivers/include/nrfx_comp.h.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>