Hi,
I'm trying to play some sounds on a piezo with the help of the pwm. I tried to set the period with pwm_set_dt but only the first call is successful and every subsequent call raised an error.
Here is my test code:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
for(uint16_t i = 400; i < 800; i++)
{
int ret = pwm_set_dt(&piezo_pwm_pos, PWM_HZ(i),
PWM_HZ(i) / 2);
LOG_DBG("pwm_set_dt = %d", ret);
ret = pwm_set_dt(&piezo_pwm_neg, PWM_HZ(i),
PWM_HZ(i) / 2);
LOG_DBG("pwm_set_dt = %d", ret);
k_msleep(10);
}
The results looked like this:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
00> D: pwm_set_dt = 0
00> D: pwm_set_dt = 0
00> E: Incompatible period.
00> D: pwm_set_dt = -22
00> E: Incompatible period.
00> D: pwm_set_dt = -22
00> E: Incompatible period.
00> D: pwm_set_dt = -22
00> E: Incompatible period.
00> D: pwm_set_dt = -22
00> E: Incompatible period.
00> D: pwm_set_dt = -22
I didn't find anything in the documentation of pwm_set for the error 22.
How can I change period and pulse while the pwm is running?
Best regards,
Christian