PDA

View Full Version : Propeller proto board



clcorbin
05-22-2008, 01:50 AM
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

hippy
05-22-2008, 02:52 AM
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.

clcorbin
05-22-2008, 04:25 AM
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 Stabler
05-22-2008, 05:45 AM
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