pulse_width( pulse, clocks )

Set Pulse Width

Syntax: pulse_width( pulse, clocks )
Description: Sets the width of the pulse circuit.
Parameters: pulse The number of the pulse circuit. This is a number 0, 1, or 2. Upto to 3 different pulse circuits are available. The number of pulse circuits available depends on the microcontroller chip. Note pulse 1 and 2 have the same period.
clocks Sets the number of clocks for the pulse width . This is a 16bit integer number.
Returns: Nothing
Related: pulse_enable()pulse_width(), pindir()

This command sets the width of a pulse.

To use a pulse output on the microcontroller,  first enable the pulse circuit using  the pulse_enable() command, then enable the output pin using the pindir() command. Then set the period using the pulse_period() command and then set the pulse width using the pulse_width() command.  See here for more details on the use of the pulse functions.

Most of the microcontroller chips have only one pulse circuit, so only timer 0 output is available for use.  But the largest MSP430G2553 has three pulse timers 0, 1, and 2.

The pulse output pin are enabled using the pindir(pin,PULSEOUT) command. However the pulse outputs can only be used on certain output pins. The hardware pins that can be used for pulse outputs are limited as follows.

The timer 0 output can only be used on two pins P1_2, and P1_6.
The timer 1 output can only be used on two pins P2_1, and P2_2.
The timer 2 output can only be used on two pins P2_4, and P2_5.

For the largest MSP430G2553 chip the pulse_period() of timer 1 and timer 2 are the same.  Changing the period of timer 1 using the command  pulse_period(1, 1000) will also change the period of timer 2 output to 1000,  and changing the period of timer 2 using the command pulse_period(2,3000)  will also set timer 1 period to 3000.


pulse_enable(0)                # Enables the Pulse 0 circuit
pindir(P1_2,PULSEOUT)          # Enables the Pulse 0 output onto pin P1_2
pulse_period(0, 20000)         # Output a pulse that repeats every 20,000 clocks
pulse_width(0, 5000)           # Output a pulse that has a width of 5000 clocks

In this example the timer 0 circuit is enabled with the pulse_enable(0) command and pindir(P1_2,PULSEOUT)  command enables the timer 0 output onto to pin P1_2. The pulse_period(20000) command produces a pulse output  that repeats every 20000 clocks, and the pulse_width(5000) sets the width of the pulse to 5000 clocks.