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
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.
19
+
20
+
```csharp
21
+
// Case of ESP32, you need to set the pin function, in this example PWM3 for pin 18:
// You can check then if it has created a valid one:
25
+
if (pwmPin!=null)
26
+
{
27
+
// You do have a valid one
28
+
}
29
+
```
30
+
### Duty cycle
31
+
32
+
You can adjust the duty cycle by using the property:
33
+
34
+
```csharp
35
+
pwmPin.DutyCycle=0.42;
36
+
```
37
+
38
+
The duty cycle goes from 0.0 to 1.0.
39
+
40
+
### Frequency
41
+
42
+
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.
43
+
44
+
### Advance PwmChannel creation
45
+
46
+
You can as well, if you know the chip/timer Id and the channel use the create function:
47
+
48
+
```csharp
49
+
PwmChannelpwmPin=new(1, 2, 40000, 0.5);
50
+
```
51
+
52
+
This is only recommended for advance users.
53
+
54
+
### Other considerations
55
+
56
+
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.
57
+
16
58
## Feedback and documentation
17
59
18
60
For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).
0 commit comments