Name:
pulsout
Syntax:

PULSOUT pin,time

Pin - is a variable/constant which specifies the i/o pin to use.

Time - is a variable/constant which specifies the period (0-65535) in 10us units (at 4MHz resonator).

Description:

Output a timed pulse by inverting a pin for some time.

The pulsout command generates a pulse of length time. If the output is initially low, the pulse will be high, and vice versa. This command automatically configures the pin as an output, but for reliable operation you should always ensure this pin is an output before using the command (using high, low or output).

Effect of Increased Clock Speed:

4MHz 10us unit
8MHz 5us unit
16MHz 2.5us unit
32MHz 1.25us unit
64MHz 0.625us unit
Applies To:
All
See Also:
Related Create:
Share:
Print:

Output a pulse

Generate 1.5ms pulses on output B.1 with a 20ms interval between each pulse

Code Example:
main:	pulsout B.1,150	; send a 1.50ms pulse out of pin B.1
	pause 20	; pause 20 ms
	goto main	; loop back to start
Copy Code Submit an Example

Control servos with pulsout commands

This code shows how to control three servos on pins B.1, B.2 and B.3 using 'pulsout' commands. The servo positions are set in the w1, w2 and w3 variables. The w0 variable is used to set the servo frame loop time, how frequently the servo pulses are sent out, which will normally be around 20ms, giving a frame rate of 50 Hz. The w0 variable is then adjusted to take account of how much of the loop time was spent issuing pulses so the 'pauseus' time is reduced accordingly, and the frame time and rate is kept fairly constant. The 'min' operators are used to prevent the 'pauseus' time going below zero.

Code Example:
#picaxe 20M2

; At default operating speed of 4 MHz; pulsout and pauseus act in units of 10 us

Main:
	w1 =  75		; Channel 1 pulse = 0.75 ms =  750 us =  75 x 10 us
	w2 = 150		; Channel 2 pulse = 1.50 ms = 1500 us = 150 x 10 us
	w3 = 225		; Channel 3 pulse = 2.25 ms = 2250 us = 225 x 10 us
	pulsout B.1, w1		; Servo channel 1
	pulsout B.2, w2		; Servo channel 2
	pulsout B.3, w3		; Servo channel 3
	w0 = 2000		; Frame time = 20 ms = 20000 us = 2000 x 10 us
	w0 = w0 min w1 - w1	; Less time for servo channel 1
	w0 = w0 min w2 - w2	; Less time for servo channel 2
	w0 = w0 min w3 - w3	; Less time for servo channel 3
	pauseus w0		; Pad out loop time to achieve desired frame time 
	goto Main		; Repeat loop
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.