This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to set PWM duty cycle run stepper motor for 5sec?

I'm using PWM library example using nrf52840 with SDK17.0.2  to run stepper motor, I need to run the motor based on duty cycle  so how i able to run based on duty cycle for  different time seconds?

Parents Reply Children
  • Thanks for reply

    I already used PWM library  example to run the stepper motor  but the thing is i couldn't able to desire timing for example:-i want to expel the  fluid 2ml per second  out of 10ml so, the stepper motor expel the fluid with 5seconds so this what happening now  for more clarification please find the following codes.

    else if(strcmp(DATA,"F1")==0)                                                
      {
            proto_flag=false;
            kvorun_flag=false;
            uint32_t value;
            uint8_t target_ml;
            nrf_gpio_pin_set(SIP_SENSOR_BOARD_ENABLE);
            nrf_gpio_pin_set(SIP_SENSOR_BOARD_ROTATION);
            app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(600, SIP_SENSOR_BOARD_PWM_PIN);
            app_pwm_init(&PWM1,&pwm1_cfg, NULL);
            app_pwm_enable(&PWM1);
            rightsensor=opt1;
            if(volume_flag==0)
            {
            monitor_volume=resist-AUTO_EXP_VOL;
            volume_flag=1;
            }
    
          if(resist>monitor_volume)
          {  
              if(rightsensor!=1)
              {   
                  while (app_pwm_channel_duty_set(&PWM1, 0,50) == NRF_ERROR_BUSY);
                  nrf_delay_ms(20);    
                  revs_fillback_flag=true;
              }
              else
              {
                app_pwm_disable(&PWM1);
                revs_fillback_flag=false;
                memset(FINAL,0,12);
              } 
          }
    
         else
            {
            nrf_gpio_pin_set (SIP_SENSOR_BOARD_ENABLE);
            INT_KVO=0;
            KVO_FLAG=0;
            memset(prcol,0,120);
            memset(FINAL,0,120);
            revs_fillback_flag=false;
            proto_flag=false;
            kvorun_flag=false;
            counter_shark=0;
            volume_flag=0;
            }
            app_pwm_disable(&PWM1);
            app_pwm_uninit(&PWM1);
       }

    thank you.

  • The simplest may just be to start a repeated 1ms app_timer. In the 1ms timeout handler you increment a 1ms global counter. You then have two options to use this 1ms counter:

    1. You can then either directly in the timeout handler start and stop the PWM based on the 1ms counter value.
    OR
    2. You can just have a while() loop in your main() that just check the 1ms tick counter value and start and stop the PWM.

    Best regards,
    Kenneth

  • Hi,

    Here my stepper motor running with some speed and now for example:- I want to expel the fluid  1ml/sec  out of 10ml  so, it takes 10sec to complete. so, here I need to change that  fluid expel change 2ml/sec  out of 10ml  I need to complete it with in 5sec. so, I can't implement this by using timer so we need to control the speed.??

    please share your thoughts regarding this..  

    thank you.

  • Sorry, but I don't have any experience with this. The PWM example show example use of the PWM driver/peripheral, how frequently you want to update the PWM and what duty cycle you want on PWM is fully controllable, but it is up to you how you implement this.

    Kenneth

Related