Help a Newbie? Will this work?
Andy_F
Posts: 5
I'm not new to microcontrollers, but new to the Propeller.
Here goes:
I have some variables (longs) defined in my program. Each one is a pattern for lights being on or off. I am interested in the first 24 bits of each pattern and want to check each bit in turn and turn on the output if it is a one - off if zero.
Which of these methods will work? Sorry, but the editor seems to remove the leading spaces. I've put periods in to represent the leading spaces. Both of these compile fine, which leads me to believe both will work.
repeat index from 0 to 23
...IF frontleft[noparse][[/noparse]index]
......OUTA[noparse][[/noparse]0]~~
...ELSE
......OUTA[noparse][[/noparse]0]~
There's a few others, but that's the jist for one of them - 24 comparisons. Or, do I have to do this:
repeat index from 0 to 23
...IF frontleft[noparse][[/noparse]index] == %1
......OUTA[noparse][[/noparse]0]~~
...ELSE
......OUTA[noparse][[/noparse]0]~
Does the first one work, or the second? I'm waiting for my Propeller Demo Board to get here and wanted to get started on the program.
Thanks for any help.
Andy
Here goes:
I have some variables (longs) defined in my program. Each one is a pattern for lights being on or off. I am interested in the first 24 bits of each pattern and want to check each bit in turn and turn on the output if it is a one - off if zero.
Which of these methods will work? Sorry, but the editor seems to remove the leading spaces. I've put periods in to represent the leading spaces. Both of these compile fine, which leads me to believe both will work.
repeat index from 0 to 23
...IF frontleft[noparse][[/noparse]index]
......OUTA[noparse][[/noparse]0]~~
...ELSE
......OUTA[noparse][[/noparse]0]~
There's a few others, but that's the jist for one of them - 24 comparisons. Or, do I have to do this:
repeat index from 0 to 23
...IF frontleft[noparse][[/noparse]index] == %1
......OUTA[noparse][[/noparse]0]~~
...ELSE
......OUTA[noparse][[/noparse]0]~
Does the first one work, or the second? I'm waiting for my Propeller Demo Board to get here and wanted to get started on the program.
Thanks for any help.
Andy
Comments
Sorry I couldn't be more help on the repeat loop, as I am just learning the prop also...
Take a look at the various operators I've used and see if you can figure out why this works. The WAITCNT statement just adds a 50ms delay between bits displayed so the whole loop takes a little over a second.
Sorry, should have been clearer. Actually, I am controlling 10 outputs, each one is controlled by a pattern like 'frontleft'. I have a delay and switch checking, etc, I just didn't include them. Basically, each bit of each pattern represents a tick. I control the outputs based on the patterns and the delay at the bottom of the repeat loop controls how long each tick lasts. I also check if the master switch has been turned off and quit the loop if it has (after I wait for a 50ms debounce time and check it again).
As to what you wrote:
I think I get the AND and the bitwise decode - as it steps index through from 0 to 23, pin0 is turned on or off based on what the bit in frontleft is. Basically what I was fumbling around trying to do. What I don't understand is the requirement for the "is not equal to 0"
Could I trouble you to explain?
Thanks very much,
Andy
I GET IT!!!
If the bit at (index) position of frontleft is NOT a zero - set outa[noparse][[/noparse]0] to that bit - in other words, of its a 1, set outa[noparse][[/noparse]0] to a 1 as well.
If the bit is a zero, outa[noparse][[/noparse]0] will be set to zero as well - because of the AND. I think. I did a lot better with assembler.
Did I learn well, master?
Thanks,
Grasshopper
<loved 'Kung Fu' as a kid!>
Post Edited (Andy_F) : 3/28/2009 1:47:20 AM GMT
I just learned the same lesson from Mr. Green the other day in a past post of mine...
http://forums.parallax.com/forums/default.aspx?f=25&m=337395