ppipwm

package
v0.0.0-...-168ccc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package ppipwm allows to produce PWM signal using PPI, TIMER and GPIOTE peripherals.

Index

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

func MakeToggle(t *timer.Periph) Toggle

MakeToggle returns configured Toggle implementation of PPI based PWM using timer t.

func NewToggle

func NewToggle(t *timer.Periph) *Toggle

NewToggle provides convenient way to create heap allocated Toggle struct. See MakeToggle for more information.

func (*Toggle) DutyCycle

func (pwm *Toggle) DutyCycle(n int) int

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

func (pwm *Toggle) Max() int

Max returns a value that corresponds to 100% PWM duty cycle. See SetFreq for more information.

func (*Toggle) Set

func (pwm *Toggle) Set(n, dc int)

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

func (pwm *Toggle) SetFreq(log2pre, periodus int) int

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) SetInv

func (pwm *Toggle) SetInv(n, dc int)

SetInv works like Set but produces inverted waveform.

func (*Toggle) SetMany

func (pwm *Toggle) SetMany(mask uint, dc0, dc1, dc2 int)

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

func (pwm *Toggle) SetManyInv(mask uint, dc0, dc1, dc2 int)

SetManyInv works like SetMany but produces inverted waveform.

func (*Toggle) Setup

func (pwm *Toggle) Setup(n int, pin gpio.Pin, gc gpiote.Chan, pc0, pc1 ppi.Chan)

Setup setups n-th of three PWM channels. Each PWM channel uses one GPIOTE channel and two PPI channels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL