Setting up CC case using Timer 2

Am I able to set up both a case where a GPIOTE event controls through PPI a Capture event on CC[2] of Timer 2's value as well as when Timer 2 reaches its max value (overflows to = 0) it will activate a COMPARE event on CC[2] or will I need to use another CC register? Here is some sample code

void system_timer_cc_0_2_init(void)
{
    uint32_t capture_task_addr;
    uint32_t gpiote_evt_addr;
    ret_code_t err_code;
    nrf_drv_gpiote_in_config_t in_config;
    /* CC[2]
     * Setup PPI tasks for GPIOTE and system timer channel[2]
     */

    //VCE: The below block needs to be called for each pin
    in_config.pull = NRF_GPIO_PIN_NOPULL; //User defined
    in_config.sense = NRF_GPIOTE_POLARITY_LOTOHI; //User defined
    in_config.hi_accuracy = true; //User defined
    in_config.is_watcher = false; //Don't change this
    in_config.skip_gpio_setup = false; //Don't change this

    //enable the pin for GPIOTE
    err_code = nrf_drv_gpiote_in_init(SPEEDO_TACHO_PIN_NUMBER, &in_config, speedo_tach_input_handler);
    APP_ERROR_CHECK(err_code);

    //setup a ppi channel to associate with the system_timer_cc_0_2 compare events
    err_code = nrf_drv_ppi_channel_alloc(&(ppi_channel[2]));
    APP_ERROR_CHECK(err_code);

    capture_task_addr = nrf_drv_timer_event_address_get(&system_timer_cc_0_2, NRF_TIMER_TASK_CAPTURE2);
    gpiote_evt_addr = nrf_drv_gpiote_in_event_addr_get(SPEEDO_TACHO_PIN_NUMBER);

    err_code = nrf_drv_ppi_channel_assign(ppi_channel[2],  gpiote_evt_addr, capture_task_addr);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel[2]);
    APP_ERROR_CHECK(err_code);
    // check for timer2 overflow which will be 2^16 -1 = 65535
    NRF_TIMER2->CC[2] = 65535;

    nrf_drv_gpiote_in_event_enable(SPEEDO_TACHO_PIN_NUMBER, true);
    //Once all system_timer_cc_0_2 shared peripherals are ready, enable the shared timer
    nrf_drv_timer_enable(&system_timer_cc_0_2);
}

Parents Reply Children
No Data
Related