You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe your hardware setup (e.g. board connected to i2c sensor) and describe briefly the issue, specifying the steps needed to reproduce it, if necessary.
Gpio18 → LED → 220 Ohm → GND
I was trying out the PWM example in the readme with its default 500 ns period argument by making an LED pulse softly. What I experienced was that instead of my expected 20 updates per second of the duty cycle, that I got a "5 FPS animation" so to speak — it didn't pulse softly but instead jumped about 5 times/second to distinct brightnesses.
I simply used the example value of 500 and scratched my head for a while before trying changing it to 1000, after which everything worked smoothly and the LED pulsed beautifully.
I'm wondering if anyone can explain why this happens? Is 500 not a reasonable value when updating duty this often?
import Foundation
import SwiftyGPIO
let pwms = SwiftyGPIO.hardwarePWMs(for:.RaspberryPi3)!
let pwm = (pwms[0]?[.P18])!
pwm.initPWM()
let breathingPeriod = 2
let stepsPerSecond = 20
let stepsPerPeriod = breathingPeriod * stepsPerSecond
let pwmPeriodNs = 500 // changing this to 1000 solves the problem
while true {
for i in 0...stepsPerPeriod {
let duty = Float(Double(30) * abs(cos(Double(i) / Double(stepsPerPeriod) * Double.pi)))
pwm.startPWM(period: pwmPeriodNs, duty: duty)
usleep(UInt32(breathingPeriod * 1_000_000/stepsPerPeriod))
}
}
Also, I read in the readme:
This feature uses the M/S algorithm and has been tested with signals with a period in a range from 300ns to 200ms
I'm not sure exactly what this means. I didn't find this algorithm in a search — what is it referring to? Since this is hardware PWM, is it a hardware implemented algorithm?
The text was updated successfully, but these errors were encountered:
Board Type
RaspberryPi3
Operating System
Raspberry Pi OS bookworm arm64 lite
Swift Version
6.0.1 release build
Description
Describe your hardware setup (e.g. board connected to i2c sensor) and describe briefly the issue, specifying the steps needed to reproduce it, if necessary.
Gpio18 → LED → 220 Ohm → GND
I was trying out the PWM example in the readme with its default 500 ns period argument by making an LED pulse softly. What I experienced was that instead of my expected 20 updates per second of the duty cycle, that I got a "5 FPS animation" so to speak — it didn't pulse softly but instead jumped about 5 times/second to distinct brightnesses.
I simply used the example value of
500
and scratched my head for a while before trying changing it to1000
, after which everything worked smoothly and the LED pulsed beautifully.I'm wondering if anyone can explain why this happens? Is
500
not a reasonable value when updatingduty
this often?Also, I read in the readme:
I'm not sure exactly what this means. I didn't find this algorithm in a search — what is it referring to? Since this is hardware PWM, is it a hardware implemented algorithm?
The text was updated successfully, but these errors were encountered: