#include <zephyr.h>
#include <device.h>
#include <drivers/pwm.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(main);
#define MOTOR_PWM DT_NODELABEL(pwm0)
void main(void) {
const struct device *pwm_dev = DEVICE_DT_GET(MOTOR_PWM);
if (!device_is_ready(pwm_dev)) {
LOG_ERR("PWM device not ready");
return;
}
while (1) {
int ret = pwm_pin_set_usec(pwm_dev, PWM_PIN, 1000, 500, PWM_POLARITY_NORMAL);
if (ret) {
LOG_ERR("PWM set failed: %d", ret);
return;
}
k_sleep(K_MSEC(1000));
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/pwm.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(main);
#define MOTOR_PWM DT_NODELABEL(pwm0)
void main(void) {
const struct device *pwm_dev = DEVICE_DT_GET(MOTOR_PWM);
if (!device_is_ready(pwm_dev)) {
LOG_ERR("PWM device not ready");
return;
}
while (1) {
int ret = pwm_pin_set_usec(pwm_dev, PWM_PIN, 1000, 500, PWM_POLARITY_NORMAL);
if (ret) {
LOG_ERR("PWM set failed: %d", ret);
return;
}
k_sleep(K_MSEC(1000));
}
}