This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using comparator functions in Zephyr and NRF Connect

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 example I looked at has a set of calls to configure it that are all missing a parameter, eg. 

  nrf_comp_ref_set(NRF_COMP_REF_Int1V8);
  nrf_comp_main_mode_set(NRF_COMP_MAIN_MODE_SE);
  nrf_comp_speed_mode_set(NRF_COMP_SP_MODE_High);
  nrf_comp_hysteresis_set(NRF_COMP_HYST_NoHyst);
  nrf_comp_input_select(NRF_COMP_INPUT_0);
  nrf_comp_enable();


It appears that each of these functions now requires a {NRF_COMP_Type *} parameter passed first. I have not found any example or description with this parameter supplied and have so far been unable to find out how I should obtain the relevant pointer address. I imagine this is the memory address for the registers for the comparator being configured but there must be a symbolic way to obtain this that I am just missing.

Where can I find an example of the comparator being used in a Zephyr nRF Connect SDK based application?

Parents
  • Hi,

    This is part of the nrfx drivers, so you can find the documentation for the functions here: COMP HAL.

    You can find NRF_COMP_Type in some of the files under <NCS_root>/modules/hal/nordic/nrfx/mdk, such as nrf52840.h.

    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 <NCS_root>/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, nrfx_comp_init():

    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->reference);
    
        //If external source is chosen, write to appropriate register.
        if (p_config->reference == COMP_REFSEL_REFSEL_ARef)
        {
            nrf_comp_ext_ref_set(NRF_COMP, p_config->ext_ref);
        }
        
        nrf_comp_th_set(NRF_COMP, p_config->threshold);
        nrf_comp_main_mode_set(NRF_COMP, p_config->main_mode);
        nrf_comp_speed_mode_set(NRF_COMP, p_config->speed_mode);
        nrf_comp_hysteresis_set(NRF_COMP, p_config->hyst);
        
        ...
        
        nrf_comp_input_select(NRF_COMP, p_config->input);
    
        nrf_comp_enable(NRF_COMP);
        
        ...

    As you can see, they simply use NRF_COMP as the first parameter, NRF_COMP_Type*p_reg, and the second parameter, which depends on the function, comes from p_config. You can find these COMP configurations, nrfx_comp_config_t, in <NCS_root>/modules/hal/nordic/nrfx/drivers/include/nrfx_comp.h.

    Best regards,

    Marte

Reply
  • Hi,

    This is part of the nrfx drivers, so you can find the documentation for the functions here: COMP HAL.

    You can find NRF_COMP_Type in some of the files under <NCS_root>/modules/hal/nordic/nrfx/mdk, such as nrf52840.h.

    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 <NCS_root>/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, nrfx_comp_init():

    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->reference);
    
        //If external source is chosen, write to appropriate register.
        if (p_config->reference == COMP_REFSEL_REFSEL_ARef)
        {
            nrf_comp_ext_ref_set(NRF_COMP, p_config->ext_ref);
        }
        
        nrf_comp_th_set(NRF_COMP, p_config->threshold);
        nrf_comp_main_mode_set(NRF_COMP, p_config->main_mode);
        nrf_comp_speed_mode_set(NRF_COMP, p_config->speed_mode);
        nrf_comp_hysteresis_set(NRF_COMP, p_config->hyst);
        
        ...
        
        nrf_comp_input_select(NRF_COMP, p_config->input);
    
        nrf_comp_enable(NRF_COMP);
        
        ...

    As you can see, they simply use NRF_COMP as the first parameter, NRF_COMP_Type*p_reg, and the second parameter, which depends on the function, comes from p_config. You can find these COMP configurations, nrfx_comp_config_t, in <NCS_root>/modules/hal/nordic/nrfx/drivers/include/nrfx_comp.h.

    Best regards,

    Marte

Children
No Data
Related