I want to generate 2 fast PWM waves with 25% duty cycles from nRF51822. They have same frequency of 4MHz but there is half a cycle delay between them. I checked the nrf_pwm library but couldn't find a function can do that. Is there a way around?
I want to generate 2 fast PWM waves with 25% duty cycles from nRF51822. They have same frequency of 4MHz but there is half a cycle delay between them. I checked the nrf_pwm library but couldn't find a function can do that. Is there a way around?
Hi
I do not think either there is a mechanism in the nrf_pwm library that makes the PWMs to be out of phase synchronized. I think the library sets all PWMs to have the same frequency and phase.
The nrf_pwm library does not anyway support more than 62,5 kHz frequency. Anyway, if you do not intend to change the duty cycle during operation you should be able to use higher frequencies just if you set the duty cycle prior to enabling the PWM. See some hints on this thread. I suspect however that the two PWM's will have the same phase when using the nrf_pwm_library.
What you could do is to manually use a TIMER peripheral and connect it to 2xGPIOTE channels by using 2xPPI channels. Make TIMER CC register 1 set PWM channel 1 low, make TIMER CC register 2 set PWM channel 2 low, make TIMER CC register 3 set both PWM channels high and reset the TIMER. Thereby you could get fixed duty cycle, out of phase synchronized PWMs with 4MHz frequency and 25% duty cycle. You could use this example as a starting point.
It might also be possible to implement this with help of the latest drivers in the SDK, see the gpiote example in the SDK for code reference starting point.
2.9.2015 Looking at this the second time, I think you actually need 4xCC compare registers to do the task. Perhaps the procedure is as follows:
Let me know if you see any flaws in this idea
Hi Stefan, thanks for you reply. I still don't quite get your way of generating those two PWM waves with three CC registers. What I need are two 25% duty cycle PWM waves that one is on between 0~T/4 and the other is on between T/2~3T/4 with T being the period of PWM. With the way you described, I can see you can generate the first one, but I don't see how to generate the second one. Would you please elaborate? Thanks.
Hi Stefan, thanks for you reply. I still don't quite get your way of generating those two PWM waves with three CC registers. What I need are two 25% duty cycle PWM waves that one is on between 0~T/4 and the other is on between T/2~3T/4 with T being the period of PWM. With the way you described, I can see you can generate the first one, but I don't see how to generate the second one. Would you please elaborate? Thanks.