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
The `PWMConfig` struct contains configuration for the PWM peripheral.
332
+
333
+
*`Period` is the period of the PWM signal, in nanoseconds.
334
+
335
+
```go
336
+
typePWMstruct {
337
+
// values are unexported or vary by chip
338
+
}
339
+
340
+
var (
341
+
PWM0 = PWM{...}
342
+
PWM1 = PWM{...}
343
+
PWM2 = PWM{...}
344
+
)
345
+
```
346
+
347
+
The PWM struct corresponds to a single PWM/timer hardware peripheral, which controls 1 or more output channels. This interface exposes a simple PWM model, that can generate outputs with a variable period and duty cycle.
348
+
349
+
Note: As of TinyGo 0.41, the name of the PWM peripheral type is not consistent across supported platforms. This could be: PWM, TCC, LEDCPWM, timerType, and pwmGroup. The name of the exported structs could be: Timerx, TCCx, PWMx, TIMx.
350
+
351
+
For more information, see the [PWM tutorial](../tutorials/pwm)
352
+
353
+
```go
354
+
func(pwmPWM) Configure(configPWMConfig) error
355
+
```
356
+
357
+
Enables and configures the PWM peripheral for use. Does not enable any output channels.
358
+
359
+
```go
360
+
func (pwm PWM) SetPeriod(period uint64) error
361
+
```
362
+
363
+
Update the period of the PWM timer, in nanoseconds.
364
+
365
+
```go
366
+
func (pwm PWM) Period() uint64
367
+
```
368
+
369
+
Get the period of the PWM timer, in nanoseconds.
370
+
371
+
```go
372
+
func (pwm PWM) Top() uint32
373
+
```
374
+
375
+
Get the top (highest value before rollover) of the PWM.
376
+
377
+
```go
378
+
func (pwm PWM) Counter() uint32
379
+
```
380
+
381
+
Get the current value of the PWM counter.
382
+
383
+
```go
384
+
func (pwm PWM) Channel(pin Pin) (uint8, error)
385
+
```
386
+
387
+
Configures the specified pin for PWM mode, and assigns a PWM channel to it.
Configure whether the ouput should be inverted. Normally, the PWM output will go high at the beginning of a cycle, then low when the counter is equal to the channel compare value. If inverted, the channel will start low, then turn high at the compare value.
394
+
395
+
```go
396
+
func (pwm PWM) Set(channel uint8, value uint32)
397
+
```
398
+
399
+
Update the compare value for the specified channel. To calculate the comparison value from a desired duty cycle, multiply the duty cycle by the value of Top().
0 commit comments