📦 System.Device.Pwm library for .NET nanoFramework.
Перейти к файлу
nfbot bb2c7f1b10
Update 1 NuGet dependencies
***NO_CI***
2024-06-06 01:02:55 +01:00
.github/workflows
.sonarlint
System.Device.Pwm
assets
config
.github_changelog_generator
.gitignore
CHANGELOG.md
LICENSE.md
NuGet.Config
README.md
azure-pipelines.yml
nanoFramework.System.Device.Pwm.nuspec
nanoFramework.System.Device.Pwm.sln
template.vssettings
version.json

README.md

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework System.Device.Pwm Library repository

Build status

Component Build Status NuGet Package
System.Device.Pwm Build Status NuGet

Usage

You can create a PWM channel from a pin number, this is the recommended way. Keep in mind, you will have to allocate the pin in the case of ESP32 and make sure your pin is PWM enabled for STM32 devices.

// Case of ESP32, you need to set the pin function, in this example PWM3 for pin 18:
Configuration.SetPinFunction(18, DeviceFunction.PWM3);
PwmChannel pwmPin = PwmChannel.CreateFromPin(18, 40000);
// You can check then if it has created a valid one:
if (pwmPin != null)
{
    // You do have a valid one
}

Duty cycle

You can adjust the duty cycle by using the property:

pwmPin.DutyCycle = 0.42;

The duty cycle goes from 0.0 to 1.0.

Frequency

It is recommended to setup the frequency when creating the PWM Channel. You can technically change it at any time but keep in mind some platform may not behave properly when adjusting this element.

Advance PwmChannel creation

You can as well, if you know the chip/timer Id and the channel use the create function:

PwmChannel pwmPin = new(1, 2, 40000, 0.5);

This is only recommended for advance users.

Other considerations

PWM precision may vary from platform to platform. It is highly recommended to check what precision can be achieved, either with the frequency, either with the duty cycle.

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.