Module zio :: Class PWM

Class PWM

object --+    
         |    
    Module --+
             |
            PWM

PWM class is used to rapidly turn on and off an output pin. The period of output and the duty cycle can be controlled. Examples of applications of PWM are LED brightness control, DC motor speed control, and servo motor shaft angle control.
Instance Methods
 
__init__(self, agent)
Contructs a PWM object.
 
set_period(self, pins, period)
Sets the output period for the specified pins.
 
set_freq(self, pins, freq)
Sets the output frequency for the specified pins.
tuple of integers
get_period(self, pin)
Gets the output period of the specified pin.
tuple of integers
get_freq(self, pin)
Gets the output frequency of the specified pin.
 
set_duty(self, pins, duty)
Sets the output duty cycle for the specified pins.
tuple of integer integer
get_duty(self, pin)
Gets the output duty cycle for the pins.
bool
get_state(self, pin)
Returns if the PWM has been started on the pin.
 
start(self, pins)
Enable PWM output for the specified pins.
 
stop(self, pins)
Disable PWM output for the specified pins.

Inherited from Module: do_op

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties
  output_pin_count
The no.

Inherited from object: __class__

Method Details

__init__(self, agent)
(Constructor)

 
Contructs a PWM object.
Parameters:
  • agent (Agent) - the agent interface object
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted
Overrides: object.__init__

set_period(self, pins, period)

 
Sets the output period for the specified pins. The period should be less than 1ms. Note that setting the period always occurs in pairs (0, 1) and (2, 3). For example, setting period of pin 2 will cause the same period to be set on pin 3.
Parameters:
  • pins (list of integers) - the pins whose period is to be set
  • period (integer) - the output period in nano seconds
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

set_freq(self, pins, freq)

 
Sets the output frequency for the specified pins. The frequency should be greater than 1kHz. Note that setting the frequency always occurs in pairs (0, 1) and (2, 3). For example, setting frequency of pin 2 will cause the same frequency to be set on pin 3.
Parameters:
  • pins (list of integers) - the pins whose frequency is to be set
  • freq (integer) - the output frequency in kHz
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

get_period(self, pin)

 
Gets the output period of the specified pin.
Parameters:
  • pin (int) - the pin whose period is required
Returns: tuple of integers
the output period (in nanoseconds) of the pins
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

get_freq(self, pin)

 
Gets the output frequency of the specified pin.
Parameters:
  • pin (int) - the pin whose frequency is required
Returns: tuple of integers
the output frequency (in kHz) of the pins
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

set_duty(self, pins, duty)

 
Sets the output duty cycle for the specified pins.
Parameters:
  • pins (list of integers) - the pins whose duty cycle is to be set
  • duty (integer) - the percentage of ON time
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

get_duty(self, pin)

 
Gets the output duty cycle for the pins.
Parameters:
  • pin (int) - the pin whose duty is required
Returns: tuple of integer integer
the duty cycle of the pins
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

get_state(self, pin)

 
Returns if the PWM has been started on the pin.
Parameters:
  • pin (int) - the pin whose state is required
Returns: bool
returns true of PWM has been started, false otherwise
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

start(self, pins)

 
Enable PWM output for the specified pins.
Parameters:
  • pins (list of integers) - the pins whose PWM output is to be enabled
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

stop(self, pins)

 
Disable PWM output for the specified pins.
Parameters:
  • pins (list of integers) - the pins whose PWM output is to be disabled
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

Property Details

output_pin_count

The no. of output pins supported by the interface kit.
Get Method:
_get_output_pin_count(self)