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

How to connect single pwm signal to multiple GPIO

Hi,

At the moment I generate 4 independent pwm signals, I would prefer to have 6 but this is not possible to my understanding due to the lack of GPIOTE [ref1,ref2].

So I am trying to connect a single PWM signal to 2 gpio pins, is this possible through the ppi or any other way?

Link, here they advise to connect them in hardware. I would like to do this in software so that in the future it is possible to switch from PWM to something else.

Kind regards,

Niels Kool

Parents
  • There are several ways to do that. As your references point out you can fork the TE to 2 gpio.  Then since one TEP can drive many EEP's, you can wrap it back around in PPI to bring it out again.  Only downside of this is the first TEP and the replicated TEP will be delayed by one Pclk. Though you could bring out four or more TEP's in phase if they are all this second replication.

    If it is a slow PWM signal, eg more than millisecond period, then you can have the PWM TEP drive an ISR and then you can write as many  bits in the port register as you wish within the interrupt handler. If this is the only task running on the board then you can have more frequent ISR's, but not when running a softdevice.

  • But in order to switch gpio a GPIOTE is needed... right? so the replicated TEP would still need the extra GPIOTE or am I mistaken here?

  • Yeah, I really glossed over that.  Sorry.

    The spec references the sequence start/stop EEP's.  These could be used to drive multiple peripheral TEP's. So start is set and stop is clear. This is ok per the spec which says, "One event can trigger multiple tasks by using multiple channels and one task can be triggered by multiple events in the same way."

    I looked in the spec and didn't see where they call out the TEP's for pwm. However, according to Sigurd at Nordic, one can use the pwm TEP's in ppi a little more elegantly to affect this.  See this reference: https://devzone.nordicsemi.com/f/nordic-q-a/20120/what-is-the-maximum-limit-for-pwm-outputs-pins-on-nrf52832-can-we-use-all-the-gpio-pins-as-a-pwm-output

    Finally, if none of these approaches work out, you can always make a PWM using one of the timers and then you have easy access to all the registers to map out as many gpio pins as you wish up to the limits of the gpiote channels. There were many references to this in the devzone.  Basically you use one cc register for "on" period, and one for "off" period.

  • Hi,

    Your reference is for a 52832 as I am using the 51822. 
    Sigurd makes use of the DMA and the GPIOTE, where as the 52832 has 8 GPIOTE and the 51822 only 4.
    And I don't see any mentioning of a DMA in the 51822 that can be used.

    The problem is not really the limitation of the timers but getting it to the GPIO.
    However your suggestion to use IRQ might be possible but is not preferred.

  • As far as I know, since you are on 51822 your only choice is IRQ.  You should avoid using the GPIO drivers as there is a lot of code between you and the ports.  Just write the set/clear register directly.  In one shot you can write all the gpio if needed.

    Average latency due to the SD is up to about 1 millisecond.  But if you are not running the SD then you can easily do the PWM using an ISR and run it reliably up to about 500kHz maybe more.  Just depends on how much code has to get executed.

    You can also timeslot your PWM solution to make it less dependent on the SD.  But most people don't want a PWM that is only on some of the time.

Reply
  • As far as I know, since you are on 51822 your only choice is IRQ.  You should avoid using the GPIO drivers as there is a lot of code between you and the ports.  Just write the set/clear register directly.  In one shot you can write all the gpio if needed.

    Average latency due to the SD is up to about 1 millisecond.  But if you are not running the SD then you can easily do the PWM using an ISR and run it reliably up to about 500kHz maybe more.  Just depends on how much code has to get executed.

    You can also timeslot your PWM solution to make it less dependent on the SD.  But most people don't want a PWM that is only on some of the time.

Children
No Data
Related