cm4iofan

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2021 License: MIT Imports: 3 Imported by: 2

README

cm4iofan

Simple utility to get/set the PWM duty cycle and to measure the RPM for a fan connected to the 4-pin header on the CM4IO.

Requirements

  • Enabled i2c_vc overlay (dtparam=i2c_vc=on in /boot/config.txt)
  • Loaded i2c-dev module (e.g. modprobe i2c-dev or using /etc/modules)
  • A user in the i2c group (or root)

Using the Go Module

package main

import "github.com/tmsmr/cm4iofan"

ctrl, err := cm4iofan.New()
if err != nil {
	panic(err)
}
err = ctrl.SetDutyCycle(50)
if err != nil {
	panic(err)
}

Using fanctl

  • Build with cd fanctl && go build.
  • For every tagged version of the Go Module, the fanctl utility is built (Available on the Releases page).
$ fanctl set 50
$ fanctl get
50
$ fanctl rpm
2623

Comments

Direct Setting mode vs. Fan Speed Control mode

The EMC2301 has a built-in closed loop Fan Speed Control algorithm (Besides many awesome features), that allows the user to select a target RPM which is controlled by a PID. I opted for the Direct Setting mode, because it feels more natural to me (Yes, i know that duty cycle/RPM is far from linear...).

Should i use this for my 24/7-running project?

If you want a reliable/automatic cooling solution, you should probably go with something like https://github.com/neg2led/cm4io-fan.

There are scenarios where this Module might be handy (Well, that's why i built it...). But keep in mind, all you do with it, is setting the fan's PWM signal:

  • Some fans won't stop with 0% duty cycle.
  • Most fans will stall with a low duty cycle.
  • ...
TACH to RPM conversion

Unfortunately it is not possible to detect RPM's lower than 500 using the EMC2301. That's why the RPM measurement returns a RPMResult:

type RPMResult struct {
    Rpm int
    Stopped bool
    Undef bool
}
  • When the PWM duty cycle is set to 0%, Stopped is true. This is only true for fans that are able to stop completely!
  • When the calculated RPM is below 500 (smallest value could be 480), it is not possible to determine the real RPM. In this case Undef is true.
On poles, edges and ranges...

The EMC2301 may be used to control a wide variety of PWM fans. TACH measurement works different based on the fan's design type (emc2301.pdf: 4.4 Tachometer Measurement).

Noctua's PWM specification states that (regardless of the actual motor design) the tachometer always pulses two times per revolution (Emulating a fan with 2 poles). I think this is true for other regular, modern PWM fans. That's why i settled with the following values for the RPM calculation:

  • poles = 2
  • n = 5

Since i wanted to measure RPM's as low as possible, RANGE[1:0] is set to 500 RPM. This means the TACH multiplier is m = 1.

Using these values, a simplified formula for TACH conversion can be used (emc2301.pdf: EQUATION 4-3).

Documentation

Index

Constants

View Source
const (
	// Emc2301Bus The i2c bus, the EMC2301 is connected to (cm4io.pdf: 2.9 Fan connector)
	Emc2301Bus = 10
	// Emc2301Addr The address of the EMC2301 (cm4io.pdf: 2.9 Fan connector)
	Emc2301Addr = 0x2F

	// Emc2301ProductIdReg Register containing the EMC2301's product id (emc2301.pdf: TABLE 6-1)
	Emc2301ProductIdReg = 0xFD
	// Emc2301ProductIdVal The EMC2301's product id (emc2301.pdf: TABLE 6-1)
	Emc2301ProductIdVal = 0x37

	// Emc2301ConfigReg The EMC2301's fan configuration register (emc2301.pdf: 4.1 Fan Control Modes of Operation, 6.14 Fan Configuration Registers)
	Emc2301ConfigReg = 0x32

	// Emc2301DutyCycleReg The EMC2301's fan drive setting register (emc2301.pdf: 6.12 Fan Drive Setting Register)
	Emc2301DutyCycleReg = 0x30

	// Emc2301TachHighReg Register containing the TACH measurement's HIGH byte (emc2301.pdf: 6.23 TACH Reading Registers)
	Emc2301TachHighReg = 0x3E
	// Emc2301TachLowReg Register containing the TACH measurement's LOW byte (emc2301.pdf: 6.23 TACH Reading Registers)
	Emc2301TachLowReg = 0x3F

	// Emc2301Tach2RPM RPM conversion constant (emc2301.pdf: EQUATION 4-3: SIMPLIFIED TACH CONVERSION)
	Emc2301Tach2RPM = 3932160
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EMC2301

type EMC2301 struct {
	// contains filtered or unexported fields
}

func New

func New() (*EMC2301, error)

New opens the connection to the EMC2301, verifies the product id, performs the initial configuration and returns the handle

func (*EMC2301) GetDutyCycle

func (ctrl *EMC2301) GetDutyCycle() (int, error)

GetDutyCycle reads and returns the current PWM duty cycle in %

func (*EMC2301) GetRPM

func (ctrl *EMC2301) GetRPM() (*RPMResult, error)

GetRPM measures/calculates the current RPM (if possible)

func (*EMC2301) SetDutyCycle

func (ctrl *EMC2301) SetDutyCycle(pct int) error

SetDutyCycle sets the PWM duty cycle in %

type RPMResult

type RPMResult struct {
	// Rpm The measured/calculated RPM (valid if !Stopped && !Undef)
	Rpm int
	// Stopped is true, when the PWM duty cycle is set to 0
	Stopped bool
	// Undef is true, when the TACH value is too low to calculate the RPM (emc2301.pdf: EQUATION 4-3: SIMPLIFIED TACH CONVERSION)
	Undef bool
}

RPMResult contains the result of a RPM measurement

Directories

Path Synopsis
fanctl module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL