#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_timer.h"
#include "bsp.h"
#include "app_error.h"
#include "nrf_gpio.h"
#define LED1 13
#define LED2 14
#define LED3 15
#define Button 11
#define Button1 12
static nrfx_timer_t timer=NRFX_TIMER_INSTANCE(0);
static int n=12,m=12;
void time_handler(nrf_timer_event_t event_type, void* p_context)
{
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
{
if(n<11)
{
nrf_gpio_pin_toggle(LED1);
printf("%d",n);//debug
n++;
if(n==10)
{
nrf_gpio_pin_clear(LED1);
}
}
}
break;
case NRF_TIMER_EVENT_COMPARE1:
{
if(m<11)
{
nrf_gpio_pin_toggle(LED2);
printf("%d",m);//debug
m++;
if(m==10)
{
nrf_gpio_pin_clear(LED2);
}
}
}
break;
default:
break;
}
}
int main(void)
{
uint32_t time_ticks,time_ticks1,count=0;
uint32_t time_ms=1000,time_ms1=5000;
nrfx_timer_config_t configure = NRFX_TIMER_DEFAULT_CONFIG;
nrfx_timer_init(&timer,&configure,time_handler);
time_ticks=nrfx_timer_ms_to_ticks(&timer,time_ms);
time_ticks1=nrfx_timer_ms_to_ticks(&timer,time_ms1);
nrfx_timer_extended_compare(&timer,NRF_TIMER_CC_CHANNEL0,time_ticks,NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,true);
nrfx_timer_extended_compare(&timer,NRF_TIMER_CC_CHANNEL1,time_ticks1,NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,true);
nrfx_timer_enable(&timer);
nrf_gpio_cfg_output(LED1);
nrf_gpio_cfg_output(LED2);
nrf_gpio_cfg_input(Button,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(Button1,NRF_GPIO_PIN_PULLUP);
while(1)
{
if(nrf_gpio_pin_read(Button)==0)
{
n=0;
}
if(nrf_gpio_pin_read(Button1)==0)
{
m=0;
}
}
}
WHEN I TRY WITH ONE CHANNEL THE TIMER WORKS PREFECT BUT WHILE HANDLING WITH TWO OR MORE CHANNELS IN TIMER I DON'T GET OUTPUT .PLEASE HELP ME TO GET OUTPUT IN 2 CHANNEL .THANK YOU