Skip to content

Commit 1c3e298

Browse files
authored
Merge pull request #11 from cgomesu/doc
Improve organization and add controllers info
2 parents 0fc580d + 0976212 commit 1c3e298

File tree

4 files changed

+101
-43
lines changed

4 files changed

+101
-43
lines changed

README.md

Lines changed: 101 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ A fan control script written in bash for the [**2-pin PH2.0 12v fan connector of
33

44
Many of the variables used in this fan controller can be modified directly from the CLI, such as setting custom temperature thresholds (`-t`, `-T`) or disabling temperature monitoring altogether (`-f`). For a more detailed description, see [**Usage**](#usage).
55

6-
There's arguably more code here than necessary to run a fan controller. This was a hobby of mine (I wanted to revisit the first version which used a fixed table to set the speed) and an opportunity to learn more about bash and the sysfs interface.
6+
There's arguably more code here than necessary to run a fan controller. This was a hobby of mine (I wanted to revisit the first version which used a fixed table to set the speed) and an opportunity to learn more about bash and the sysfs interface. There are multiple comments in the script as well, which makes it easy to edit for other similar cases.
77

88
This is free. There is NO WARRANTY. Use at your own risk.
99

1010
If you have any issues or suggestions, open an issue or [send me an e-mail](mailto:me@cgomesu.com).
1111

1212

13+
# Table of Contents
14+
1. [Requisites](#requisites)
15+
2. [Installation](#installation)
16+
3. [Usage](#demos)
17+
4. [Controllers](#controllers)
18+
- [Logistic](#logistic)
19+
5. [Implementation](#Implementation)
20+
- [Systemd](#systemd)
21+
22+
[:arrow_up: top](#)
23+
24+
1325
# Requisites
1426
- Linux distro;
1527
- Access to the [pwm sysfs interface](https://www.kernel.org/doc/Documentation/pwm.txt) (run with `sudo` permission or as `root`);
@@ -31,27 +43,39 @@ And software:
3143
- bc v1.07.1
3244

3345
<p align="center">
34-
<img width="350" height="350" src="img/fan-pins-500-500.jpg"><br>
46+
<img width="350" height="350" src="img/fan-pins-500-500.jpg"><br><br>
3547
<img width="350" height="350" src="img/fan-soc-500-500.jpg">
3648
</p>
3749

50+
[:arrow_up: top](#)
51+
3852

3953
# Installation
40-
```
41-
apt update
42-
apt install git
43-
cd /opt
54+
To install the fan controller script, run the following commands either as `root` or append `sudo` to each command with a user that has sudo permission:
4455

45-
# From now on, if you're not running as root, append 'sudo' if you run into permission issues
46-
git clone https://github.com/cgomesu/nanopim4-satahat-fan.git
47-
cd nanopim4-satahat-fan
56+
1. Install `git` and `bc` (GNU Basic Calculator).
57+
```
58+
apt update && apt install git bc
59+
```
60+
2. Create a new directory in `/opt` for the default branch (`master`) of the `nanopim4-satahat-fan` repository.
61+
```
62+
cd /opt
63+
git clone https://github.com/cgomesu/nanopim4-satahat-fan.git
64+
cd nanopim4-satahat-fan/
65+
```
66+
3. Test the script.
67+
```
68+
./pwm-fan.sh -F 10
69+
```
70+
And if you run into any error messages, fix the issue and try again. Otherwise, press `Ctrl`+`c` to send an interrupt signal and stop the script.
4871

49-
# Test the script
50-
./pwm-fan.sh -F 10
72+
4. *Optional.* Check [Usage](#usage) for non-default options that you might want to test before running the script in the background.
5173

52-
# Check for any error messages
53-
# When done, press Ctrl+C after to send a SIGINT and stop the script
54-
```
74+
5. *Optional.* If using thermal controllers, take a look at [Controllers](#controllers) to learn how to tune a few parameters to best fit your environment.
75+
76+
6. Lastly, see the [Implementation](#implementation) section for information on how to run the script in the background.
77+
78+
[:arrow_up: top](#)
5579

5680

5781
# Usage
@@ -98,42 +122,76 @@ This is free. There is NO WARRANTY. Use at your own risk.
98122
99123
```
100124

125+
[:arrow_up: top](#)
126+
101127

102128
# Examples
103-
- Run with a custom period and min/max temperature thresholds
104-
```
105-
./pwm-fan.sh -p 25000000 -t 30 -T 60
106-
```
129+
- Run with a custom period and min/max temperature thresholds.
130+
```
131+
./pwm-fan.sh -p 25000000 -t 30 -T 60
132+
```
133+
134+
- Run with defaults, except that the minimum duty cycle threshold is 40%.
135+
```
136+
./pwm-fan.sh -d 40
137+
```
138+
139+
- Run in full speed mode all the time.
140+
```
141+
./pwm-fan.sh -f
142+
```
143+
144+
- Set fan startup to 15 sec.
145+
```
146+
./pwm-fan.sh -F 15
147+
```
107148

108-
- Run with defaults, except that the minimum duty cycle threshold is 40%
109-
```
110-
./pwm-fan.sh -d 40
111-
```
149+
- When using args `-u` and `-U` (introduced by [@araynard](https://github.com/araynard) via [#7](https://github.com/cgomesu/nanopim4-satahat-fan/pull/7)), it is recommended to leave a difference of at least 5°C between them. In most cases, `-u` can be set to a value slightly higher than the idle temperature *with* the fan, whereas `-U` can be set to a value slightly higher than the idle temperature *without* the fan.
150+
```
151+
./pwm-fan.sh -u 45 -U 55
152+
```
112153

113-
- Run in full speed mode all the time
114-
```
115-
./pwm-fan.sh -f
116-
```
154+
[:arrow_up: top](#)
117155

118-
- Set fan startup to 10 sec
119-
```
120-
./pwm-fan.sh -F 10
121-
```
122156

123-
- When using args `-u` and `-U` (introduced by [@araynard](https://github.com/araynard) via [#7](https://github.com/cgomesu/nanopim4-satahat-fan/pull/7)), it is recommended to leave a difference of at least 5°C between them. In most cases, `-u` can be set to a value slightly higher than the idle temperature *with* the fan, whereas `-U` can be set to a value slightly higher than the idle temperature *without* the fan.
124-
```
125-
./pwm-fan.sh -u 45 -U 55
126-
```
157+
# Controllers
158+
## Logistic
159+
The default thermal controller is based on a [logistic model](https://en.wikipedia.org/wiki/Logistic_function) that outputs the duty cycle in nanoseconds, owing to the constraint that *L* = upper duty cycle threshold, which can be specified via the argument `-D` in percentage of the period.
127160

161+
The following plot illustrates how the logistic controller changes the duty cycle as a function of the current temperature using default parameter values and three different mean temperatures:
128162

129-
# Run in the background
130-
If you're running options different than the default values, first edit the `pwm-fan.service` file to include those options into the `ExecStart=` command execution.
163+
<p align="center">
164+
<img width="70%" src="img/controller-logistic-change-mean.jpg">
165+
</p>
131166

132-
```
133-
# Enable the service and start it
134-
systemctl enable /opt/nanopim4-satahat-fan/systemd/pwm-fan.service
135-
systemctl start pwm-fan.service
167+
The parameters *k* (*k* = *a*/*b*), as well as the critical temperature (75°C) used as reference for the moving mid-point, can both be modified by editing the script. The following plot illustrates the effects of changing *k* while holding the mean temperature constant (everything else follows default):
136168

137-
# Check the service status to make sure it's running without issues
138-
systemctl status pwm-fan.service
139-
```
169+
<p align="center">
170+
<img width="70%" src="img/controller-logistic-change-k.jpg">
171+
</p>
172+
173+
Similarly, the following plot illustrates the effects of changing the critical temperature while holding the mean temperature constant (everything else follows default):
174+
175+
<p align="center">
176+
<img width="70%" src="img/controller-logistic-change-critical.jpg">
177+
</p>
178+
179+
[:arrow_up: top](#)
180+
181+
182+
# Implementation
183+
## Systemd
184+
If you're running options different than the default ones, first edit the `systemd/pwm-fan.service` file to include those options into the `ExecStart=` command execution. Then, run the following commands to enable and start the `pwm-fan.service`:
185+
186+
1. Enable the service and start it.
187+
```
188+
systemctl enable /opt/nanopim4-satahat-fan/systemd/pwm-fan.service
189+
# alternatively, copy the service file to '/lib/systemd/system/' and enable it via 'systemctl enable pwm-fan.service'.
190+
systemctl start pwm-fan.service
191+
```
192+
2. Then, check the service status to make sure it's running without issues.
193+
```
194+
systemctl status pwm-fan.service
195+
```
196+
197+
[:arrow_up: top](#)
32.3 KB
Loading
31.5 KB
Loading
31.1 KB
Loading

0 commit comments

Comments
 (0)