Module zio :: Class PWM

Class PWM

object --+    
         |    
    Module --+
             |
object --+   |
         |   |
     LockI --+
             |
            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 and motor speed 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)
Gets the output period of the pins.
tuple of integers
get_freq(self)
Sets the output freq of the pins.
 
set_duty(self, pins, duty)
Sets the output duty cycle for the specified pins.
tuple of integer integer
get_duty(self)
Gets the output duty cycle for the pins.
 
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__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods

Inherited from LockI: synchronized

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
Decorators:
  • @LockI.synchronized
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)

 
Gets the output period of the pins.
Returns: tuple of integers
the output period (in nanoseconds) of the pins
Decorators:
  • @LockI.synchronized

get_freq(self)

 
Sets the output freq of the pins.
Returns: tuple of integers
the output frequency (in kHz) of the pins

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
Decorators:
  • @LockI.synchronized
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

get_duty(self)

 
Gets the output duty cycle for the pins.
Returns: tuple of integer integer
the duty cycle of the pins
Decorators:
  • @LockI.synchronized

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)