Hello
I am using sdk v17.0 and pwm_library example.
I'd like to add a 'dead time' of 10us between the two PWM channels.
Can you give me a good example or method for this?
(Attempt to create dead time using nrf_delay failed.)
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "app_error.h"
#include "bsp.h"
#include "nrf_delay.h"
#include "app_pwm.h"
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1.
static volatile bool ready_flag; // A flag indicating PWM status.
void pwm_ready_callback(uint32_t pwm_id) // PWM callback function
{
ready_flag = true;
}
int main(void)
{
ret_code_t err_code;
/* 2-channel PWM, 200Hz, output on DK LED pins. */
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(20, 23, 24);
/* Switch the polarity of the second channel. */
pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
/* Initialize and enable PWM. */
err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM1);
while (true)
{
ready_flag = false;
//while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 0, 50)); //1-channel
nrf_delay_us(10); //dead time
/* ... or wait for callback. */
//while (!ready_flag);
APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 1, 40)); //2-channel
}
}
Thank you!