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

how to change gpio pin voltage/current levels

Hi, i am working on Pancake motor C0820B006F circuit and it is connected to P0.12 pin and ground iam usin NRF52 development board. i want to change the pan cake vibrator frequency by changing Pin0.12 voltage or current. how to change the current/voltage at certain PIN to change frequency level of vibrator.

Thank you.

##EDIT :-

/* 2-channel PWM, 200Hz, output on DK LED pins. */ app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(200L, BSP_LED_0);

       /* Switch the polarity of the second channel. */
       //pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;

       /* Initialize and enable PWM. */
       err_code = app_pwm_init(&PWM,&pwm1_cfg,pwm_ready_callback);
       APP_ERROR_CHECK(err_code);
       app_pwm_enable(&PWM);

       uint32_t value;

          APP_ERROR_CHECK(err_code);
       while(true)
       {

           for (uint8_t i = 0; i < 40; ++i)
           {
               value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5);
               //printf("value = %d\n",value);
               ready_flag = false;
               /* Set the duty cycle - keep trying until PWM is ready... */
               while (app_pwm_channel_duty_set(&PWM, 0, value) == NRF_ERROR_BUSY);

               /* ... or wait for callback. */
               while(!ready_flag);
               APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM, 1, value));
               nrf_delay_ms(50);

           }

       }
Parents
  • You can't drive this motor directly from the nRF. The spec sheet says it draws 100mA. The nRF52 can provide max 10mA in high drive mode. Also there is no DAC capability with nRF52. GPIO are either on or off. The only solution you can do is drive the pin as PWM and through a low pass filter use a fet or bjt to drive the motor.

  • There are a couple of pwm examples in the SDK. Also I have seen numerous postings on the blog with pwm code. But in short, a pwm is just a timer tied to the gpio. You set the length of the timer (how long it can actually count for until it starts back at 0) and you set the amount of time it counts until it turns off the gpio. There are several built in hardware timers on the nRF. So, it goes as: the timer starts, gpio goes high, timer hits your number, gpio turns off, timer keeps running until it hits end, timer goes back to zero and starts over. In this manner you can set any duty cycle for the output you wish. If you are running other code you probably want a solution that doesn't bother the processor to do the pwm. Nordic allow you to tie timers/counters to the PPI and gpio to facilitate a pwm that runs independent of the processor.

Reply
  • There are a couple of pwm examples in the SDK. Also I have seen numerous postings on the blog with pwm code. But in short, a pwm is just a timer tied to the gpio. You set the length of the timer (how long it can actually count for until it starts back at 0) and you set the amount of time it counts until it turns off the gpio. There are several built in hardware timers on the nRF. So, it goes as: the timer starts, gpio goes high, timer hits your number, gpio turns off, timer keeps running until it hits end, timer goes back to zero and starts over. In this manner you can set any duty cycle for the output you wish. If you are running other code you probably want a solution that doesn't bother the processor to do the pwm. Nordic allow you to tie timers/counters to the PPI and gpio to facilitate a pwm that runs independent of the processor.

Children
No Data
Related