Shop OBEX P1 Docs P2 Docs Learn Events
PWM -- SX/B Question — Parallax Forums

PWM -- SX/B Question

MacgruberMacgruber Posts: 20
edited 2008-11-08 02:24 in General Discussion
So I've been trying to use some switching between an LED being full on and PWM and I'm running into some problems... The below code demonstrates what I'm seeing...

' BUG.SXB

DEVICE    SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ    4_000_000


Led        PIN RC.7    OUTPUT

increaseVal    VAR        BYTE


PROGRAM Start
Start:
  increaseVal = 0

  DO
    IF increaseVal > 10 THEN
      Led = 1
    ELSE
      PWM Led, 50, 2
    ENDIF

  PAUSE 100
  INC increaseVal

  LOOP




The behaviour I expected was that for the first second the LED is PWM and then after that it is full on... What I am seeing is that the LED goes off after the first second of PWM???

Why is this happening!?!

Comments

  • BeanBean Posts: 8,129
    edited 2008-11-08 01:58
    PWM is only generated during the PWM command.
    During the PAUSE 100 there is no PWM to the LED.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • MacgruberMacgruber Posts: 20
    edited 2008-11-08 02:01
    The problem isn't the lack of PWM during the PAUSE but that once the counter (increaseVal) becomes greater than 10 it should switch the LED on permanently... This doesn't happen! It turns the LED off???
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-11-08 02:20
    The problem is that the PWM command leaves the LED pin in an input state -- change Led = 1 to HIGH Led.

    From the help file PWM page:
    After outputting the PWM pulses, the SX leaves the pin in input mode...
  • MacgruberMacgruber Posts: 20
    edited 2008-11-08 02:24
    JonnyMac said...
    The problem is that the PWM command leaves the LED pin in an input state -- change Led = 1 to HIGH Led.

    From the help file PWM page:
    After outputting the PWM pulses, the SX leaves the pin in input mode...

    Sweet! Thanks! I was pulling my hair for a little bit there! Thanks for the help!
Sign In or Register to comment.