52832 timer and PWM interrupt

hi,

I want to use timer interrupt to start PWM function, and PWM had PWM interrupt too, hoping every 20ms to start PWM function, but if I open PWM and timer interrupt together, can't get normal wave, if I stop PWM interrupt, the wave is ok. I don't know reason. maybe I can't start PWM in the timer interrupt function?

normal waveabnormal wave

timer interrupt 

void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
	//bsp_board_led_invert(0);
	PWM init();	//---PWM init
}


PWM init

    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &configTip0, NULL)); //--- normal wave
    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm1, &configRing0, NULL));//--- normal wave
//		
//	APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &configTip0, TipHandler));//--- abnormal wave
//	APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm1, &configRing0, RingHandler));//--- abnormal wave

Parents
  • Hi,

    I am not able to explain this based on the information here, and generally it should not matter if you initialize PWM from an event handler (though that makes me wonder if you re-init it or perhaps something else you did not expect is happening)?. Perhaps you can elaborate a bit, bot about how things are failing, and perhaps more importantly add a bitt more code to provide context.

  • nrf_pwm_values_wave_form_t seq_values_Tip[] =
    	{
    		{ 0x8000+320,      0,      0,      640 }, 
    
    		{ 0x8000,      0,      0,      16 },
    
    		{ 0x8000+200,      0,      0,      400 },  
    				
    		{ 0x8000,      0,      0,      1600 },
    		
    	};
    	
    int number_Tip[]={32,61,40,114};
    nrf_pwm_values_wave_form_t /*const*/ seq_values_Tip0[1];
    nrf_pwm_values_wave_form_t /*const*/ seq_values_Tip1[1];
    
    
    static void TipHandler(nrfx_pwm_evt_type_t event_type)
    {
    	
    	if (event_type == NRFX_PWM_EVT_END_SEQ0)
    	{	
    		Count_Tip = Count_Tip+2;
    		seq_values_Tip0[0] = seq_values_Tip[Count_Tip];// add this code, wave is abnormal
    		NRF_PWM0->SEQ[0].REFRESH = number_Tip[Count_Tip]-1;
    	}
    	if (event_type == NRFX_PWM_EVT_END_SEQ1)
    	{	
    		seq_values_Tip1[0] = seq_values_Tip[Count_Tip+1];// add this code, wave is abnormal
    		NRF_PWM0->SEQ[1].REFRESH = number_Tip[Count_Tip+1]-1;
    	}
    
    }
    
    		
    		
    		

    please see my code, I debug yesterday, found if I open PWM interrupt though, but if I add "seq_values_Tip0[0] = seq_values_Tip[Count_Tip];" code in the PWM interrupt, the wave is abnormal, if remove it, we can get normal wave, so I think maybe that code affected my program.

Reply
  • nrf_pwm_values_wave_form_t seq_values_Tip[] =
    	{
    		{ 0x8000+320,      0,      0,      640 }, 
    
    		{ 0x8000,      0,      0,      16 },
    
    		{ 0x8000+200,      0,      0,      400 },  
    				
    		{ 0x8000,      0,      0,      1600 },
    		
    	};
    	
    int number_Tip[]={32,61,40,114};
    nrf_pwm_values_wave_form_t /*const*/ seq_values_Tip0[1];
    nrf_pwm_values_wave_form_t /*const*/ seq_values_Tip1[1];
    
    
    static void TipHandler(nrfx_pwm_evt_type_t event_type)
    {
    	
    	if (event_type == NRFX_PWM_EVT_END_SEQ0)
    	{	
    		Count_Tip = Count_Tip+2;
    		seq_values_Tip0[0] = seq_values_Tip[Count_Tip];// add this code, wave is abnormal
    		NRF_PWM0->SEQ[0].REFRESH = number_Tip[Count_Tip]-1;
    	}
    	if (event_type == NRFX_PWM_EVT_END_SEQ1)
    	{	
    		seq_values_Tip1[0] = seq_values_Tip[Count_Tip+1];// add this code, wave is abnormal
    		NRF_PWM0->SEQ[1].REFRESH = number_Tip[Count_Tip+1]-1;
    	}
    
    }
    
    		
    		
    		

    please see my code, I debug yesterday, found if I open PWM interrupt though, but if I add "seq_values_Tip0[0] = seq_values_Tip[Count_Tip];" code in the PWM interrupt, the wave is abnormal, if remove it, we can get normal wave, so I think maybe that code affected my program.

Children
No Data
Related