Similar to t_m's post here (only in a different SDK), I am trying to generate two PWM signals (motor1_fwd_pwm & motor2_fwd_pwm) in 180 degrees phase shift in respect to each other.
I'm using SDK 17.1.0 and an nRF52833 module; currently I am initializing my PWM signals like so:
uint32_t err_code;
low_power_pwm_config_t low_power_pwm_config;
APP_TIMER_DEF(lpp_timer_0);
low_power_pwm_config.active_high = true;
low_power_pwm_config.period = STD_PERIOD;
low_power_pwm_config.bit_mask = BSP_M1_IN1_MASK;
low_power_pwm_config.p_timer_id = &lpp_timer_0;
low_power_pwm_config.p_port = NRF_GPIO;
err_code = low_power_pwm_init((&motor1_fwd_pwm), &low_power_pwm_config, pwm_handler);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_duty_set(&motor1_fwd_pwm, 0);
APP_ERROR_CHECK(err_code);
APP_TIMER_DEF(lpp_timer_1);
low_power_pwm_config.active_high = true;
low_power_pwm_config.period = STD_PERIOD;
low_power_pwm_config.bit_mask = BSP_M1_IN2_MASK;
low_power_pwm_config.p_timer_id = &lpp_timer_1;
low_power_pwm_config.p_port = NRF_GPIO;
err_code = low_power_pwm_init((&motor1_rvs_pwm), &low_power_pwm_config, pwm_handler);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_duty_set(&motor1_rvs_pwm, 0);
APP_ERROR_CHECK(err_code);
APP_TIMER_DEF(lpp_timer_2);
low_power_pwm_config.active_high = true;
low_power_pwm_config.period = STD_PERIOD;
low_power_pwm_config.bit_mask = BSP_M2_IN1_MASK;
low_power_pwm_config.p_timer_id = &lpp_timer_2;
low_power_pwm_config.p_port = NRF_GPIO;
err_code = low_power_pwm_init((&motor2_fwd_pwm), &low_power_pwm_config, pwm_handler);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_duty_set(&motor2_fwd_pwm, 0);
APP_ERROR_CHECK(err_code);
APP_TIMER_DEF(lpp_timer_3);
low_power_pwm_config.active_high = true;
low_power_pwm_config.period = STD_PERIOD;
low_power_pwm_config.bit_mask = BSP_M2_IN2_MASK;
low_power_pwm_config.p_timer_id = &lpp_timer_3;
low_power_pwm_config.p_port = NRF_GPIO;
err_code = low_power_pwm_init((&motor2_rvs_pwm), &low_power_pwm_config, pwm_handler);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_duty_set(&motor2_rvs_pwm, 0);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_start((&motor1_fwd_pwm), motor1_fwd_pwm.bit_mask);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_start((&motor1_rvs_pwm), motor1_rvs_pwm.bit_mask);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_start((&motor2_fwd_pwm), motor2_fwd_pwm.bit_mask);
APP_ERROR_CHECK(err_code);
err_code = low_power_pwm_start((&motor2_rvs_pwm), motor2_rvs_pwm.bit_mask);
APP_ERROR_CHECK(err_code);
I tried setting the active_high property to false for one and true for the other, but this led to other undesired effects. Is there a way to simply delay one of the timers by 1/2 period?