maix.peripheral.pwm

maix.peripheral.pwm module

You can use maix.peripheral.pwm to access this module with MaixPy
This module is generated from MaixPy and MaixCDK

Module

No module

Enum

Variable

Function

Class

PWM

Peripheral pwm class

C++ defination code:

class PWM

__init__

def __init__(self, id: int, freq: int = 1000, duty: float = 0, enable: bool = True, duty_val: int = -1) -> None

PWM constructor

item description
type func
param pin: direction [in], pwm id, int type, like 0, 1, 2 etc.
freq: direction [in], pwm frequency, unit: Hz. int type. default is 1000
duty: direction [in], pwm duty. double type. range is [0, 100], default is 0.
enable: direction [in], enable pwm output right now. bool type. default is true, if false, you need to call enable() to enable pwm output.
duty_val: direction [in], pwm duty value, int type. default -1 means not set and auto calculate by freq and duty.
This arg directly set pwm duty value, if set, will ignore duty arg.
duty_val = duty / 100 * T_ns, T_ns = 1 / freq * 1000000000.
throw If args error or init pwm failed, will throw err::Exception
static False

C++ defination code:

PWM(int id, int freq = 1000, double duty = 0, bool enable = true, int duty_val = -1)

duty

def duty(self, duty: float = -1) -> float

get or set pwm duty

item description
type func
param duty: direction [in], pwm duty, double type, value in [0, 100], default -1 means only read.
return current duty, float type, if set and set failed will return -err::Err
static False

C++ defination code:

double duty(double duty = -1)

duty_val

def duty_val(self, duty_val: int = -1) -> int

set pwm duty value

item description
type func
param duty_val: direction [in], pwm duty value. int type. default is -1
duty_val > 0 means set duty_val
duty_val == -1 or not set, return current duty_val
return int type
when get duty_val, return current duty_val, else return -err::Err code.
static False

C++ defination code:

int duty_val(int duty_val = -1)

freq

def freq(self, freq: int = -1) -> int

get or set pwm frequency

item description
type func
param freq: direction [in], pwm frequency. int type. default is -1
freq >= 0, set freq
freq == -1 or not set, return current freq
return int type, current freq, if set and set failed will return -err::Err
static False

C++ defination code:

int freq(int freq = -1)

enable

def enable(self) -> maix.err.Err

set pwm enable

item description
type func
return err::Err type, err.Err.ERR_NONE means success
static False

C++ defination code:

err::Err enable()

disable

def disable(self) -> maix.err.Err

set pwm disable

item description
type func
return err::Err type, err.Err.ERR_NONE means success
static False

C++ defination code:

err::Err disable()

is_enabled

def is_enabled(self) -> bool

get pwm enable status

item description
type func
return bool type, true means enable, false means disable
static False

C++ defination code:

bool is_enabled()