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

PWM signal was reversed.

I using github code. SDK is 7.0.1 SD : S110 7.1.0

Channel : 4 ch

Period : 20ms

Width : 1-2ms ( RC )

Sometimes the width operates at 18-19ms.

ex : PWM2 was reversed. image description

Init code:

void _init(void) {

nrf__config_t _config = _DEFAULT_CONFIG;

_config.mode             = _MODE_RC_5000;
_config.num_channels     = 4;
_config.gpio_num[0]      = 26;
_config.gpio_num[1]      = 17;
_config.gpio_num[2]      = 9;
_config.gpio_num[3]      = 12;

// Initialize the  library
nrf__init(&_config);


nrf__set_value(0, 1500);
nrf__set_value(1, 1500);
nrf__set_value(2, 1500);
nrf__set_value(3, 1500);

}

output code :

{ if(_out[0] >= 2000) _out[0] = 2000; if(_out[0] < 1000) _out[0] = 1000;

nrf__set_value(0, _out[0] );

}

I attached my code. nrf_.c

nrf_.h

Parents
  • Hi, Torbjørn, What do you mean exactly by powerdown? If I do this: sd_power_mode_set(NRF_POWER_MODE_CONSTLAT); does this avoid any PWM powerdown issue? I'm using USE_WITH_SOFTDEVICE = 1 and I have 3 PWM channels.

    Even with this, and with the Feb 5 2015 Github release of nrf_pwm.c, I still sometimes get an inverted waveform (I'm only looking at channel 0 for now).

    I repeat this sequence 10 times a second (with PWM frequency = 488 Hz):

    • set pwm value to 0 (to float one side of an H-bridge) for 5ms
    • read two ADC channels
    • restore PWM value to previous setting
    • do some calculations (quickly)
    • set new PWM value

    I'm suspecting there is a problem with your code when it writes to TASKS_OUT to "fix" the polarity of the output. I think sometimes it gets it wrong, and inverts the waveform by mistake.

    It looks to me like there is a race condition between when the CC[2] is captured and when the TASKS_OUT is written, though I think the safe_margins_present() is supposed to prevent that. I tried increasing the pwm_cc_margin_by_prescaler[] for my prescaler, but this did not help.

    Any suggestions?

  • @plskeggs: I believe by "power down" he wanted to mention SystemON with CPU turn off (_WFE()).

    Do you still have trouble with PWM ? If possible please attach a project that shows the issue, I can try to test it here.

Reply Children
No Data
Related