PWM pin,duty,cycles

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

Duty - is a variable/constant (0-255) which specifies analog level.

Cycles - is a variable/constant (0-255) which specifies number of cycles. Each cycle takes about 5ms at 4MHz clock frequency.


Output pwm then return pin to input. This command is historical and hence rarely used.

For pwm control of motors etc. the pwmout command is recommended instead. This pwm command is used to provide 'bursts' of PWM output to generate a pseudo analogue output on the PICAXE pins.

This is achieved with a resistor connected to a capacitor connected to ground; the resistor-capacitor junction being the analog output. As the pin returns to an input after execution, the capacitor's rate of discharge is limited - however PWM should be executed periodically to update/refresh the analog voltage.

Applies To:
08, 08M, 08M2, 14M2, 20M2, 20X2, 28X2, 40X2
See Also:
Related Create:

    Generate bursts of PWM

    Generate a burst of PWM on output pin 4 every 20ms

    Code Example:
    main:	pwm C.4,150,20	; send 20 pwm bursts out of pin 4
    	pause 20	; pause 20 ms
    	goto main	; loop back to star
    Copy Code Submit an Example

    Submit Your Own Code!

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