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

PPI CHANNEL USED TO generate pulse wave

Hi All,

I am using NRF51822 chip pca10001 development board.

I flashed ble_app_hrs application to the board.

I configure 3 channel for PPI.

static void ppi_init(void)
{
  
  uint32_t err_code;

	 err_code = sd_ppi_channel_assign(0,
                                     &(NRF_TIMER2->EVENTS_COMPARE[0]),
                                     &(NRF_GPIOTE->TASKS_OUT[0]));
    APP_ERROR_CHECK(err_code);
	
		
		err_code = sd_ppi_channel_assign(1,
                                     &(NRF_TIMER2->EVENTS_COMPARE[1]),
                                     &(NRF_GPIOTE->TASKS_OUT[0]));
    APP_ERROR_CHECK(err_code);
	
		err_code = sd_ppi_channel_assign(2,
                                     &(NRF_TIMER2->EVENTS_COMPARE[1]),
                                     &(NRF_TIMER2->TASKS_CLEAR));
    APP_ERROR_CHECK(err_code);
}

I configure gpiote task for channel 0.

void gpiote_channel_0_set(void)
{
	 nrf_gpiote_task_config(0, AC_OUT_PIN, NRF_GPIOTE_POLARITY_TOGGLE, \
                           NRF_GPIOTE_INITIAL_VALUE_HIGH);
}

Now i enable all 3 channels.

__inline void ppi_enable(void)
{
		uint32_t err_code;
		err_code = sd_ppi_channel_enable_set( (PPI_CHEN_CH0_Msk) |  (PPI_CHEN_CH1_Msk)| (PPI_CHEN_CH2_Msk));
    APP_ERROR_CHECK(err_code)
}

The timer2 is intialised as fallows.

static void timer2_init(void)
{
		
   /* Start 16 MHz crystal oscillator */
    NRF_CLOCK->EVENTS_HFCLKSTARTED    = 0;
    NRF_CLOCK->TASKS_HFCLKSTART       = 1;
    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)       
    {
        // Do nothing.
    }
		NRF_TIMER2->TASKS_CLEAR = 1;
    NRF_TIMER2->MODE        = TIMER_MODE_MODE_Timer;
		NRF_TIMER2->PRESCALER   = 4;

    /* Load initial values to Timer 2 CC registers */
    /* Set initial CC0 value to anything > 1 */
		NRF_TIMER2->BITMODE   = TIMER_BITMODE_BITMODE_16Bit;
	
}

Now i am updating timer2 cc0 value and cc1 value from BLE characteristic interrupt and then i start the timer.

But for constant cc0 and cc1 value its giving two waveform.

ex- cc0=1000(1ms), cc1=10000(9ms);

i am getting two wave

  1. 1ms on and 9ms off.

  2. 1ms off and 9ms on.

I need to get only first wave all the time if i write constant value to ble characteristic

Could any one tell me how to solve this?. ( I need to do this with PPI only).

I tried by reinitialising all ppi and gpiote for every ble characteristic interrupt then also it dont work.

Kindly tell me what is the issue.

Regards Punit

Parents
  • HI Aryan,

    Now i solved the toggle output by doing fallowing changes.

        static void peripheral_init()
    {
    			static int x=1;
    			int xx;
              //nrf_gpio_pin_toggle(18);
    				gpiote0_timer_dis();
            gpiote_init();
            gpio_event_config();
            nrf_gpio_pin_clear(AC_OUT_PIN);
    				NRF_TIMER2->TASKS_CLEAR=1;
    				NRF_TIMER2->TASKS_START=1;
    			  ppi_enable(); 
    				NRF_GPIOTE->EVENTS_IN[3]=0;
    				//NRF_GPIOTE->EVENTS_IN[2]=0;
    		
            
    	}
    
    void GPIOTE_IRQHandler(void)
    {
        
        if(NRF_GPIOTE->EVENTS_IN[3]==1)
        {
    			nrf_gpio_pin_toggle(19);
    					NRF_GPIOTE->EVENTS_IN[3]=0;
             	first_event=true;				
    					//peripheral_init();
    				
        }
        if(NRF_GPIOTE->EVENTS_IN[2]==1)
        {
                    if(first_event == true)
    								{
    										peripheral_init();
    										first_event=false;
    										//NVIC_DisableIRQ(GPIOTE_IRQn);
    								}
    //										gpiote_init();
    //							nrf_gpio_pin_clear(AC_OUT_PIN);
                    NRF_GPIOTE->EVENTS_IN[2]=0;
        }   
    }
    
    int main(void)
    {
    		nrf_gpio_cfg_input(20,GPIO_PIN_CNF_PULL_Pullup);
    		nrf_gpio_cfg_input(16,GPIO_PIN_CNF_PULL_Pullup);
    		gpio_event_config();
    		nrf_gpio_cfg_output(AC_OUT_PIN);
    		nrf_gpio_cfg_output(19);
    	
    		timer2_init();
    		gpiote_init();
    		ppi_init();
    		nrf_gpio_pin_clear(AC_OUT_PIN);
    	//	NRF_TIMER2->TASKS_START=1;
    	//	pwm_set(7);
    		while (true)
        {
    				//gpiote_init();
    			
        }
    }
    
Reply
  • HI Aryan,

    Now i solved the toggle output by doing fallowing changes.

        static void peripheral_init()
    {
    			static int x=1;
    			int xx;
              //nrf_gpio_pin_toggle(18);
    				gpiote0_timer_dis();
            gpiote_init();
            gpio_event_config();
            nrf_gpio_pin_clear(AC_OUT_PIN);
    				NRF_TIMER2->TASKS_CLEAR=1;
    				NRF_TIMER2->TASKS_START=1;
    			  ppi_enable(); 
    				NRF_GPIOTE->EVENTS_IN[3]=0;
    				//NRF_GPIOTE->EVENTS_IN[2]=0;
    		
            
    	}
    
    void GPIOTE_IRQHandler(void)
    {
        
        if(NRF_GPIOTE->EVENTS_IN[3]==1)
        {
    			nrf_gpio_pin_toggle(19);
    					NRF_GPIOTE->EVENTS_IN[3]=0;
             	first_event=true;				
    					//peripheral_init();
    				
        }
        if(NRF_GPIOTE->EVENTS_IN[2]==1)
        {
                    if(first_event == true)
    								{
    										peripheral_init();
    										first_event=false;
    										//NVIC_DisableIRQ(GPIOTE_IRQn);
    								}
    //										gpiote_init();
    //							nrf_gpio_pin_clear(AC_OUT_PIN);
                    NRF_GPIOTE->EVENTS_IN[2]=0;
        }   
    }
    
    int main(void)
    {
    		nrf_gpio_cfg_input(20,GPIO_PIN_CNF_PULL_Pullup);
    		nrf_gpio_cfg_input(16,GPIO_PIN_CNF_PULL_Pullup);
    		gpio_event_config();
    		nrf_gpio_cfg_output(AC_OUT_PIN);
    		nrf_gpio_cfg_output(19);
    	
    		timer2_init();
    		gpiote_init();
    		ppi_init();
    		nrf_gpio_pin_clear(AC_OUT_PIN);
    	//	NRF_TIMER2->TASKS_START=1;
    	//	pwm_set(7);
    		while (true)
        {
    				//gpiote_init();
    			
        }
    }
    
Children
No Data
Related