Jump to content

Recommended Posts

Posted

Hi all,

 

So if a lot of you maybe know is a heatsink and fan  a must for the OrangePi 4. With my temporarly installed fan makes a lot of noise i maked yesterday the step to order a Noctua NF-A4x20 5V PWM. The price was arround €17,- not the cheapest but te reviews are amazing.

 

Even on full speed its a lot more silence then the 20x20 mini fan but with a good air flow. But as you could read did i choose for a PWM variant so i could control the rpm´s with a PWM GPIO pin. And amazingly it did work! I have the PWM pin connected to pin 7 of the OrangePi 4.

 

Commands to start pwm for the first time:

 

cd /sys/class/pwm/pwmchip1/
echo 0 > export
  
echo 1000000 > pwmchip1/pwm0/period

echo 500000 > pwm0/duty_cycle
  
#and with this step the fan goes on a lower speed
  
echo 1 > pwm0/enable

#and back on full speed without PWM

echo 0 > pwm0/enable

 

So it´s really nice. And i found a nice script for the Nanopi M4 with also a RK3399 chip from @mar0ni in this topic

 

To make it complete i paste also here the script from @mar0n

Posted
Just now, haajee said:

Hi all,

 

So if a lot of you maybe know is a heatsink and fan  a must for the OrangePi 4. With my temporarly installed fan makes a lot of noise i maked yesterday the step to order a Noctua NF-A4x20 5V PWM. The price was arround €17,- not the cheapest but te reviews are amazing.

 

Even on full speed its a lot more silence then the 20x20 mini fan but with a good air flow. But as you could read did i choose for a PWM variant so i could control the rpm´s with a PWM GPIO pin. And amazingly it did work! I have the PWM pin connected to pin 7 of the OrangePi 4.

 

Commands to start pwm for the first time:

 


cd /sys/class/pwm/pwmchip1/
echo 0 > export
  
echo 1000000 > pwmchip1/pwm0/period

echo 500000 > pwm0/duty_cycle
  
#and with this step the fan goes on a lower speed
  
echo 1 > pwm0/enable

#and back on full speed without PWM

echo 0 > pwm0/enable

 

So it´s really nice. And i found a nice script for the Nanopi M4 with also a RK3399 chip from @mar0ni in this topic

 

To make it complete i paste also here the script from @mar0ni

 


#!/bin/bash

if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip1/pwm0 ];
do
    sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

# max speed run 5s
echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
sleep 5
echo 49994 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

declare -a CpuTemps=(75000 63000 58000 52000 48000 0)
declare -a PwmDutyCycles=(25000 37000 48300 49250 49300 49994)

while true
do
	temp=$(cat /sys/class/thermal/thermal_zone0/temp)
	for i in 0 1 2 3 4 5; do
		if [ $temp -gt ${CpuTemps[$i]} ]; then
			DUTY=${PwmDutyCycles[$i]}
			echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";
			#echo "temp: $temp, target: ${CpuTemps[$i]}, duty: $DUTY"
			break		
		fi
	done
	sleep 2s;
done

 

I saved the file in my home dir as pwm-fan.sh and run it as administrator with

bash ./pwm-fan.sh

And the fan spins up full speed but after that it stops running. Even when the temperature is over the 30 degrees celsius. I have changed 48000 in the above script to 30000. So i think there is also something else to change but i have no idea what. Who could help me? :)

Posted
On 4/19/2020 at 6:25 AM, VyacheslavS said:

@haajee,

I have for some reason does not work, there is no signal from the 7 pin.

Kernel 5.6.3 Buster.

What else do I need to do to make it work?

 

Oh sorry i didn´t saw your post. My fan script is now:

 

#!/bin/bash

if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip1/pwm0 ];
do
    sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

# max speed run 60s
echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
sleep 5
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

declare -a CpuTemps=(45000 40000 38000 30000 28000 0)
declare -a PwmDutyCycles=(1000 5000 10000 15000 30000)

while true
do
        temp=$(cat /sys/class/thermal/thermal_zone0/temp)
        for i in 0 1 2 3 4 5; do
                if [ $temp -gt ${CpuTemps[$i]} ]; then
                        DUTY=${PwmDutyCycles[$i]}
                        echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";
                        echo "temp: $temp, target: ${CpuTemps[$i]}, duty: $DUTY"
                        break
                fi
        done
        sleep 1s;
done

Do you see something if you go to /sys/class/pwm/pwmchip1?  And do you have installed wiring orangepi from:  https://github.com/orangepi-xunlong/wiringOP ?? what does the command gpio readall shows?

Posted
On 7/9/2020 at 2:45 AM, haajee said:

what does the command gpio readall shows?

$ gpio readall shows
 +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | GPIO |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |  1 || 2  |   |      | 5V       |     |      |
 |   64 |   0 | I2C2_SDA |   IN | 0 |  3 || 4  |   |      | 5V       |     |      |
 |   65 |   1 | I2C2_SCL |   IN | 0 |  5 || 6  |   |      | GND      |     |      |
 |  150 |   2 |     PWM1 | ALT2 | 1 |  7 || 8  | 1 | ALT2 | I2C3_SCL | 3   | 145  |
 |      |     |      GND |      |   |  9 || 10 | 1 | ALT2 | I2C3_SDA | 4   | 144  |
 |   33 |   5 | GPIO1_A1 |   IN | 0 | 11 || 12 | 1 | IN   | GPIO1_C2 | 6   | 50   |
 |   35 |   7 | GPIO1_A3 |  OUT | 1 | 13 || 14 |   |      | GND      |     |      |
 |   92 |   8 | GPIO2_D4 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO1_C6 | 9   | 54   |
 |      |     |     3.3V |      |   | 17 || 18 | 0 | IN   | GPIO1_C7 | 10  | 55   |
 |   40 |  11 | SPI1_TXD | ALT3 | 0 | 19 || 20 |   |      | GND      |     |      |
 |   39 |  12 | SPI1_RXD | ALT3 | 1 | 21 || 22 | 0 | IN   | GPIO1_D0 | 13  | 56   |
 |   41 |  14 | SPI1_CLK | ALT3 | 1 | 23 || 24 | 1 | ALT3 | SPI1_CS  | 15  | 42   |
 |      |     |      GND |      |   | 25 || 26 | 0 | IN   | GPIO4_C5 | 16  | 149  |
 |   64 |  17 | I2C2_SDA |   IN | 0 | 27 || 28 | 0 | IN   | I2C2_SCL | 18  | 65   |
 |      |     |  I2S0_RX |      |   | 29 || 30 |   |      | GND      |     |      |
 |      |     |  I2S0_TX |      |   | 31 || 32 |   |      | I2S_CLK  |     |      |
 |      |     | I2S0_SCK |      |   | 33 || 34 |   |      | GND      |     |      |
 |      |     | I2S0_SI0 |      |   | 35 || 36 |   |      | I2S0_SO0 |     |      |
 |      |     | I2S0_SI1 |      |   | 37 || 38 |   |      | I2S0_SI2 |     |      |
 |      |     |      GND |      |   | 39 || 40 |   |      | I2S0_SI3 |     |      |
 +------+-----+----------+------+---+----++----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | GPIO |
 +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+

 

On 7/9/2020 at 2:45 AM, haajee said:

Do you see something if you go to /sys/class/pwm/pwmchip1?

$ ls /sys/class/pwm/pwmchip1
device  export  npwm  power  subsystem  uevent  unexport

I don't have a pwm0 folder.

 

On 7/9/2020 at 2:45 AM, haajee said:

And do you have installed wiring orangepi from:  https://github.com/orangepi-xunlong/wiringOP ??

Yes.

Posted

@haajee , This is a problem with my cooler.  It starts rotating with 3.3 V. If the tension is less, then silence.

I took voltage measurements from 7 pin.  The voltage on this pin is: min=1.0 V, max=2.9 V.

Tell me please did you connect Noctua NF-A4x20 5V PWM directly or via MOSFET?

In Noctua cooler with 4 pins or 3 pins?

Posted
On 7/11/2020 at 2:25 PM, VyacheslavS said:

@haajee , This is a problem with my cooler.  It starts rotating with 3.3 V. If the tension is less, then silence.

I took voltage measurements from 7 pin.  The voltage on this pin is: min=1.0 V, max=2.9 V.

Tell me please did you connect Noctua NF-A4x20 5V PWM directly or via MOSFET?

In Noctua cooler with 4 pins or 3 pins?

 

Very sorry for my always late anwsers. I have my nf-a4x20-5v-pwm directly connected to gnd and 5V pin on the orange pi. The PWM pin do i have connected to pin 7. The RPM pin did i have not connected. I have bought the Noctua in a local internet store for arround €12,- without shipping. The fan is also on full speed so much silent than al the fans i got. I am a really Fanboy now of Noctua ;) I could advice you to buy. :) more specifications are here https://noctua.at/en/products/fan/nf-a4x20-5v-pwm

 

All what you post is exactly the same what i have... I don´t see a different.

 

Posted
On 8/2/2020 at 3:32 AM, haajee said:

I have bought the Noctua in a local internet store for arround €12,- without shipping.

 

I also bought the same one, about 15 Euros.  I configured the script and now it starts to rotate from +35, the rotation speed is floating. The maximum spin speed starts at +60 . This cooler is really quiet and worth it money.

Posted

Another solution to avoid noise and fan management for orange pi 4 is to use a big heatsink (fanless solution):

 

Orange Pi 4 Heatsink

 

I tried it and it works well.

 

The temperature can rise to 85°C in peak (and 82°C in average) when I tried to stress the cpu with benchmark or with high resolution youtube video, but I never stayed stuck due to a overheat.

In normal use, I have more something between 58 to 65 °C.

Posted

My device is only equipped with this tiny cooling set:

Spoiler

cooling-set.jpg.da9d3d4d8c43da51a990b00191fe967b.jpg

Even though all six cores run at 100% load, the fan only runs at full speed for two occasions:

Spoiler

tmon-log.thumb.png.dbd7171871b9e87d2edaaa76c9ff7156.png

Frequency scaling and DVFS haven't even begun yet. The kernel is handling the thermal system, no user space involved. Maybe time to collect tmon's log and investigate how the thermal system is performing.

Posted
On 8/8/2020 at 11:47 AM, firedgje said:

Another solution to avoid noise and fan management for orange pi 4 is to use a big heatsink (fanless solution):

 

Orange Pi 4 Heatsink

 

I tried it and it works well.

 

The temperature can rise to 85°C in peak (and 82°C in average) when I tried to stress the cpu with benchmark or with high resolution youtube video, but I never stayed stuck due to a overheat.

In normal use, I have more something between 58 to 65 °C.

 

IMHO is 85 celsius really hot. I don´t also know how a big themalpad could work. Is the heatsink warm when you run?

 

On 8/3/2020 at 2:04 PM, VyacheslavS said:

 

I also bought the same one, about 15 Euros.  I configured the script and now it starts to rotate from +35, the rotation speed is floating. The maximum spin speed starts at +60 . This cooler is really quiet and worth it money.

 

Mine have i running really slow and the temperature is arround 32 degrees on normal day with normal load. Full speed about 50 degrees. But i need to say that i have also a heatsink on the CPU from an old Fritzbox router. But even on fullspeed is the fan really quiet and you need to listen very well to here it run. In my opinion is 15 euros a really good deal when i compare with a lot of noisie fans i have. The only problem is that the fan is a little bit bigger than the fan opening of the Geekworm case... So i din´t have the original cover on the case...

 

temperatuur-laatste-maan.thumb.jpeg.681e4f8d8484fd9b70a60660060cc496.jpeg

Posted
On 8/9/2020 at 10:06 PM, haajee said:

 

IMHO is 85 celsius really hot. I don´t also know how a big themalpad could work. Is the heatsink warm when you run?

Yes, the heatsink could be warm. But as I said globally always around 82°C with all cpus at 100%, (and decrease quickly when I stop). I think the processor limit ~85 °C.

On 8/9/2020 at 10:06 PM, haajee said:

 

 

Mine have i running really slow and the temperature is arround 32 degrees on normal day with normal load. Full speed about 50 degrees. But i need to say that i have also a heatsink on the CPU from an old Fritzbox router. But even on fullspeed is the fan really quiet and you need to listen very well to here it run. In my opinion is 15 euros a really good deal when i compare with a lot of noisie fans i have. The only problem is that the fan is a little bit bigger than the fan opening of the Geekworm case... So i din´t have the original cover on the case...

 

temperatuur-laatste-maan.thumb.jpeg.681e4f8d8484fd9b70a60660060cc496.jpeg

I tested previously another solution with a little heatsink and a fan, the temperature was also around 50°C. It is a personal choice to change in order to have no noise, because I use it as pc and as media center.

Posted
On 8/11/2020 at 9:04 PM, firedgje said:

Yes, the heatsink could be warm. But as I said globally always around 82°C with all cpus at 100%, (and decrease quickly when I stop). I think the processor limit ~85 °C.

I tested previously another solution with a little heatsink and a fan, the temperature was also around 50°C. It is a personal choice to change in order to have no noise, because I use it as pc and as media center.

I did a more complete temperature  test with cpu sysbench during a long time:

 

Temperature Test
 
N°: T0°C T1°C
1:  79°C 79°C
2:  82°C 83°C
3:  83°C 83°C
4:  83°C 82°C
5:  83°C 83°C
6:  82°C 82°C
7:  83°C 83°C
8:  83°C 83°C
9:  83°C 83°C
10:  83°C 83°C
11:  83°C 83°C
12:  83°C 83°C
13:  83°C 83°C
14:  82°C 83°C
15:  83°C 83°C
16:  83°C 83°C
17:  83°C 83°C
18:  83°C 83°C
19:  82°C 83°C
20:  83°C 83°C

 

The temperature never exceeds 83°C.

Posted
2 hours ago, firedgje said:

I did a more complete temperature  test with cpu sysbench

Out of curiosity, I'm interested in how your thermal system works during the test.
Can you by chance provide a tmon.log?
To collect one, start "tmon -dl", perform your thermal stress test and after round about 15 minutes kill the tmon process.
Now post the resulting /var/tmp/tmon.log.

Posted
On 8/15/2020 at 5:57 PM, usual user said:

Out of curiosity, I'm interested in how your thermal system works during the test.
Can you by chance provide a tmon.log?
To collect one, start "tmon -dl", perform your thermal stress test and after round about 15 minutes kill the tmon process.
Now post the resulting /var/tmp/tmon.log.

Sorry, tmon package seems not to be available.... but I can give you my simple test script:

 

#!/bin/bash
clear

echo "Temperature Test"
echo " "
echo "N°: T0°C T1°C"

for i in {1..50}
do
    a=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)
    b=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone1/temp) / 1000)
    echo "$i:  $a°C $b°C"
    sysbench cpu --cpu-max-prime=1000000 --threads=$(nproc) run > /dev/null
done

a=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone0/temp) / 1000)
b=$(expr $(cat /sys/devices/virtual/thermal/thermal_zone1/temp) / 1000)
echo "$i:  $a°C $b°C"

exit 0

 

Posted
On 8/16/2020 at 9:33 PM, firedgje said:

but I can give you my simple test script:

I've run it three times in a row.
This is the visualization of the tmon log, which shows how my thermal system is performing:

Spoiler

tmon-log.thumb.png.29b7d2f664b001e078fb0b14850e0823.png

 

Posted (edited)

Hi all,

 

This is my upgrade. Mean temperature Epoch PWM FAN regulator for Orange Pi 4/4B for Noctua NF-A4x10 5V PWM, Noctua NF-A4x20 5V PWM.

 

$ sudo systemctl status fanepoch
● fanepoch.service - Mean temperature Epoch PWM FAN regulator
     Loaded: loaded (/etc/systemd/system/fanepoch.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-06-22 21:24:01 CEST; 2min 28s ago
   Main PID: 13074 (epochpwmfan_op4)
      Tasks: 2 (limit: 4459)
     Memory: 516.0K
     CGroup: /system.slice/fanepoch.service
             ├─13074 /bin/bash /usr/local/sbin/epochpwmfan_op4 -e 10
             └─13374 /usr/bin/sleep 10

čen 22 21:25:11 NAS epochpwmfan_op4[13074]: [0]53333 [1]55000 [2]53333 [3]59444 [4]53333 [5]55000 [6]52777
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: Calculate and create RPM list from DutyCycles array
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[0]: temp 82, duty_cycle 0, rpm 5000
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[1]: temp 80, duty_cycle 4705, rpm 4415
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[2]: temp 75, duty_cycle 12549, rpm 3440
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[3]: temp 65, duty_cycle 20392, rpm 2466
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[4]: temp 55, duty_cycle 23529, rpm 2062
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[5]: temp 45, duty_cycle 28235, rpm 1478
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: RPMLIST[6]: temp 0, duty_cycle 32000, rpm 1004
čen 22 21:25:11 NAS epochpwmfan_op4[13074]: temp 51, epoch 54, target 45, duty 28235, rpm 1478

 

Bash script epochpwmfan_op4 with installation instructions in systemd, but also works via init.d, etc...

Spoiler

#!/bin/bash
if [ $# -eq 0 ];
 then
cat << EOF
Mean temperature Epoch PWM FAN regulator for Orange Pi 4/4B - peepr
for Noctua NF-A4x10 5V PWM, Noctua NF-A4x20 5V PWM

Syntax: epochpwmfan_op4 <[-c <N sec> : Classic ||-e <N sec> : Epoch]>

Info: -e Define interval durations between temperature measuring and
 update/control PWM in second.
 One epoch contains 7 intervals. Default interval is 1s.
 Recommended for control PWM with mean Epochs is 3s(= 3x7=21s) to 10s(= 10x7=70s), etc..
 My recommendation is -e 10, ideal for heavy load, at ambient temperature air 21°C
 the CPU temperature will not exceed 62°C.
 
Examples: epochpwmfan_op4 -e 10

Installation instructions: look in the code
EOF
exit 0
fi

#INSTALLATION INSTRUCTIONS:
#sudo cp epochpwmfan_op4 /usr/local/sbin/epochpwmfan_op4
#sudo chmod 755 /usr/local/sbin/epochpwmfan_op4
#sudo geany /etc/systemd/system/fanepoch.service
#--- START ---- insert this line (uncomment!) to fanepoch.service (you can change the switches here according to your preferences in ExecStart)
#[Unit]
#Description=Mean temperature Epoch PWM FAN regulator
#After=syslog.target
#[Service]
#Type=simple
#User=root
#Restart=on-failure
#RestartSec=5s
#ExecStart=/usr/local/sbin/epochpwmfan_op4 -e 10
#[Install]
#WantedBy=multi-user.target
#---  END -----
#sudo chmod 644 /etc/systemd/system/fanepoch.service
#sudo systemctl daemon-reload
#sudo systemctl enable fanepoch
#sudo systemctl start fanepoch
#Check status: sudo systemctl status fanepoch

if [ "$(id -u)" != "0" ]; then
echo "[!] must be root." 1>&2
exit 1
fi

declare -i PERIOD=40000
THA=false #no edit
SLEEPTIME=1 #default
declare -i temp=0
declare -i measuretemp=0

declare -i THAS=6  #temphistory_array_size
THERMAL_ZONE0="/sys/class/thermal/thermal_zone0/temp"

if [ $# -eq 2 ]; then
SLEEPTIME=$2
fi
#activation only with switch -e
if [ "$1" == "-e" ]; then
	THA=true
	declare -a temphistory_array
	declare -i ACTUAL_EPOCH_MEAN_TEMP=0
	echo "Create first Epoch array real temperature - duration $(($SLEEPTIME*(THAS+1))) sec, interval $SLEEPTIME sec"
	for i in $(eval echo "{0..$THAS}");
	do	temphistory_array+=($(cat $THERMAL_ZONE0))
		echo -n "[$i]${temphistory_array[$i]} "
		/usr/bin/sleep $SLEEPTIME
	done
	echo ""
	#Calculation of the actual epoch mean
	ACTUAL_EPOCH_MEAN_TEMP=$(((${temphistory_array[@]/%/+}0)/($THAS+1)))
fi

#Enable PWM regulation
if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi

ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi

# Noctua PWM specification: https://noctua.at/pub/media/wysiwyg/Noctua_PWM_specifications_white_paper.pdf
# Range PWM - minimal: 21kHz (47618ns) to maximum: 28kHz (35714ns). RECOMMENDED is 25kHz (40000ns).
# Convert kHz to ns: https://www.google.com/search?q=period+to+frequency+calculator
echo $PERIOD > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

declare -a CpuTemps=(82000 80000 75000 65000 55000 45000 0)

# duty_cycle 40000 = the fan stop. My fan is Noctua NF-A4x10 5V PWM
# - GPIO [yellow cable - +5V in pin2 or pin4, black cable - GND in pin6, blue cable - PWM Signal in pin7]. Look here - run "gpio readall"
# - My fan spins up from off to 38200ns (~250-300rpm) but that can't realistically be used.

declare -a DutyCycles=(0 4705 12549 20392 23529 28235 32000)

#!Calculation formula +- only for Noctua NF-A4x10 5V PWM, Noctua NF-A4x20 5V PWM!
#! - is only but informational and does not control anything					!
echo "Calculate and create RPM list from DutyCycles array" #for speed up script - we avoid infinte counting in a loop :)
declare -a RPMLIST
for i in $(eval echo "{0..$THAS}"); do
 if [ ${DutyCycles[$i]} -ne $PERIOD ]; then 
	RPMLIST[$i]=$(echo "scale=2;5000-((23.2/2)*60)*((${DutyCycles[$i]}/10000)/0.5568)" | bc | cut -d . -f1)
 else
	RPMLIST[$i]=0
 fi
 echo "RPMLIST[$i]: temp $((${CpuTemps[$i]}/1000)), duty_cycle ${DutyCycles[$i]}, rpm ${RPMLIST[$i]}"
done

declare -i LOOPID=0 #max. N = THAS, LOOPID controls the array updates of temperature Epochs
declare -i PREVDUTY=0 #Previous duty_cycle (for comparsion [show rows 133] - we only write a new value, it speeds up the script)
#And we start walking in infinite circles, this part needs to be as fast in running and well thought out as possible :)
while true
do		#Measure real temperature in the thermal_zone0
        measuretemp=$(/usr/bin/cat $THERMAL_ZONE0)
        if  $THA; then
			temp=$ACTUAL_EPOCH_MEAN_TEMP
		else
			temp=$measuretemp
        fi        
        BRK=false
        for i in {0..6}; do
				if [ $BRK == false ] && [ $temp -gt ${CpuTemps[$i]} ]; then
						DUTY=${DutyCycles[$i]}
						#echo "DUTY_CYCLE=$DUTY, PREVDUTY_CYCLE=$PREVDUTY" #debug info
						if [ $PREVDUTY -ne $DUTY ]; then
							echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle"
							PREVDUTY=$DUTY
							#print info only change fan speed (ideal output for syslog)
							echo "temp $(($measuretemp/1000)), epoch $(($temp/1000)), target $((${CpuTemps[$i]}/1000)), duty $DUTY, rpm ${RPMLIST[$i]}"
						fi						
						#uncomment and comment [rows 137] for print info every interval
						#echo "temp $(($measuretemp/1000)), epoch $(($temp/1000)), target $((${CpuTemps[$i]}/1000)), duty $DUTY, rpm ${RPMLIST[$i]}"
						BRK=true #break
                fi
        done
		if $THA; then
			#echo "LOOPID=$LOOPID" #debug info
			#echo "temphistory_array[$LOOPID] ${temphistory_array[$LOOPID]}" #debug info
			
			#Update "Epoch" array and actual and previous mean
			temphistory_array[$LOOPID]=$measuretemp
			ACTUAL_EPOCH_MEAN_TEMP=$(((${temphistory_array[@]/%/+}0)/($THAS+1)))
			if [ $LOOPID -lt $THAS ]; then
				LOOPID+=1
			else
				LOOPID=0
			fi
		fi
		#loop (measuring) interval: default is 1s [show row 54]
        /usr/bin/sleep $SLEEPTIME
done

 

 

Edited by pepper

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines