Why is TRUE == -1
Jay Kickliter
Posts: 446
In spin, why is TRUE equal to -1? Isn't TRUE usually 1 in most languages?
Also, what is the maximum delay I can create when using waitcnt @ 20MHz? Am I limited to the maximum value of a 32 bit singed character? I ask, because I somehow need to program a ~2 hour delay for a balloon-cutdown program.
Also, what is the maximum delay I can create when using waitcnt @ 20MHz? Am I limited to the maximum value of a 32 bit singed character? I ask, because I somehow need to program a ~2 hour delay for a balloon-cutdown program.
Comments
As for the maximum delay, you are limited to a 32 bit integer. However, you can stack multiple delays in a loop routine to compensate for this. For instance,
waitcnt(cnt + clkfreq) will give you a 1 second delay. If you multiply clkfreq by 60 your delay is stretched to a minute : waitcnt(clk + clkfreq*60) If you set this in a loop from 60 times you are left with a 1 hour delay, or if you loop it 120 times you get a 2 hour delay.
repeat 120
waitcnt(cnt + clkfreq*60)
........
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
~Some men see things as they are and ask "why?"
I dream of things that never were and ask "why not?"~
For timing, even though the system clock wraps around at 32 bits, you can wait for longer times with the same accuracy as shorter ones by using multiple WAITCNTs like:
A TRUE in other languages is also represented by a "-1" ... Take Visual Basic for example...
http://en.wikipedia.org/wiki/Visual_Basic
..."Boolean constant True has numeric value −1.· This is because the Boolean data type is stored as a 16-bit signed integer. In this construct −1 evaluates to 16 binary 1s (the Boolean value True), and 0 as 16 0s (the Boolean value False). "
In the case of the Propeller, the same thing is true, with the exception that the Boolean numbers are stored as a 32-bit signed integer instead of a 16-Bit signed integer.
To further quote the Visual Basic wiki site...
"This definition of True is also consistent with BASIC since the early 1970s Microsoft BASIC implementation and is also related to the characteristics of microprocessor instructions at the time."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/13/2008 4:42:26 PM GMT
This works out if FALSE is zero and TRUE is minus one.
In C and other language any random non-zero value is TRUE and complementing most of them will get you a different non-zero number that is also TRUE. Yuk.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Are you working on a high altitude balloon project? If so, tell us more. We would love to hear about it. Maybe in another thread though.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.sxmicro.com - a blog·exploring the SX micro
www.tdswieter.com
Tim, I am working on a balloon project. But at this point I don't have much substance to be worthy of a new thread/announcement. I need to learn this language a bit more and get my Ham license before launch. It's just me and a buddy working on it, so it's slow going now. What I do know is that although we're using amateur radio equipment for telemetry, this is not going to be a ham-centric project. We want it to be easier for non-ham people to understand and duplicate. I am also using a Motorola c168i phone for text-message position reports, but it is proving to be more difficult than expected. The Open GPS Tracker people have it down, but there's not a whole lot of information on interfacing with this phone outside of their project. I may just be overlooking something simple. I've only been able to get it to send a text message once, connecting to it through a USB serial adapter and my computer. I haven't even tried to get the propeller to communicate with it yet. The c168i phone might warrant a whole thread in itself, as I think it could be of value to propeller projects (since it's only $15, and has a TTL serial port). When I figure something out, I post it.
Jay,
I'd like to hear more about this when you have opportunity..
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
What heater meant by "complement" is "to perform the bitwise NOT operation (a.k.a. ones-complement)", wherein each bit is inverted from its current state. To "compliment" an integer would involve saying something nice about it, such as, "Whoa! Nice bits!"
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
Actually, I think I got the spelling correct quite by accident.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.