On page 15 of the PBP3 Reference Manual (1.3) it says that "Long variables are 32-bits wide and can hold values -2147483648 to 2147483648. Is it really true you can have a negative number? Thanks, Ed
On page 15 of the PBP3 Reference Manual (1.3) it says that "Long variables are 32-bits wide and can hold values -2147483648 to 2147483648. Is it really true you can have a negative number? Thanks, Ed
Only if you use PBPL instead of PBPW then yes. You can make e.g. comparisons for negative numbers.
In the abobe example although Bval is byte, internally the PBPL holds the temporary result in a long variable which in turn can hold negative numbers too.Code:Bval VAR BYTE Bval = 0 IF ((Bval – 1) < 0) THEN negative
So the result of the IF-THEN will goto negative.
Ioannis
http://melabs.com/resources/articles/longs.pdf
Might be of interest too.
Dave
Always wear safety glasses while programming.
Ioannis,
Are you sure about that?In the abobe example although Bval is byte, internally the PBPL holds the temporary result in a long variable which in turn can hold negative numbers too.
So the result of the IF-THEN will goto negative.
I thought that although you could "manually" look at the highest bit (IF BVal.7 THEN Negative) to see if it's negative doing a comparison for less than zero only really works with variables declared as LONGs. Or are you saying that it'll actually work because you're doing an intermediate calculation in your actual comparison ieWorks, while...Code:BVal VAR BYTE BVal = 0 If (BVal - 1) < 0 THEN Negative..doesn't?Code:BVal VAR BYTE BVal = 0 BVal = BVal - 1 If BVal < 0 THEN Negative
Guess I could try it myself....
/Henrik.
First code will work, if you use PBPL, because result is stored into temporally long variable.
That is same as this
Temp VAR LONG
BVal VAR BYTE
BVal = 0
Temp = BVal - 1
If Temp < 0 THEN Negative
That's what I thought, makes sense, thanks!
I haven't yet used PBPL in any project. I tried on my servo project but the "cost" of compiling with PBPL was too high so I managed without it.
/Henrik.
hello
As am not super fluent in English, I understand that if I want to use PBPL.exe I need to use a 18Fxxx PIC
I need to use a variable that will contents the number 39000000 (39 millions)
it is use in a frequency generator that goes to this frequency
my board (display and push buttons is equiped with a 16F877 so I have no chance to use such LONG variable !
Am I right ?
francois F1CHF
thanks
Last edited by F1CHF; - 26th December 2012 at 18:20. Reason: keyboard error !
Hi,
Yes, LONGs can only be used on 18-series parts. Do you need to do any math etc on that 32bit variable or are you just trying to store it? If you only need to store it then simply use an array of 4 bytes. If you need math you could always take a look at Darrels N-Bit math routines which will allow you to declare variables of "any" size and do math with them.
/Henrik.
Thanks Henrik for this quick answer
But it is "too much" for my old brain !
Darrel has done a great job , as usual !
yes I have just one calculation (I got the Arduino code)
something like that
unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_REF
frequency will go from 1 to 39 millions
DDS_REF is 125 millions
and I must decode what is the POW(2,32) !
For this need I think that I will order an Arduino board !
Happy new year for everybody
and all my congratulations for this very nice help forum, it is great
Francois F1CHF (radio amateur) 65 years old now ....
Bookmarks