nRF52 PWM / Stepper Motor

The article  RE: nRF52 PWM / Stepper Motor has most of what I need.  The unfortunate thing is that the solution is written for a version of the SDK that I do not know.  I am new to the nRF52* platform, and have come up to speed with using nRFConnect V2.1.0 with VSCode.  The solution does not compile under this newer version of the SDK.  Would someone be able to translate it?  

Specifically, I am trying to drive 2 stepper motors without the use of a secondary MCU to control the steps/acceleration/position/etc that comes with steppers.  I was able to use PWM to drive one motor, but I need 2 motors running at an independent frequency for differing speeds. According to the nRF52840 spec, the same PWM frequency is shared with all the PWM outputs. I would love to try the PPI/counter example to see if it would work for me, but as far as demo code for PPI and Counters with nRFConnect2.1.0, examples are scarce. 

So bottom line is, with nRF.Connect v2.1.0, is there a low-overhead method that would allow the chip to handle 2 stepper motors with minimal overhead?  

Parents
  • Hello,

    I have a few repositories that may be interesting for you. 

    The bare metal PPI implementation was ported for a side project, and you can find it here:

    https://github.com/edvinand/ppi_pwm_hands_on

    Please see the file: suggested_solution_main.c

    If you want to go with this approach, and you need different PWM frequencies, I believe you need to use two separate timer instances for this, since this PPI implementation resets the timer counter register when the PWM period is reached. 

    If you want to use the PWM peripheral, and you want the two PWM signals to have different periods, you would need to use two instances of the PWM. As you can see here, the nRF52840 has 4 PWM instances, which can be set with their own countertops (which will give different frequencies). 

    I have not played too much around with the PWM peripheral in NCS, but I suggest that you try to use the nrfx pwm drivers directly in case you want to test this. That gives you better control of the peripherals than if you use the generic Zephyr drivers.

    Best regards,

    Edvin

Reply
  • Hello,

    I have a few repositories that may be interesting for you. 

    The bare metal PPI implementation was ported for a side project, and you can find it here:

    https://github.com/edvinand/ppi_pwm_hands_on

    Please see the file: suggested_solution_main.c

    If you want to go with this approach, and you need different PWM frequencies, I believe you need to use two separate timer instances for this, since this PPI implementation resets the timer counter register when the PWM period is reached. 

    If you want to use the PWM peripheral, and you want the two PWM signals to have different periods, you would need to use two instances of the PWM. As you can see here, the nRF52840 has 4 PWM instances, which can be set with their own countertops (which will give different frequencies). 

    I have not played too much around with the PWM peripheral in NCS, but I suggest that you try to use the nrfx pwm drivers directly in case you want to test this. That gives you better control of the peripherals than if you use the generic Zephyr drivers.

    Best regards,

    Edvin

Children
Related