FAN Detection Demo
1 Demo overview
This demo shows how to test the fan interface on the development board to start, stop, and adjust the speed of a fan.
2 FAN interface overview
The board's FAN interface is a 4-pin connector, but only three pins are active: 12V, PWM, and GND. The fan is controlled (start/stop and speed) via a PWM signal.
3 Procedure
Open a terminal and copy the executable smdt_fan_demo from this demo's bin directory (05-Development Materials\Software Development Materials\linux_demo\smdt_fan_demo\bin) to the board's filesystem (the source code is available under the src path).
Optional: Because the board has a wireless network card, if the terminal keeps printing log messages generated by the wireless driver, you can change the Linux kernel log level with the following command.
#修改 Linux 内核日志的显示级别,内核的日志级别被设置为只显示紧急或更高级别的消息
echo 1 4 1 7 > /proc/sys/kernel/printkFirst check whether the PWM device has been exported. If it has not, you need to export it. Here we choose the device pwmchip0 and export its first channel (pwm0).
#检查 /sys/class/pwm/pwmchip0 目录中是否有 pwm0
ls /sys/class/pwm/pwmchip0
#若没有,则导出 PWM 设备
echo 0 > /sys/class/pwm/pwmchip0/export
#再次检查是否成功导出 PWM 设备
ls /sys/class/pwm/pwmchip0In the terminal, run the following commands to switch to the directory containing the smdt_fan_demo executable.
#切换到 smdt_fan_demo 可执行程序所在目录
cd ‘可执行文件所在目录’
#查看 smdt_fan_demo 是否在该目录下
lsIf the executable smdt_fan_demo is in the current directory, change its permissions.
#修改文件权限
chmod 777 smdt_fan_demo
#查询是否修改成功
ls -ld smdt_fan_demoAfter confirming the permission change succeeded, run ./smdt_fan_demo -h to view the program's help information. Some default parameters set in this test script are as follows:
- period: 200000, i.e. the PWM waveform period is 200ms.
- polarity: normal — in this mode,
duty_cyclerepresents the duration of the high level within one period.
#查看帮助信息
./smdt_fan_demo -hThe result is shown below:

Run the following commands to start, stop, and adjust the fan speed.
#查看帮助信息
#风扇启动
./smdt_fan_demo -s
#风扇调速
./smdt_fan_demo -p 50 #50%占空比
#风扇停止
./smdt_fan_demo -kFan start result:

Fan at 50% duty cycle result:

Fan stop result:
