November 17, 2024, 01:29:03 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


PWM - quick question

Started by steveo, August 09, 2007, 06:46:52 AM

Previous topic - Next topic

steveo

John,
I'm making great headway learning the Prop-1, thanks for the help thus far.

With the PWM function, I don't quite yet understand what the last parameter is for.

When I use it to ramp up LED's like so:

SYMBOL  bug     = B2
SYMBOL  level    = B3

FOR level = 0 TO 255 STEP 2
  PWM bug, level, 1
NEXT

I use the random function with // 6 to create the bug value

I understand:
PWM (pin#), (value for LED brightness), ??

So what does that last parameter do? I went through the help files (they're awesome) but still can't seem to wrap my brain around it.


JonnyMac

Stehveo,

The last parameter -- called Duration in the documentation -- specifies how long PWM will stay at the level specified.  For the Prop-1, each unit in duration is equal to 5 milliseconds.  So this loop:

  FOR level = 0 TO 255 STEP 2
    PWM bug, level, 1
  NEXT


Should take about 0.64 seconds.  You have 128 steps times 0.005 (that's not counting instruction overhead).


Jon McPhalen
EFX-TEK Hollywood Office

jssherrard

June 02, 2008, 02:24:07 PM #2 Last Edit: June 02, 2008, 02:37:42 PM by jssherrard
Quote from: JonnyMac on August 09, 2007, 07:26:05 AM...The last parameter -- called Duration in the documentation -- specifies how long PWM will stay at the level specified.  For the Prop-1, each unit in duration is equal to 5 milliseconds.  So this loop:

  FOR level = 0 TO 255 STEP 2
    PWM bug, level, 1
  NEXT


Should take about 0.64 seconds.  You have 128 steps times 0.005 (that's not counting instruction overhead).

I am new to Prop-1 programming so please excuse my newby questions...

;)

1. Is there a maximum value for Duration?

2. Lets say I illuminate an LED using:

PWM led, level, 5000

Does that mean the LED will turn off after 5 seconds without requiring an additional command?

JonnyMac

When in doubt or question, double-click on a PBASIC keyword (you can tell it's a keyword because the editor highlights it blue) and press the F1 key; this will take you to the correct page in the help file.

The cycles parameter for PWM is limited to a byte (255 max), so command above would actually get truncated to 136.  Also note, though, that the cycles parameter for the BS1 (Prop-1) is 5 milliseconds, so the maximum PWM output duration on the Prop-1 is going to be 1.275 seconds (5ms x 255).  At the end of the command the output will be low, so an active-high LED will be off.
Jon McPhalen
EFX-TEK Hollywood Office