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

Материал из Wiren Board
(Новая страница: «Sets the period in nanoseconds. The conversion from frequency(from kilohertz per period in nanoseconds is produced by the formula: <b> T(ns) = 1 000 000 / f(kHz)…»)
Строка 13: Строка 13:
<br/>
<br/>


Установка периода в наносекундах. Пересчёт из частоты(в килогеграцах в период в наносекундах производится по формуле:
Sets the period in nanoseconds. The conversion from frequency(from kilohertz per period in nanoseconds is produced by the formula:
<b>
<b>
T(ns) = 1 000 000 / f(kHz)
T(ns) = 1 000 000 / f(kHz)

Версия 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

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 # устанавливаем период в 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

Пример