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

How to accurately measure active USB current on nRF52840?

I am using nRF52840 Preview DK (0.12.0) and I want to measure USB currents. I am using the DK as a starting point for doing measurements on custom HW and verifying that we get the same measurements there.

I used the usbd_cdc_acm example from the SDK (15.0.0) as a starting point. My main function is:

   

int main(void)
{
    NRF_P0->DIRSET = 0xFFFFFFFC;
    NRF_P0->OUTCLR = 0xFFFFFFFC;
    NRF_P1->DIRSET = 0xFFFFFFFF;
    NRF_P1->OUTCLR = 0xFFFFFFFF;
   
    ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    
    app_usbd_serial_num_generate();

    ret = app_usbd_init(&usbd_config);
    APP_ERROR_CHECK(ret);

    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
    ret = app_usbd_class_append(class_cdc_acm);
    APP_ERROR_CHECK(ret);

    ret = app_usbd_power_events_enable();
  
    size_t size = sprintf(m_tx_buffer, "a");
    
    while (true)
    {
       while (app_usbd_event_queue_process())
        {
            // Nothing to do
        }
        
        app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
    }
}

All it does is spew 'a' as fast as possible (I think). However, the measurement I get swings between 6.8mA and 7.9mA. I think on average it matches what the spec suggests, but I was wondering if there is a better way to measure this active current?

Related