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.

Parents
  • Hello Stefan, Thank you for your response after which I manage to have what I wanted. However, what I saw now is that the PWM signal looks fine for the first three modes: PWM_MODE_LED_100, PWM_MODE_LED_250, PWM_MODE_LED_1000. If I use faster clock in either of PWM_MODE_MTR_255 and PWM_MODE_BUZZER_255, there are still unexpected changes in polarity after which the signal duty cycle starts decreasing.

Reply
  • Hello Stefan, Thank you for your response after which I manage to have what I wanted. However, what I saw now is that the PWM signal looks fine for the first three modes: PWM_MODE_LED_100, PWM_MODE_LED_250, PWM_MODE_LED_1000. If I use faster clock in either of PWM_MODE_MTR_255 and PWM_MODE_BUZZER_255, there are still unexpected changes in polarity after which the signal duty cycle starts decreasing.

Children
Related