Jetson Nano-PWM自动调速

由于Nano散热差时,会造成宕机等问题,所以必须配上风扇,PWM最佳

手动设置

PWM范围:0 - 255
最小0即不转,255为最大转速

sudo sh -c 'echo 255 > /sys/devices/pwm-fan/target_pwm' 

运行后,若风扇引脚正确,则此时风扇会以最大速度运行

自动调速

  • 编写自动运行的py文件
#!/usr/bin/env python
import os
# import commands

# from the path of this pattern
path = '/sys/kernel/debug/soctherm/{dev}/temp'
# get the temperature from following sensors
dev = ['cpu', 'gpu', 'mem', 'pll']
# the fan PWM factor is 0 ~ 255, make 10 as the min, 255 as the max
# the fan speed will be sliding from 10% ~ 100% according to the temperature
# the greater, the cooler yet noisier, this script will balance it
MIN=80
MAX=255
RANGE=MAX-MIN
# the target file to write PWM factor to control the fan speed
TARGET_PWM = '/sys/devices/pwm-fan/target_pwm'

# defined the lowest temperature (Celsius), fan speed at MIN if temp lower then this
LOWEST=38.0
# defined the highest temperature (Celsius), fan speed at MAX if temp higher then this
HIGHEST=60.0
# the temp at range between HIGHEST and LOWEST, the fan speed is auto ajusted
# to balance the cool and the quiet
TMP_RANGE=HIGHEST-LOWEST

def getTmpFromFile(p):
    '''get temp value in Celsius from a file'''
    with open(p, 'r') as f:
        x = f.read()
        y = int(x)/1000.0
        return y

def getSpeedByTemp(temp):
    '''calculate a fan speed pwm factor from a temperature in Celsius'''
    if temp<=LOWEST-5:
        return 0
    if temp<=LOWEST:
        return MIN
    if temp>=HIGHEST:
        return MAX
    
    rate = (temp-LOWEST)/TMP_RANGE
    return MIN+int(RANGE*rate) if rate<1.0 else MAX
        
def setSpeed(pwm):
    '''write target PWM factor to the target file to set fan speed'''
    with open(TARGET_PWM, 'w') as f:
        f.write(str(pwm))

# get max temperature from all sensors
max_temp = max(map(getTmpFromFile, map(lambda x: path.format(dev=x), dev)))
print(max_temp)
# calculate the target fan pwm factor
target_speed = getSpeedByTemp(max_temp)
print(target_speed)
# set to target file to take effect
setSpeed(target_speed)
  • 开机自启,编写/etc/rc.local文件如下
#!/bin/bash
sudo /usr/bin/jetson_clocks
nohup sudo watch -n 20 '/usr/bin/python /root/adj_fan_pwm.py > /tmp/fan_pwm_log.log' &

即每20秒运行一次,其中/root/adj_fan_pwm.py 记为上面到py文件,并将运行的log保存到/tmp/fan_pwm_log.log

实时观察状态:jtop

在这里插入图片描述

  • 创建rc-local.service文件
sudo vi /etc/systemd/system/rc-local.service
  • 复制以下内容到rc-local.service文件
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
  • 设置rc.local的权限
sudo chmod +x /etc/rc.local
  • 启动服务
sudo systemctl enable rc-local
  • 开启服务和查看状态
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值