06 FAN Detection Case
1 Case Introduction
This case aims to introduce how to test the fan interface on the development board to control the fan start, stop and speed regulation functions.
2 FAN Interface Introduction
The FAN interface on the development board is a 4P interface, but only three ports are functional, namely 12V, PWM, and GND. The fan is debugged through PWM signal control.
3 Operation process
Open the terminal and copy the executable program smdt_fan_demo in the bin directory of this case (05-Development Materials\Software Development Materials\linux_demo\smdt_fan_demo\bin) to the development board file system (the source code can be viewed in the src path).
Optional operation: Because the development board is equipped with a wireless network card, if the terminal keeps displaying the log information generated by the wireless network card driver, you can modify the display level of the Linux kernel log by using the following code.
#修改 Linux 内核日志的显示级别,内核的日志级别被设置为只显示紧急或更高级别的消息
echo 1 4 1 7 > /proc/sys/kernel/printk
First check if the PWM device is exported. If it is not exported, we need to export the PWM device. Here we select the device pwmchip0 to export the 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/pwmchip0
Execute the following command in the terminal to switch to the directory where the smdt_fan_demo executable program is located
#切换到 smdt_fan_demo 可执行程序所在目录
cd ‘可执行文件所在目录’
#查看 smdt_fan_demo 是否在该目录下
ls
If the executable file smdt_fan_demo is in the current directory, modify the permissions of the executable file
#修改文件权限
chmod 777 smdt_fan_demo
#查询是否修改成功
ls -ld smdt_fan_demo
After confirming that the file modification permission is successful, execute ./smdt_fan_demo -h to view the help information of the program. The default parameters of some settings in this test script are as follows: period: 200000, that is, the PWM waveform period is 200ms polarity: normal In this mode, duty_cycle represents the duration of the high level in one cycle.
#查看帮助信息
./smdt_fan_demo -h
The execution result is as follows:

Enter the following command to test the start, stop and speed regulation of the fan.
#查看帮助信息
#风扇启动
./smdt_fan_demo -s
#风扇调速
./smdt_fan_demo -p 50 #50%占空比
#风扇停止
./smdt_fan_demo -k
Fan startup execution result:

The fan is set to 50% duty cycle execution result:

Fan stop execution result: