-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Labels
ffmFFM API PluginFFM API Plugin
Description
It's probably me, but I find PWM the hardest IO Type to use... It's unclear how to map GPIO pin numbers to chip/channel parameters for hardware PWM, how to configure on different types of RPi's, etc.
Current documentation: https://www.pi4j.com/documentation/io-types/pwm/
I guess this can be fixed by extending the documentation and parameters in the following way:
Hardware PWM
Only a limited number of hardware-accelerated PWMs are available. These can be checked with:
$ ls -l /sys/class/pwm/
pwmchip0
$ pinctrl | grep PWM
18: a3 pd | lo // GPIO18 = PWM0_CHAN2
19: a3 pd | lo // GPIO19 = PWM0_CHAN3
45: op dh pd | hi // FAN_PWM/GPIO45 = output
Implementation
- Parameters should be
chipandchannel - The plugin PWM provider must throw an error if
chipandchannelare not provided withPwmType.HARDWARE - The plugin PWM provider should log a warning if a
bcmis provided withPwmType.HARDWARE - Implementation changes needed in the plugins to allow this usage
- @DigitalSmile can we add com.pi4j.plugin.ffm.providers.pwm.PwmFFMSoftware ?
# Chip can be retrieved with a helper method
# This returns 0 for non-RP1 (pre-RPi 5) and correct number for RP1 (RPi 5)
var chip = PwmChipUtil.getPWMChip();
# Example based on the output above for `GPIO18 = PWM0_CHAN2`
var pwmConfig = Pwm.newConfigBuilder(pi4j)
.pwmType(PwmType.HARDWARE)
.chip(chip)
.channel(2)
.build();
Documentation
- Describe how to enable, configure, and use HARDWARE PWM with chip and channel on different RPi models
- Create JBang example
- Document what happens if you try to use hardware PWM on a non-hardware PWM pin
- Document frequency/duty cycle usage and limitations
Software PWM
Software PWM is implemented entirely in code, and it can generate PWM signals on any pin that supports general-purpose output. But it has less accurate timing due to CPU load and OS scheduling.
Implementation
- Parameters should be
bcm - The plugin PWM provider throw an error if i
bcmis not provided withPwmType.SOFTWARE - The plugin PWM provider should log a warning if anything else than
bcmis provided withPwmType.SOFTWARE - Implementation changes needed in the plugins to allow this usage
# Example based on the output above for `GPIO18 = PWM0_CHAN2`
var pwmConfig = Pwm.newConfigBuilder(pi4j)
.pwmType(PwmType.SOFTWARE)
.bcm(18)
.build();
Documentation
- Describe how to use SOFTWARE PWM with bcm
- Create JBang example
DigitalSmile
Metadata
Metadata
Assignees
Labels
ffmFFM API PluginFFM API Plugin