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

How to control a servo motor from nrf52832 with angle precision?

I am using the Hackable Kit from Electronut labs and using their Bumpy , black magic probe alternative for programming. I would like to control a servo motor precisely at given angle from a mobile app over bluetooth. I have tried the PWM library and driver examples from the SDK 15 examples.

When i run them independently they work well and good. But when i integrate it with any of the Ble_peripheral example it doesn't work. Either i get a SIGSEGU interrupt error, or, when servo motor runs BLE service is disconnected or vice versa happens as if like they both are sharing same resources. But i made sure by tracing their dependencies that they are not sharing any common TIMER or PPI Channel. Yet the problem persists. However even when the servo motor is working i couldn't control its angle the way i wanted it. 

I would like to know whether PWM is the right way to control a servo motor for precision angles. If it is is there any sample code that i can refer to. But please not the SDK examples as they are not helpful. I am Using SEGGER and GBD for codding and loading code into the hardware as I don't own a J-Link. 

Parents
  • Which SDK PWM example are you using? I ask because there are a few different PWM examples.

    I suspect that the example you are using is using TIMER0, which is also used by the SoftDevice. Try to change the PWM example to use another timer, e.g. TIMER1.

     

    Best regards,

    Edvin

Reply
  • Which SDK PWM example are you using? I ask because there are a few different PWM examples.

    I suspect that the example you are using is using TIMER0, which is also used by the SoftDevice. Try to change the PWM example to use another timer, e.g. TIMER1.

     

    Best regards,

    Edvin

Children
  • As i mentioned in the question i used the PWM library, PWM Driver (demo 1 to 4) examples. Also i would like to mention that my servo motor is Tower PRO SG90. 

  • Ok. I will use the pwm_library example, then.

    I assume that you tried to add the pwm_library to one of the ble_examples.

    The pwm_library example uses TIMER1, as it says in the comment of the initialization of the PWM_INSTANCE:

    Fullscreen
    1
    APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    Have you enabled TIMER1 in sdk_config.h of the project you are trying to merge with the PWM project?

     

    BR,

    Edvin

  • Yes I have Enables the TIMER1_ENABLE in sdk_config.h. Infact to check i enabled All the TIMERS 0 to 4 and also enabled NRFX_TIMER 0 to 4. I have also also added all the required drivers and libraries.

  • Is it possible to send the project, then I can take a look at it.

     

    Best regards,

    Edvin