stamp.core
Class PWM

java.lang.Object
  |
  +--stamp.core.VirtualPeripheral
        |
        +--stamp.core.PWM
Direct Known Subclasses:
Freqout

public class PWM
extends VirtualPeripheral

Perform Pulse Width Modulation (PWM) on an I/O pin. PWM is a virtual peripheral so it will continue to run in the background.

The timebase for PWM (and all other virtual peripherals) is 8.68 microseconds.


Field Summary
 boolean stoppedState
          The state that the pin should be set to whenever the PWM is stopped.
 
Constructor Summary
PWM(int pin)
          Creates a PWM object, assigns it to a pin but does not start it running.
PWM(int pin, int highTime, int lowTime)
          Creates a PWM object, assigns it to a pin and starts it running.
PWM(int pin, int highTime, int lowTime, boolean stoppedState)
          Creates a PWM object, assigns it to a pin and starts it running.
 
Method Summary
 void start()
          Start the PWM running.
 void stop()
          Stop a running PWM.
 void update(int highTime, int lowTime)
          Update the PWM duty cycle.
 
Methods inherited from class java.lang.Object
equals
 

Field Detail

stoppedState

public boolean stoppedState
The state that the pin should be set to whenever the PWM is stopped. By default the pin will be set low if the PWM is stopped.
Constructor Detail

PWM

public PWM(int pin)
Creates a PWM object, assigns it to a pin but does not start it running. Call update () to set the time. Call start () to start it running.
Parameters:
pin - the pin to generate the PWM signal on.

PWM

public PWM(int pin,
           int highTime,
           int lowTime,
           boolean stoppedState)
Creates a PWM object, assigns it to a pin and starts it running.
Parameters:
pin - the pin to generate the PWM signal on.
highTime - the number of 8.68us the waveform should be high.
lowTime - the number of 8.68us the waveform should be low.
stoppedState - the state that the pin should be set to whenever the PWM is stopped.

PWM

public PWM(int pin,
           int highTime,
           int lowTime)
Creates a PWM object, assigns it to a pin and starts it running.
Parameters:
pin - the pin to generate the PWM signal on.
highTime - the number of 8.68us the waveform should be high.
lowTime - the number of 8.68us the waveform should be low.
Method Detail

update

public void update(int highTime,
                   int lowTime)
Update the PWM duty cycle.
Parameters:
highTime - the number of 8.68us the waveform should be high.
lowTime - the number of 8.68us the waveform should be low.

start

public void start()
Start the PWM running. The constructor will start the PWM when it is first created. If it is later stopped with stop() then start() will start it again with the same set of parameters.

It is an error to call start if the PWM is already running.


stop

public void stop()
Stop a running PWM.

The PWM will stop immediately and may leave the output pin in either a high or low state.