Propeller proto board
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
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
Nested IF's do work but indentation is important. I haven't studied your code so cannot comment on your algorithm logic.
Thanks for the info. Here is the formated attempt:
Version that works:
Version that doesn't:
Test function that didn't use ANYTHING the PWM COG used, but still cause strange PWM output: