I am trying to use PPI to control an output pin. I am successfully using 2 PPI channels at the moment to use the COMP to do freq counting over a 10mS time period. I have added a 3rd PPI channel to turn an output off in below code.
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void ppi_init(void)
{
uint32_t err_code = NRF_SUCCESS;
err_code = nrf_drv_ppi_init();
error_check(err_code);
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
//Configure GPIOTE
nrf_drv_gpiote_out_config_t config = NRFX_GPIOTE_CONFIG_OUT_TASK_LOW; //TOGGLE(NRF_GPIOTE_INITIAL_VALUE_HIGH);//
err_code = nrf_drv_gpiote_out_init(MI_EN, &config);
APP_ERROR_CHECK(err_code);
uint32_t gpiote_task_addr = nrf_drv_gpiote_out_task_addr_get(MI_EN);
nrf_drv_gpiote_out_task_enable(MI_EN);
/* Configure 1st available PPI channel to count timer1 when comp has UP event
*/
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel1);
error_check(err_code);
Then I have a seperate RTC timer at 32Hz, that resets the timers and sets the output pin high.
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
//capture the counter value
MI_freq = nrf_drv_timer_capture(&m_timer1, 0);
//Restart the timers for the PPI MI capture
nrf_drv_timer_enable(&m_timer1);
nrf_drv_timer_enable(&m_timer4);
nrf_drv_timer_clear(&m_timer1);
nrf_drv_timer_clear(&m_timer4);
//Set the output high
nrf_drv_gpiote_out_set(MI_EN);
The output is always off. If I set the task type to GPIOTE TASK_HIGH then the output is always on.
Is there anything obviously wrong in the code? My timers / counter and PPI channel 1 and 2 are all working as expected.
It appears as if the GPIOTE task is always running, i.e. holding the output low all the time and not just triggering on the PPI timer compare.
Thanks