Buzzer/en: различия между версиями

Материал из Wiren Board
(Новая страница: «<pre> echo 250000 > /sys/class/pwm/pwmchip0/pwm2/period # set the period to 250 000 NS, ie 250mks, which corresponds to a frequency of 4kHz </pre>»)
(Новая страница: «Setting the duty_cycle (the duration of the high state) in nanoseconds. Maximum volume is reached at duty_cycle = period / 2»)
Строка 22: Строка 22:
</pre>
</pre>


Установка duty_cycle (длительности высокого состояния) в наносекундах. Максимальная громкость достигается при duty_cycle = period / 2
Setting the duty_cycle (the duration of the high state) in nanoseconds. Maximum volume is reached at duty_cycle = period / 2


<pre>
<pre>

Версия 19:56, 28 мая 2019

Другие языки:

The sound emitter is connected to the PWM output in the Wiren Board Smart Home controller and is controlled via the sysfs kernel interface. The PWM port number is 2.

PWM is a rectangular pulse, the core interface allows you to adjust the pulse rate and fill factor. Coeffecient filling effect on the sound volume.

Exporting port to sysfs:

echo 2 > /sys/class/pwm/pwmchip0/export

After that, the /sys/class/pwm/pwmchip0/pwm2 folder appears


Sets the period in nanoseconds. The conversion from frequency(from kilohertz per period in nanoseconds is produced by the formula: T(ns) = 1 000 000 / f(kHz)

echo 250000 > /sys/class/pwm/pwmchip0/pwm2/period # set the period to 250 000 NS, ie 250mks, which corresponds to a frequency of 4kHz

Setting the duty_cycle (the duration of the high state) in nanoseconds. Maximum volume is reached at duty_cycle = period / 2

echo 125000 > /sys/class/pwm/pwmchip0/pwm2/duty_cycle # устанавливаем duty_cycle в 125 000 нс, т.е. в половину периода


Включение выхода ШИМ:

echo 1 > /sys/class/pwm/pwmchip0/pwm2/enable

Выключение:

echo 0 > /sys/class/pwm/pwmchip0/pwm2/enable

Пример