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

Материал из Wiren Board
(Новая страница: «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: <pre> echo 2 > /sys/class/pwm/pwmchip0/export </pre>»)
Строка 4: Строка 4:
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.
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.


Экспорт порта в sysfs:
Exporting port to sysfs:
<pre>
<pre>
echo 2 > /sys/class/pwm/pwmchip0/export
echo 2 > /sys/class/pwm/pwmchip0/export

Версия 19:55, 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

После этого появляется директория /sys/class/pwm/pwmchip0/pwm2


Установка периода в наносекундах. Пересчёт из частоты(в килогеграцах в период в наносекундах производится по формуле: T(ns) = 1 000 000 / f(kHz)

echo 250000 > /sys/class/pwm/pwmchip0/pwm2/period # устанавливаем период в 250 000 нс, т.е. в 250мкс, что соответствует частоте 4кГц

Установка duty_cycle (длительности высокого состояния) в наносекундах. Максимальная громкость достигается при 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

Пример