Buzzer/en: различия между версиями
(Новая страница: «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.») |
||
Строка 2: | Строка 2: | ||
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. | 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. | |||
Экспорт порта в sysfs: | Экспорт порта в sysfs: |
Версия 19:54, 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.
Экспорт порта в 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