Avisaro Online Documentation - Wiki
Impressum Kontakt Sitemap

PWM

Description

To output square waves of variable length and pulse widths, one can use the PWM command.

PWM requires three arguments:

  1. The first one is the pin number on the Avisaro Module. For pin number assignments, please see here: click.
  2. The second argument is the length of the pause in 1/2 µs units.
  3. The third argument is the length of the pulse, also in 1/2 µs units. Both together form a square wave which period is determined by the sum of the second and third argument.

To make this clear: If you want to generate square waves with a frequency of 1µs, call PWM with 1 and 1 as second and third argument. Unfortunately, the pulse width for an 1µs wave is not adjustable because this is the highest possible frequency. To generate waves that have a period of exactly 1s, but a very small pulse of 1µs, call PWM with 199998 as second and 2 as third argument, and so on...

Pin 5, 6, 7, 9, 10, 11 can be used as PWM outputs simultaneously. Since all outputs share a common timer, the frequency of each signal must be equal to the the others. To follow this rule, simply make sure that the sum of the last two arguments of the PWM command is the same for all outputs. 

Example

The following example slowly moves a hobbyist RC servo (Compatible to a S03NXF Std. Servo) from one end to the other and vice versa:

outmode -2
lab:
print "+"
for p = 1900 to 4500 step 10
pwm 7, 40000, p
sleep 50
next
print "-"
for p = 4500 to 1900 step -10
pwm 7, 40000, p
sleep 50
next
goto lab

Remarks

Please note: The PWM command immediately changes pin configuration for the selected ports. No explicit initialization is required.