Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU usage, and which PWM_FREQ? #3

Open
josejsarmento opened this issue Jul 18, 2022 · 5 comments
Open

High CPU usage, and which PWM_FREQ? #3

josejsarmento opened this issue Jul 18, 2022 · 5 comments

Comments

@josejsarmento
Copy link

josejsarmento commented Jul 18, 2022

Hello! Thank you very much for this, it's been very handy. I just wanted to ask two questions:

  • Typing ´docker stats´ shows me the container is around 60% to 80% CPU, why is this so high? The 'fan.py' process in htop also shows the same CPU usage, but the cores above don't seem to be working that much (around 3%)
  • Should I edit the PWM_FREQ to something appropriate for my own fan? I'm using this fan

This is a Raspberry Pi 4B 8GB with a 64-bit Ubuntu server

@josejsarmento
Copy link
Author

I have set the PWM_FREQ to 25, and CPU usage has lowered to ~2%, and temps and fan noise seem to be ok.

@josejsarmento
Copy link
Author

As pointed to me elsewere, a hardware PWM solution wouldn't use much of the CPU, so this PWM solution is software-based right? Are there any hardware solution alternatives?

@josejsarmento josejsarmento reopened this Jul 18, 2022
@andesse
Copy link

andesse commented Jul 18, 2022

I connected a 5v mini fan to the 3v output.
i need to tip it with my finger that it starts running, but then steady and very slow and silent. It’s fine to cool my Tinkerboard with node red down from 50 to 30 degree. No software needed

@mariusmotea
Copy link

mariusmotea commented Sep 25, 2022

Update: i commit a new version with hardware PWM.

@josejsarmento the changes to enable hardware PWM are minimal. Just use https://github.com/Pioreactor/rpi_hardware_pwm library and follow the steps to enable PWM in config.txt.

Changes to apply:
line 4:

   - import lgpio as sbc
   + from rpi_hardware_pwm import HardwarePWM

line 127-129:

    - fan = sbc.gpiochip_open(0)
    - sbc.gpio_claim_output(fan, PWM_GPIO_NR)
    - setFanSpeed(FAN_LOW,MIN_TEMP)
    + pwm = HardwarePWM(pwm_channel=0, hz= PWM_FREQ)
    + pwm.start(FAN_LOW) # full duty cycle

line 76:

  - sbc.tx_pwm(fan , PWM_GPIO_NR, PWM_FREQ, speed, pulse_offset=0, pulse_cycles=0)
  + pwm.change_frequency(speed)

On my Raspberry PI 4 the cpu load dropped after one minute to 0.1%

@therealthingy
Copy link

Thanks @mariusmotea for the suggestion!
Works perfectly 👍

I only had to change

  + pwm.change_frequency(speed)

to pwm.change_duty_cycle(speed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants