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

NRf51822 PWM Losing Events

Hello,

I am using Timer_2 with two CC registers configured, 2 PPI channels (one for each CC register in the timer), and one GPTIO_TE to make a PWM to control dimming on an LED.

The PPI channels are configured as follows:

	// Configure PPI channel 0 to toggle ADVERTISING_LED_PIN_NO on every TIMER2 COMPARE[0] match
	err_code = sd_ppi_channel_assign(PPI_CHAN3_PWM_LED_1,
																 &(NRF_TIMER2->EVENTS_COMPARE[1]),
																 &(NRF_GPIOTE->TASKS_OUT[LED_GPIOTE_TASK]));

	// Configure PPI channel 0 to toggle ADVERTISING_LED_PIN_NO on every TIMER2 COMPARE[0] match
	err_code = sd_ppi_channel_assign(PPI_CHAN4_PWM_LED_2,
																 &(NRF_TIMER2->EVENTS_COMPARE[3]),
																 &(NRF_GPIOTE->TASKS_OUT[LED_GPIOTE_TASK]));

The Timer Registers are configured as follows:

   NRF_TIMER2->SHORTS = TIMER_SHORTS_COMPARE3_CLEAR_Enabled <<        
   TIMER_SHORTS_COMPARE3_CLEAR_Pos;
   NRF_TIMER2->CC[0] = duty_cycle;
   NRF_TIMER2->CC[3] = TIMER2_RELOAD;

The GPIOTE Channel is configured as follows:

nrf_gpiote_task_configure(LED_GPIOTE_TASK, LED_CTRL_PIN, \
                       NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
nrf_gpiote_task_enable(LED_GPIOTE_TASK);

In general the configuration works and I am able to achieve variable duty cycle and hence a variable brightness on the LED. The GPIOTE task is configured with a toggle mechanism because I wasn't able connect two GPIOTE channels to a single pin. If that were possible I would have configured one for on and another for off.

This style of control is causing issues. The brightness of the LED appears to change brightness randomly sometimes after several minutes sometimes after 30 seconds.

I decided to hook up an Oscilloscope to see what was happening with the waveform. With the oscilloscope I was able to see that the duty cycle of the wareform was inverting randomly. If I started at a duty cycle of 25% it would randomly change to 75% then later back to 25% without any software intervention. This change was seen happening completely in hardware.

This could occur if a toggle event was missed. If a toggle event is missed the duty cycle for the LED becomes inverted and the brightness will change.

Could a hardware PPI event be missed by the processor?

Parents Reply Children
No Data
Related