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

Explanation of pwm example code please

Hi, I need to configure pwm with 14uSec off time and 46uSec on time. I had a look at the pwm example in the install directory and also : developer.nordicsemi.com/.../a00039.html. But it is bit confusing, in the sense, if I need to set a duty cycle of 25% which registers to change. When I change the duty_cycle to 250, or, 100(in the local variable "duty_cycle"), there is no effect in the PWM wave generated. The On and Off times are 256msec always. Even tried pressing the configured buttons, but still no change in duty cycle. Attached my code here: main.c

Questions:

  1. Which register to change to set a desired duty cycle(say 25% off time and 75% on time)
  2. If I want to use the same PWM module for generating 25% duty cycle outputting on PIN1 for the first time, then 100% duty cycle outputting on PIN2 the next time and the above continues forever, do I need to deinit the gpiote and configure(nrf_gpio_tsk_config) every time I swap the PWM pins?
Parents
  • I have got thist ot work by just copy pasting the code that I have sent you into another working project. Now, how do I set the number of cycles for the PWM? I need just 3 cycles of PWM(on time: 34usec, off time:14usec) after those 3 cycles, I need 10msec delay, then 3 cycles of PWM and the sequence continues. I tried using a different timer to keep track of the number of cycles, but does not work very well. Ideas please..

Reply
  • I have got thist ot work by just copy pasting the code that I have sent you into another working project. Now, how do I set the number of cycles for the PWM? I need just 3 cycles of PWM(on time: 34usec, off time:14usec) after those 3 cycles, I need 10msec delay, then 3 cycles of PWM and the sequence continues. I tried using a different timer to keep track of the number of cycles, but does not work very well. Ideas please..

Children
No Data
Related