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

PWM Motor control

Hello, I am working on an application based on the "Motor control example". However instead of just setting two different values for the duty cycle I am trying to either increase or decrease it for every button press. I am still using both PPI channels to toggle an LED once when it reaches CC[0] (to set the duty cycle) and once to finish a complete period CC[1]. This is what I have placed in the main fuction while loop:

   while (true)
 {
    btn0_nstate = nrf_gpio_pin_read(BUTTON_0);
       if ((btn0_ostate == 1) && (btn0_nstate == 0))
	  {
		LED_INTENSITY +=10;
		if (LED_INTENSITY > 250)
		 {	
			LED_INTENSITY  = 10;
		 }

		pwm_set(LED_INTENSITY );
       }
      btn0_ostate = btn0_nstate;
 }

What I observe with an oscilloscope is that the program runs as expected for some time but then at a random time it seems that the signal toggles when it is not supposed to. This makes low values for the intensity to be represented with high duty cylce and vice versa. Thank you in advance and I am looking forward for some help.

Related