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

soft pwm with rtc

I would need more pwm channels, than there is possible with pwm library on nrf51822 (That is 16 channels). I would like to do it in a fashion, similar to this, using a prescaler of 15, so pwm frequency would be 2.048 kHz.

My questions are:

  • can i toggle multiple pins in one go (similar to PORTD in avr)
  • would this work with soft device
  • would this work at all, since approach in avr is specific with ORCR1A value increasing manually.

Simple example would be excellent.

Thank you.

  • Hi

    If I understand you correctly, you intend to implement PWM based on an RTC timer, and you only need a resolution of 4 bits? (0-16)

    • Using the OUTCLR and OUTSET registers in the NRF_GPIO peripheral it is possible to set or clear multiple pins at once, yes. If you need to both set and clear pins at the same time you would have to do it in two instructions, most commonly like this (the value names are just examples): NRF_GPIO->OUTCLR = [MASK FOR ALL YOUR IO's]; NRF_GPIO->OUTSET = [MASK FOR IO's THAT SHOULD BE SET HIGH];

    • Technically it will work, but since the SD has the highest priority the PWM update might be delayed leading to glitches on the PWM.

    • It might not work in the exactly same way, but you can update the CC registers dynamically to change the reload time.

    In general I would consider the nRF52 if you are looking for multiple PWM's. While this is possible with the nRF51 you will get glitches when using the SoftDevice, and you will spend a lot of CPU time in the interrupt. The nRF52 allows you to run 12 PWM channels from DMA, and 8 PWM channels using timers and PPI, for a total of 20 PWM channels.

    Best regards
    Torbjørn

  • Sorry, i was not clear on that. I would need a 16 channel PWM, of frequency approx. 2kHz, with resolution of 8 bits. I would need to soft start led strips, so glitches from SD would probably not be a big issue.

    CPU time is also not a big issue, since this PWM action occurs only once in a while.

    Currently i am looking into Low power PWM library, and so far i do not see any limitations, regarding using this library.

  • The main limitation of the low power PWM library is the speed, since it is based on the 32.768kHz clock. When doing PWM the PWM frequency is set by the PWM timer divided by the number of steps. This means you would get a PWM frequency of 32768 / (2^8) = 128 Hz if you need 8-bit resolution

    For LED's this is usually sufficient, since it's quick enough to avoid visible blinking, but if you have a hard requirement of 2kHz it is not enough.

Related