/** @brief Function initialization and configuration of QDEC driver instance. */ static void qdec_config(void) { uint32_t err_code; nrf_drv_qdec_config_t qdec_config = NRF_DRV_QDEC_DEFAULT_CONFIG; // Initialize hardware err_code = nrf_drv_qdec_init(&qdec_config, qdec_event_handler); APP_ERROR_CHECK(err_code); printf("QDEC testing started\n"); uart_printf("nrf_drv_qdec_init\n\r"); nrf_drv_qdec_enable(); // Event and corresponding interrupt are enabled. uart_printf("nrf_drv_qdec_enable \n\r"); }
int main(void) { uint32_t err_code; bool forever = true; uint32_t number_of_pulses; uint32_t min_number_of_pulses = 2; uint32_t max_number_of_pulses = 0; int32_t pulses; int32_t sign = 1; err_code = nrf_drv_qdec_init(NULL, qdec_event_handler); APP_ERROR_CHECK(err_code); max_number_of_pulses = nrf_qdec_reportper_to_value(QDEC_CONFIG_REPORTPER); // initialize quadrature encoder simulator qenc_init((nrf_qdec_ledpol_t)nrf_qdec_ledpol_get()); while (forever) { // change a number and sign of pulses produced by simulator in a loop for (number_of_pulses=min_number_of_pulses; number_of_pulses<= max_number_of_pulses; number_of_pulses++ ) { pulses = sign*number_of_pulses; // pulses have sign qenc_pulse_count_set(pulses); // set pulses to be produced by encoder nrf_drv_qdec_enable(); // start burst sampling clock, clock will be stopped by REPORTRDY event while (! m_report_ready_flag) // wait for a report { __WFE(); } m_report_ready_flag = false; check_report(pulses); // check if pulse count is as expected, assert otherwise } min_number_of_pulses = 1; // only first run is specific, for 1 there would be no call back... sign = -sign; // change sign of pulses in a loop } return -1; // this should never happen }