nordic-auko / nRF5-ble-timesync-demo

nRF52 clock synchronization demo code
56 stars 50 forks source link

Updating the pin toggle rate #3

Closed c-j-b closed 4 years ago

c-j-b commented 4 years ago

I'm trying to adapt this example for a different application and would like to use the debug compare event (pin 0.24) to trigger an SAADC measurement.

For now I'm trying to adjust the toggle frequency of the debug pin. Using the peripheral example in this repo, P0.24 toggles with a period of 5 ms. This toggle frequency corresponds to the value set in the CC[0] register (40,000) and not the vale in the CC[4] register (20,000) as configured in the PPI endpoint. If the CC[4] compare is toggling the pin the period should be 2.5 ms.

Can you provide some guidance on how to adjust the pin toggle frequency? I see that there is a CC[0] clear shortcut configured for this timer but I believe that should only occur when the timer reaches a count of 40,000. It seems like the pin is currently toggling when the timer reaches CC[0] and not when it reaches CC[4].

nrf_ppi_channel_endpoint_setup(
        NRF_PPI_CHANNEL0, 
        (uint32_t) nrf_timer_event_address_get(NRF_TIMER3, NRF_TIMER_EVENT_COMPARE4),
        nrf_gpiote_task_addr_get(NRF_GPIOTE_TASKS_OUT_3));
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL0);
static void sync_timer_start(void)
{
    // m_params.high_freq_timer[0] (NRF_TIMER) is the always-running sync timer
    // The timing master never adjusts this timer
    // The timing slave(s) adjusts this timer whenever a sync packet is received and the logic determines that there is
    m_params.high_freq_timer[0]->TASKS_STOP  = 1;
    m_params.high_freq_timer[0]->TASKS_CLEAR = 1;
    m_params.high_freq_timer[0]->PRESCALER   = SYNC_TIMER_PRESCALER;
    m_params.high_freq_timer[0]->BITMODE     = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
    m_params.high_freq_timer[0]->CC[0]       = TIME_SYNC_TIMER_MAX_VAL;
    m_params.high_freq_timer[0]->CC[1]       = 0xFFFFFFFF;
    m_params.high_freq_timer[0]->CC[2]       = 0xFFFFFFFF;
    m_params.high_freq_timer[0]->CC[3]       = 0xFFFFFFFF;
    if (m_params.high_freq_timer[0] == NRF_TIMER3 || m_params.high_freq_timer[0] == NRF_TIMER4)
    {
        // TIMERS 0,1, and 2 only have 4 compare registers
        m_params.high_freq_timer[0]->CC[4]   = TIME_SYNC_TIMER_MAX_VAL / 2; // Only used for debugging purposes such as pin toggling
    }
    m_params.high_freq_timer[0]->SHORTS      = TIMER_SHORTS_COMPARE0_CLEAR_Msk;
    m_params.high_freq_timer[0]->TASKS_START = 1;
}

Thanks!