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

Dependence between connection interval parameter and QDEC

Hi,

I have question related with some parameters of BLE transmision.

Connection interval in my project is set to 10 ms. Peripheral sends a notifications whenever the value of characteristic is changing - this interval is also set to 10 ms. So, I send one notification per single connection interval.

Whats more, I use a QDEC in my project (simplerdy mode) and I set pin P0.03 as a QDEC LED output to generate synchronized clock impulses.

I captured connectionless BLE link from one device to another. Please see a screenshot below:

image description

This is how looks waveform in that configuration - first and second lines are A and B signals from encoder, third is a sampling clock generated by the LED output:

image description

When I disable notification waveform looks like this:

image description

My main question is about LED output on these traces. They are generated according to parameters which I set in nrf_drv_config.h file. However in some periodic, regular intervals the line is hold for a some time in a high state. I guess that this is related with communication and connection interval. If the notifications are set, this time is around 0.9 ms, when they are not, the time is around 0.4 ms (connection interval parameter is still set to 10 ms). You can see these times on above waveforms.

This generates a problem for me, because I cannot count a encoder changes while LED output helds a high state.

Is it okay, that this occurs? Is it possible to decrease these times, if yes, how can I do that?

  • Looks definitely like the SoftDevice is interrupting the LED output, even though this is strange. Can you post the code you use for the setup of QDEC?

  • Thanks for your response. My qdec_event_handler function is simple and looks like that:

    static void qdec_event_handler(nrf_drv_qdec_event_t event)
    
     { 
    
     if (event.type == NRF_QDEC_EVENT_SAMPLERDY)
    
     { 
    
    m_report_ready_flag = true;
    
    nrf_drv_qdec_disable();
    
     }
     
    }
    

    I update a value of characteristic in timer handler which is calling every 10 ms. There I use a nrf_drv_qdec_accumulators_read() method and write these values to correct variable. QDEC configuration looks like this:

    define QDEC_CONFIG_REPORTPER NRF_QDEC_REPORTPER_DISABLED
    
    define QDEC_CONFIG_SAMPLEPER NRF_QDEC_SAMPLEPER_2048us
    
    define QDEC_CONFIG_PIO_A 1
    
    define QDEC_CONFIG_PIO_B 2
    
    define QDEC_CONFIG_PIO_LED 3
    
    define QDEC_CONFIG_LEDPRE 10
    
    define QDEC_CONFIG_LEDPOL NRF_QDEC_LEPOL_ACTIVE_LOW
    
    define QDEC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    define QDEC_CONFIG_DBFEN false
    
    define QDEC_CONFIG_SAMPLE_INTEN true
    
  • So you are disabling the qdec in the interrupt, why? I guess you are enabling it somewhere else in the code or else the LED output would be constantly low. If you enable in the while loop in main you will get the LED output on your traces because the SoftDevice may interrupt the code between disable and enable functions. It should not be necessary to disable and enable the qdec like you do.

  • Indeed, I enable qdec in infinite for loop in main - I followed a qdec example code. So, I shouldn't disable it by SAMPLERDY event in qdec handler and enable it once in main function?

  • How should this look like according to you? If I enable qdec only once in main and do not disable it in my code - I get then a strange measurements. The encoder linked to motor which I use generates 100 counts per turn, so there should occur 400 state changes - accumulated ACC value should be 400 per one turn. Before then, I got it corretly, but now the value is around 185.

    What about a m_report_ready_flag? Should I set it in qdec handler or not? In while loop (in main) I wait for a report this way:

    while (! m_report_ready_flag) { __WFE(); }

    How should look like a qdec handler function for my purpose? Thank you for your answers and please, help me with this. There is a little bit information how it works, even in infocenter.

Related