nRF52820 & NCS v1.9.0 , use comp to monitor voltage

Hello,

We are using NCS v1.9.0 and nRF51820 SoC in our project.

Here is a question about using the COMP function.After I configure and initialize COMP,it returns NRFX_SUCCESS.But when I using function nrfx_comp_start() or nrfx_comp_sample(),the device restarts.I can only find one example of LPCOMP in nRF5 SDK,and I did it like that.Are there any additional steps before configuring COMP?

Below is my code:

CONFIG_NRFX_COMP=y
CONFIG_NRFX_PRS=y

static nrfx_comp_config_t comp_conf = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_3);

void comp_triggered(nrf_comp_event_t event)
{
    switch (event)
    {
    case NRF_COMP_EVENT_READY:
        printk("comp triggered ready.\r\n");
        break;
    case NRF_COMP_EVENT_DOWN:
        printk("comp triggered down.\r\n");
        break;
    case NRF_COMP_EVENT_UP:
        printk("comp triggered up.\r\n");
        break;
    case NRF_COMP_EVENT_CROSS:
        printk("comp triggered cross.\r\n");
        break;

    default:
        break;
    }
}

void battery_monitor_init(void)
{
    int ret;

    ret = nrfx_comp_init(&comp_conf, comp_triggered);
    if (ret != NRFX_SUCCESS)
    {
        return;
    }
    nrfx_comp_start(NRFX_COMP_EVT_EN_CROSS_MASK |
                        NRFX_COMP_EVT_EN_UP_MASK |
                        NRFX_COMP_EVT_EN_DOWN_MASK |
                        NRFX_COMP_EVT_EN_READY_MASK,
                    NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT);
}

Parents
  • Hello,

    when I using function nrfx_comp_start() or nrfx_comp_sample(),the device restarts.I can only find one example of LPCOMP in nRF5 SDK,and I did it like that.Are there any additional steps before configuring COMP?

    What does your logger output when the device restarts? Does the restart happens immediately when you call nrfx_comp_start or nrfx_comp_sample?
    Is there anything else going on concurrently in your application when you are testing this?

    Best regards,
    Karl

  • Hello,

    I continued testing for a few more rounds, during which time I blocked other unrelated features.So there should be no other functions running at the same time.

    The device does not restart until some time after nrfx_comp_start is called,because debugging shows that the program will stay in the empty loop of main().When the device restarts, the logger only outputs the boot information, as shown in the figure:

    Sorry, I described it wrong yesterday.In fact, when nrfx_comp_sample is called, the device will not restart.And When I call nrfx_comp_sample it always returns 0,although the input voltage is greater than the threshold.

    static nrfx_comp_config_t comp_conf =
        {
            .reference = NRF_COMP_REF_Int2V4,
            .main_mode = NRF_COMP_MAIN_MODE_SE,
            .threshold = {
                .th_down = NRFX_VOLTAGE_THRESHOLD_TO_INT(1.5, 2.4),
                .th_up = NRFX_VOLTAGE_THRESHOLD_TO_INT(2.0, 2.4),
            },
            .speed_mode = NRF_COMP_SP_MODE_High,
            .hyst = NRF_COMP_HYST_NoHyst,
            .input = NRF_COMP_INPUT_3,
            .interrupt_priority = NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY,
    };

  • Hello again,

    Thank you for elaborating and clarifying.

    funong said:
    The device does not restart until some time after nrfx_comp_start is called,because debugging shows that the program will stay in the empty loop of main().

    Could it then be that it is resetting for another reason than the nrfx_comp_* calls to begin with?

    funong said:
    Sorry, I described it wrong yesterday.In fact, when nrfx_comp_sample is called, the device will not restart.And When I call nrfx_comp_sample it always returns 0,although the input voltage is greater than the threshold.

    How have you verified the input voltage, and what was that voltage in this particular case?
    which range will your voltage be fluctuating between?

    Best regards,
    Karl

  • Hello,

    Thank you for your reply,I'll check if other configurations cause the reboot.

    Measured directly with a multimeter, the input voltage is about 2.5 volts.The power supply is a button cell, and the voltage has almost no fluctuation.

  • funong said:
    Thank you for your reply,

    No problem at all, I am happy to help! :) 

    funong said:
    I'll check if other configurations cause the reboot.

    Great, I look forward to hearing any updates.

    funong said:
    Measured directly with a multimeter, the input voltage is about 2.5 volts.The power supply is a button cell, and the voltage has almost no fluctuation.

    It seems to me that you have your threshold range from 1.5 to 2.0 V, comparing against the 2.4V reference. In this case, your 2.5 battery should almost always exceed the upper bound, is this intentional? I do not think this is what is causing the issue you describe, but I thought I thought I should mention it.

    Furthermore, it is hard to get a good look at fluctuations in a power source when measuring with a multimeter, since the multimeter will average out the result over a couple of hundred ms, normally.
    The fluctuations in a coin cell battery will primarily happen in the case of a power draw surge, such as when there is a sudden increase in power consumption(RADIO + CPU working concurrently, for example).

    Best regards,
    Karl

Reply Children
No Data
Related