Shop OBEX P1 Docs P2 Docs Learn Events
Propeller proto board — Parallax Forums

Propeller proto board

clcorbinclcorbin Posts: 14
edited 2008-05-21 21:45 in Propeller 1
I'm "playing" with my Propeller proto board. Currently, I'm writing spin + asm code that takes input from three buttons (pins 0-2), turns three LEDS on/off to indicate status and sends a PWM output to a fourth LED to control it's brightness.

After reading the counter appnote, getting the PWM to work was pretty straight forward. But I am getting my but kicked on something that SEEMS pretty simple!

The function below simply toggles output to the PWM LED on or off and it works perfectly:

Pri ToggleStartStop
If parameter == 0
parameter := CurrentPWM
Else
CurrentPWM := parameter
parameter := 0

It gets interesting when I tried to implement this a different way:

Pri ToggleStartStop
If parameter == 0
If CurrentPWM == 0
CurrentPWM := MinPWM * base ' MinPWM is the slowest PWM allowed (10%) by % and base is period normalized to 1%
parameter := CurrentPWM
Else
CurrentPWM := parameter
parameter := 0

While the first version actually works perfectly fine (I just have to initialize CurrentPWM to my default MinPWM value when I set everything up), I never could get nested "If" statements to work AT ALL. Every time I tried it, I got VERY strange results from the PWM output. And it didn't matter what I was checking or what I was setting, it failed every single time.

For example, in place of "If CurrentPWM == 0 -- CurrentPWM:= MinPWM * base", I tired (as a test) "If MinPWM == MinPWM -- waitcnt(clkfreq +cnt) just to wait 1 second if MinPWM was equal to MinPWM. MinPWM is not used by the PWM COG in any way shape or form, but it STILL caused really strange output from the LED.

The only conclusion I can come to is that either nested If statements are not allowed (but why doesn't the compiler complain?) or they ARE allowed, but you have to do something different in the formatting to get it to work OR I'm making some stupidly simple mistake and I can't see it!

Well? Anyone know why this is broken? Thanks for the help!

Oh, and I absolutely LOVE the Propeller!

Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:49:36 AM GMT

Comments

  • hippyhippy Posts: 1,981
    edited 2008-05-21 18:52
    To format your code so indentation shows in a posting wrap it between {code} and {/code} but replace those curly brackets with square ones.

    Nested IF's do work but indentation is important. I haven't studied your code so cannot comment on your algorithm logic.
  • clcorbinclcorbin Posts: 14
    edited 2008-05-21 20:25
    Hippy,

    Thanks for the info. Here is the formated attempt:

    Version that works:
    Pri ToggleStartStop
      If parameter == 0
        parameter := CurrentPWM
      Else
        CurrentPWM := parameter
        parameter := 0
    



    Version that doesn't:
    Pri ToggleStartStop
      If parameter == 0
        If CurrentPWM == 0
          CurrentPWM := MinPWM * base ' MinPWM is the slowest PWM allowed (10%) by % and base is period normalized to 1%
          parameter := CurrentPWM
      Else
        CurrentPWM := parameter
        parameter := 0
    



    Test function that didn't use ANYTHING the PWM COG used, but still cause strange PWM output:
    Pri ToggleStartStop
      If parameter == 0
        If MinPWM == MinPWM      ' Always true...
          waitcnt(clkfreq + cnt)       ' Pausing the input montoring COG, NOT the PWM COG.
          parameter := CurrentPWM
        Else
          CurrentPWM := parameter
          parameter := 0
    
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-05-21 21:45
    Unindent the parameter := CurrentPWM perhaps?

    Pri ToggleStartStop
      If parameter == 0
        If CurrentPWM == 0
          CurrentPWM := MinPWM * base ' MinPWM is the slowest PWM allowed (10%) by % and base is period normalized to 1%
        parameter := CurrentPWM
      Else
        CurrentPWM := parameter
        parameter := 0
    
    
Sign In or Register to comment.