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

How long does the COMP (comparator) take to finish a sample?

Hello,

I use nRF52832's  COMP (comparator) to sample a pulse signal's voltage level.

I found when the pusle width is below like about 60us, the COMP can't get correct result, however, when the pulse width is longer than 60us, the COMP can get correct result.

I use "nrf(x)_comp_sample()" API of SDK 17.02 to do the job.

The COMP init code is like this:

static void comp_init(void)
{
    ret_code_t err_code;
    nrf_drv_comp_config_t m_comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_3);

    /* Workaround for Errata 12 "COMP: Reference ladder is not correctly calibrated" */
    *(volatile uint32_t *)0x40013540 = (*(volatile uint32_t *)0x10000324 & 0x00001F00) >> 8;

	m_comp_config.reference = NRF_COMP_REF_Int1V2;
	m_comp_config.threshold.th_down = VOLTAGE_THRESHOLD_TO_INT(0.8, 1.2);
	m_comp_config.threshold.th_up = VOLTAGE_THRESHOLD_TO_INT(1.0, 1.2);
	m_comp_config.speed_mode = NRF_COMP_SP_MODE_Low;

    err_code = nrf_drv_comp_init(&m_comp_config, comp_event_handler);
    APP_ERROR_CHECK(err_code);

    nrf_comp_shorts_disable(UINT32_MAX);
    nrf_comp_int_disable(UINT32_MAX);
}

CPU is calling "nrf_drv_comp_sample();" to do the sample job.

The datasheet says the propagation delay in low-power mode takes 0.6us, I wonder what's wrong with the code?

Please share any thoughts, thanks in advance!

Parents
  • Hello,

    Thank you for your patience with this.

    You are correct that the startup of the COMP peripheral might take some time, but subsequent sampling (following the READY event) will adhere to the propagation delay for each speed mode, as listed in the electrical specifications. If you do not stop the COMP after this it will be ready for sampling, which you may trigger with the TASKS_SAMPLE task through PPI.

    Could you share some more of the code in which you use this COMP? Do I understand you correctly that you are stopping the COMP peripheral inbetween each sampling, and starting it each time a pulse is detected on a pin?

    Best regards,
    Karl

Reply
  • Hello,

    Thank you for your patience with this.

    You are correct that the startup of the COMP peripheral might take some time, but subsequent sampling (following the READY event) will adhere to the propagation delay for each speed mode, as listed in the electrical specifications. If you do not stop the COMP after this it will be ready for sampling, which you may trigger with the TASKS_SAMPLE task through PPI.

    Could you share some more of the code in which you use this COMP? Do I understand you correctly that you are stopping the COMP peripheral inbetween each sampling, and starting it each time a pulse is detected on a pin?

    Best regards,
    Karl

Children
  • Thank you for reply.

    Yes, I start the COMP, sample and stop in a signal processing period, because I found that doing so has less power consumption than always leaving the COMP starting (not stoping it). My signal input rate is 10Hz, which means the rate I start the COMP and stop it is 10Hz in this case.

    I also found that the startup of COMP peripheral takes about 60us? the tINT_REF,START (Startup time for the internal bandgap reference, 50-80us) is involved in the COMP startup process. is this correct? 

    Thank you.

  • gilbertjuly said:
    Thank you for reply.

    No problem at all, I am happy to help!

    gilbertjuly said:
    I also found that the startup of COMP peripheral takes about 60us? the tINT_REF,START (Startup time for the internal bandgap reference, 50-80us) is involved in the COMP startup process. is this correct? 

    Yes, if you use the internal references, the startup time will typically be 50 µs, maximally 80 µs. This is the time it takes to setup the internal references, and have them reach their steady states.

    The relevant section of the COMP documentation reads:

    The delay between START and READY is tINT_REF,START if an internal reference is selected, or t COMP,START if an external reference is used.

    So if you need to reduce the startup time in order to save power, could it be an option to use an external reference?

    Best regards,
    Karl

  • Thank you, Karl.

    I'm developing a compact wearable device, so there is no space for an external reference. Slight smile

Related