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

NRF52 S123 QDEC sample period - SDK 12.2.0

I am developing an application which involves control of a brushed DC motor with a quadrature encoder. According to this post, in SDK 12.2.0 - which I am using - it is possible to set the sample period to 128 us rather than the 512 us minimum reported in the linked post. I find that I am still only able to set the sample rate to 512 us and still have my application work. My scope does not show pulses on the LED pin associated with the encoder at sample rates below 512.

devzone.nordicsemi.com/.../

Is there a workaround? Do I need to migrate to SDK 13?

nrf_gpio_cfg_input(5, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(6, NRF_GPIO_PIN_PULLUP);

nrf_qdec_sampleper_t sampleperiod = QDEC_SAMPLEPER_SAMPLEPER_128us;
nrf_qdec_reportper_t reportperiod = QDEC_REPORTPER_REPORTPER_10Smpl;

nrf_drv_qdec_config_t m_qdec = NRF_DRV_QDEC_DEFAULT_CONFIG;
m_qdec.sampleper = sampleperiod;
m_qdec.reportper = reportperiod;
m_qdec.psela = 5;
m_qdec.pselb = 6;
m_qdec.pselled = 3;
nrf_drv_qdec_init(&m_qdec, qdec_event_handler);
nrf_drv_qdec_enable();

And my event handler:

static void qdec_event_handler(nrf_drv_qdec_event_t event)
   {
   if (event.type == NRF_QDEC_EVENT_REPORTRDY)
    {
	m_accread += nrf_qdec_accread_get();
    }
  }

This code works fine with a 512 us sampling period, however my encoder transitions states every ~350 us at the normal operating speed of the motor.

I appreciate any help I might receive.

Related