Documentation ¶
Overview ¶
Package ppipwm allows to produce PWM signal using PPI, TIMER and GPIOTE peripherals.
Index ¶
- type Toggle
- func (pwm *Toggle) DutyCycle(n int) int
- func (pwm *Toggle) Max() int
- func (pwm *Toggle) Set(n, dc int)
- func (pwm *Toggle) SetFreq(log2pre, periodus int) int
- func (pwm *Toggle) SetInv(n, dc int)
- func (pwm *Toggle) SetMany(mask uint, dc0, dc1, dc2 int)
- func (pwm *Toggle) SetManyInv(mask uint, dc0, dc1, dc2 int)
- func (pwm *Toggle) Setup(n int, pin gpio.Pin, gc gpiote.Chan, pc0, pc1 ppi.Chan)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Toggle ¶
type Toggle struct {
// contains filtered or unexported fields
}
Toggle implementats three channel PWM usind GPIOTE OUT task configured in toggle mode. It is designed specifically for nRF51 chips because of limitations of their GPIOTE peripheral. Better solutions exists for nRF52.
To produce desired PWM waveform Toggle configures a timer compare register, using simple algorithm, that usually generates glitches when used on working PWM channel. After that, PWM works without any CPU intervention and produces proper waveform until next duty cycle change. This is fine to drive LEDs but can cause trubles in case of receivers that rely on stable PWM frequency or phase (eg. some servos). Correct implementation is difficult and quite expensive in case of nRF51.
Toggle cannot be used concurently by multiple gorutines without proper synchronisation.
func MakeToggle ¶
MakeToggle returns configured Toggle implementation of PPI based PWM using timer t.
func NewToggle ¶
NewToggle provides convenient way to create heap allocated Toggle struct. See MakeToggle for more information.
func (*Toggle) DutyCycle ¶
DutyCycle returns the current duty cycle on channel n. There is no way to check does it corresponds straight or inverted waveform.
func (*Toggle) Max ¶
Max returns a value that corresponds to 100% PWM duty cycle. See SetFreq for more information.
func (*Toggle) Set ¶
Set sets a duty cycle for n-th PWM channel. If dc > 0 or dc < pwm.Max() it stops the PWM timer and starts it just before return (this can produce glitches and affects all PWM channels).
func (*Toggle) SetFreq ¶
SetFreq sets timer prescaler to 2^log2pre and period to periodus microseconds (log2pre must be in range [0..9]). It allows to configure a duty cycle with a resolution = 16 * periodus / 2^log2pre. Toggle uses timer in 16-bit mode so the resolution must be <= 65536. SetFreq returns (resolution-1), which is a value that should be passed to SetDuty/SetInvDuty to produce PWM with 100% duty cycle.
func (*Toggle) SetMany ¶
SetMany sets a duty cycles for PWM channels specifid by mask. Use it for more than one channel to minimizes the number of times the PWM timer is stopped and started (should produce less glitches than call SetDuty multiple times).
func (*Toggle) SetManyInv ¶
SetManyInv works like SetMany but produces inverted waveform.