Shop OBEX P1 Docs P2 Docs Learn Events
if ( var == constant) not working*fixed!* — Parallax Forums

if ( var == constant) not working*fixed!*

IncVoidIncVoid Posts: 40
edited 2009-09-09 00:40 in Propeller 1
*fixed by lowering clock speed to 64mhz· "PLL8X"*

I have this code

but I seem to not be getting true (-1, $ffff_ffff)'s back from certain == boolean statements

{{I never changed any of this "top stuff"
4D Systems (c) 2007· ·All rights reserved
original Authors: Atilla Aknar
· · · · ·Steve McManus
· · · · ·
·

}}

CON
· _CLKMODE· · · = XTAL1 + PLL16X· · · · · · · · · · · ·
· _XINFREQ· · · = 8_000_000

· dSlow· · · · ·= 50
· dFast· · · · ·= 20
· SCREEN_BUTTON = $02
· UP_BUTTON· · ·= $04
· DOWN_BUTTON· ·= $10
· fresh· · · · ·= $01
VAR
· long screen_on_off
· long tbuttons
· long frq
· long refresha
· long refreshb
· long testdat1
· long testdat2
· long testdat3
· long testdat4
·
OBJ
· OLED· : "uOLED-96-Prop_V4"
· DELAY : "Clock"
· xpad· : "xpad"
PUB Demo

· DELAY.Init(8_000_000)

· OLED.InitOLED
· screen_on_off := $FFFF_FFFF
· OLED.CLS
· xpad.start
· frq := $c0
· xpad.setFRQA(frq)
· refresha := fresh
· refreshb := fresh
· buildtestdata
·
· 'REPEAT
· · 'Splash
· · 'Scroll
· · 'Pixels
· · 'PropLines· · · ·
· · 'Rectangles
· ·' MovingLines
· · 'TextString
· REPEAT
· ·tbuttons := xpad.getPress
· ·
· ·IF (refresha & fresh) 'something changed so refresh the screen. THIS IS THE ONE THAT WON'T WORK
··· OLED.CLS····································································· '·AS (REFRESHA == FRESH)
····· 'delay.pauseMsec(500)
· · refresha := $00· · · 'clear the fresh request
· · oled.PutText(0,0,0, 63,63,0, xpad.updateButtonString)
· · oled.PutText(0,1,0, 0,63,63, xpad.updateFrqaString)
· · oled.puttext(0,2,0, 63,0,0, @teststring1)
· · oled.puttext(0,3,0, 63,0,0, @teststring2)
· · oled.puttext(0,4,0, 63,0,0, @teststring3)
· · oled.puttext(0,5,0, 63,0,0, @teststring4)
· · oled.puttext(0,6,0, 63,0,0, @teststring5)
· · oled.puttext(0,7,0, 63,0,0, @teststring6)

· ·
· ·IF ((tbuttons & SCREEN_BUTTON)) 'screen button press means toggle screen
· · ·IF (screen_on_off == $FFFF_FFFF)· 'THIS ONE WORKS
· · · screen_on_off := $0000_0000
· · · OLED.PowerDown_Seq
· · · delay.pauseMsec(250)
· · ·else '(screen_on_off == 0)
· · · screen_on_off := $FFFF_FFFF
· · · OLED.PowerUp_Seq
· · · delay.pauseMsec(250)

· ·IF ((tbuttons & UP_BUTTON)) 'increase FRQA value
· · ·frq += 16
· · ·refresha := fresh
· ·elseif ((tbuttons & DOWN_BUTTON))'decrease frqa and request refresh
· · ·frq -= 16
· · ·refresha := fresh
· ·updatefrq·
· ·
pub buildtestdata· 'ALL THE =='S SHOULD GIVE ME $FFFF_FFFF'S right?
· · refreshb := $01
· · testdat1 := (refreshb == $01)
· · testdat2 := (refreshb == fresh)
· · testdat3 := (fresh == $01)
· · testdat4 := (fresh == fresh)
· · valtostrings(@teststring1,testdat1,6)
· · valtostrings(@teststring2,testdat2,6)
· · valtostrings(@teststring3,testdat3,6)
· · valtostrings(@teststring4,testdat4,6)
· · valtostrings(@teststring5,refreshb,6)'
· · valtostrings(@teststring6,fresh,6)'fresh is constant
· ·
pub valtostrings(str,val,off) | mask, i, t 'convert values and put hex representation in screen
· mask := $0f
· t := mask & val
· byte[noparse][[/noparse]str][noparse][[/noparse]off + 1] := hexstring.byte[noparse][[/noparse]t]
· t := mask & (val >> 4)
· byte[noparse][[/noparse]str][noparse][[/noparse]off] := hexstring.byte[noparse][[/noparse]t]
·







· ·
pub updatefrq
· ·frq #>= 0·
· ·frq <#= 640
· ·frq := frq & $3ff
· ·xpad.setFRQA(frq)
·

· ·
dat
· · · ·byte "doobiedoobie doo"
fresh2 long (fresh == $01)
· · · ·long (fresh == $01)
fresh3 long (fresh == $02)
teststring1 byte"r==l x00",0
teststring2 byte"r==c x00",0
teststring3 byte"c==l x00",0
teststring4 byte"c==c x00",0
teststring5 byte"refb x00",0
teststring6 byte"con· x00",0
hexstring· ·byte"0123456789abcdef"

l_02530293a01348ea977f29cf1727961b.jpg
thats what i get back from my device after assigning them. I'll play with it some more

but if i say IF (refresha == $01) that if statement never executes
even if i put it to IF (refresha == fresh) after saying refresha := fresh earlier
yes IF (refresha & fresh) works as needed.


Post Edited (IncVoid) : 9/9/2009 8:15:02 PM GMT

Comments

  • IncVoidIncVoid Posts: 40
    edited 2009-09-04 19:28
    I also just now put out the results of my (screen_on_off == $ffff_ffff) which works as well
    and on screen it shows ff coming back (true) its bugging the hell out of me why one == statement works and another doesn't.

    *edit* I attached my .spin files its not commented well and some of it is from original gamepad drver...
    but any input would help.

    Post Edited (IncVoid) : 9/4/2009 7:50:25 PM GMT
  • mparkmpark Posts: 1,305
    edited 2009-09-05 02:43
    Suggest you print out refresha just before "IF (refresha ..."

    Not sure if you want "refresha & fresh" or "refresha AND fresh".
  • IncVoidIncVoid Posts: 40
    edited 2009-09-05 03:58
    I only used & instead of AND cause its just easier for me..preference I guess? but AND would give me back all $ffff_ffff correct? promotes any non-0 ($01 being non 0) to -1? which is $ffff_ffff for a long correct?
    alright I'll update the string and oled.puttext right before I do the test so I can see it.

    no luck... still comes back as 00's
    <> seems to always pass through too
    also!

    i did long[noparse][[/noparse]@refreshb] := long[noparse][[/noparse]@fresh2]
    fresh2 is a long that is from the constant fresh

    then did testdat1 := ((long[noparse][[/noparse]@refreshb]) == (long[noparse][[/noparse]@fresh2]))
    then did my vartostring conversion with testdat1 and the test string
    ·got back 0's....false..even though ti should be all 1's for true

    I also took out the repeat so I know it only executes once... still nothing
    the only thing that works is => and > symbol well works incorrectly they are equal! I know that because I also output their value at least bottom 8 in 2 hex numbers
    i swap @frefreshb with @fresh2 and => and > doens't change
    I can see how => works cause it's equal or greater
    but the > should never work cause they are equal.

    I need to get a full 8 digit hex out so I can see if there is some wierd value in there..has to be.
    I'll get that going and see.

    Post Edited (IncVoid) : 9/5/2009 4:47:55 AM GMT
  • mparkmpark Posts: 1,305
    edited 2009-09-05 04:44
    & is bitwise, AND is logical.
  • IncVoidIncVoid Posts: 40
    edited 2009-09-05 04:53
    so any non 0 AND non 0 would yield a true? even if bitwise and yield a 0?
    1000 and 0001 = true
    1000 & 0001 = false?

    got a longtostring method
    ·and fresh is 00000001
    refreshb···is 00000001
    and still the only thing that is triggering a true (all 1's back) is a·">" or a·"=>"·even tho they are clearly equal.

    I removed the repeat except at the end so it blocks at the end.
    there is nothing else going on except the screen driver program.
    I took out my xpad.start call so it can't be another cog bug.
    I'm tempted to compile it on another computer and hope its not some viral activity on my comp.
    which would be very far fetched to say that it only affects my compiled .spin-s.
    I tried the .98 propeller tool from the hydra cd and got the same results back.



    Post Edited (IncVoid) : 9/5/2009 5:28:53 AM GMT
  • mparkmpark Posts: 1,305
    edited 2009-09-05 13:49
    IncVoid said...
    so any non 0 AND non 0 would yield a true? even if bitwise and yield a 0?
    1000 and 0001 = true
    1000 & 0001 = false?

    Assuming binary or hex, yes, though I'd say 1000 & 0001 = 0 rather than false (just being picky).

    Please reduce your program to a minimal test case. Take out everything except the parts pertaining to refreshb. I'm having trouble following your description of the problem.
  • IncVoidIncVoid Posts: 40
    edited 2009-09-07 00:44
    fresh is a constant.
    refresha and refreshb are longs
    I assign the constant to the longs (refresha, refreshb)
    the if statement which asks if they are equal (refreshb == fresh) never executes

    the if statement with (refresha == fresh) never executes.

    refreshb == fresh returns 0's
    when I know refreshb and fresh are both $0000_0001
    all I have is the clear screen, assignments
    even tried an alternate assignment as long[noparse][[/noparse]@refreshb] := fresh
    I then convert refreshb and fresh to strings
    I store the result of ((refreshb) == (fresh)) into testdat1
    convert testdat1 to a string.
    output all 3 strings to the screen via OLED.puttext

    test again for (refresha == fresh) because thats what I originally wanted to test for
    and that if block never executes, because I only get the original 3 strings
    then a final repeat to block any further execution.

    I don't see why the == isn't working yet a > will come back as true when they are equal!






    {{I never changed any of this "top stuff"
    4D Systems (c) 2007·· All rights reserved
    original Authors: Atilla Aknar
    ········ Steve McManus
    ········
    ·
    }}
    CON
    · _CLKMODE····· = XTAL1 + PLL16X·······················
    · _XINFREQ····· = 8_000_000
    · dSlow········ = 50
    · dFast········ = 20
    ·
    · fresh········ = $0000_0001
    VAR
    · long screen_on_off
    · long tbuttons 'unused
    · long frq 'unused
    · long refresha
    · long refreshb
    · long testdat1 'only one of the 4 used
    · long testdat2
    · long testdat3
    · long testdat4
    ·
    OBJ
    · OLED· : "uOLED-96-Prop_V4"
    · DELAY : "Clock"
    ·
    PUB Demo
    · DELAY.Init(8_000_000)
    · OLED.InitOLED
    · OLED.CLS
    · refresha := fresh
    · refreshb := fresh
    ·
    ·
    ··
    ·· long[noparse][[/noparse]@refreshb] := fresh 'assign it refreshb := $0000_0001
    ·· longtostring(@teststring5,refreshb)
    ·· longtostring(@teststring6,fresh)
    ·· testdat1 := ((refreshb)==(fresh)) 'THIS IS THE PART COMING BACK AS 0'S!
    ·· valtostrings(@teststring1,testdat1,6)
    ·· oled.PutText(0,2,0, 63,60,0,@teststring1)
    ·· oled.PutText(0,3,0, 63,0,0,@teststring5)· 'refreshb's value
    ·· oled.PutText(0,4,0, 63,0,0,@teststring6)· 'fresh's value
    ··
    ·· IF (refresha == fresh) 'something changed so refresh the screen. 'THIS NEVER EXECUTES EITHER!
    ···
    ··· refresha := $00····· 'clear the fresh request
    ···
    ···
    ··· oled.puttext(0,3,0, 63,0,0, @teststring2)
    ··· oled.puttext(0,4,0, 63,0,0, @teststring3)
    ··· oled.puttext(0,5,0, 63,0,0, @teststring4)
    ··· oled.puttext(0,6,0, 63,0,0, @teststring5)
    ··· oled.puttext(0,7,0, 63,0,0, @teststring6)
    ···
    ·
    ···
    ·· repeat 'do nothingelse
    ···
    pub valtostrings(str,val,off) | mask, i, t 'convert values and put hex representation in screen
    · mask := $0f
    · t := mask & val
    · byte[noparse][[/noparse]str][noparse][[/noparse]off + 1] := hexstring.byte[noparse][[/noparse]t]
    · t := mask & (val >> 4)
    · byte[noparse][[/noparse]str][noparse][[/noparse]off] := hexstring.byte[noparse][[/noparse]t]
    ··
    pub longtostring(str,val) | t,b,i
    repeat i from 0 to 7
    ·b := val
    ·b := b >> (i * 4)
    ·b := b & $0f
    ·byte[noparse][[/noparse]str][noparse][[/noparse]7-i]:= hexstring.byte[noparse][[/noparse]b]
    ···
    dat
    ······ byte "doobiedoobie doo"
    fresh2 long (fresh)
    ······ long (fresh == $01)
    fresh3 long (fresh == $02)
    teststring1 byte"r==l x00",0
    teststring2 byte"r==c x00",0
    teststring3 byte"c==l x00",0
    teststring4 byte"c==c x00",0
    teststring5 byte"refb x00",0
    teststring6 byte"con· x00",0
    hexstring·· byte"0123456789abcdef"
  • Jesse DruehlJesse Druehl Posts: 25
    edited 2009-09-07 09:54
    Check your indention in the method longtostring, that repeat should be indented and everything inside the repeat should be indented further.

    Also, try changing:
    _CLKMODE = XTAL1 + PLL16X

    to:
    _CLKMODE = XTAL1 + PLL8X

    I have one of these modules, and it can behave strange running at 128Mhz (which is not really wise for the prop). They later changed to a 10Mhz crystal, but the ones with an 8Mhz are best run at 64Mhz (8Mhz * PLL8x).
  • IncVoidIncVoid Posts: 40
    edited 2009-09-09 00:35
    I'll change the indent. then change the clock speed constant and see which solves it.
  • IncVoidIncVoid Posts: 40
    edited 2009-09-09 00:40
    oh yeah! BIG THANKS to you mpark and Jesse!

    I was begginning to think the compiler was poor. I was about ready to start looking through the binary image of the compiled to spin and looking for == op codes to see if they were even there.







    my indent was fine. I could tell by the indent ctrl + i block identifier
    but you were nail on the head with pll8 I was stoked to see the difference with it!
    the if refresha == fresh "if block" now executes!
    I was never so happy to see garbage on screen! (from it writing strings in the same place without a cls
    ·*edit* no video. focus won't work that well on it.

    That is so strange why it won't work at 128mhz. I wonder why? internal switching not able to catch up and proper values not showing up?
    I just have to double up my FRQA value and my rapid fire should be back to the same speed.
    half the clocks, FRQA is being added half as much to PHSA now. so I just double it right?
    sounds good to me!

    any other notes about the 96 oled prop? is that why they stopped making them?

    also how do i mark my topic as solved?

    Post Edited (IncVoid) : 9/9/2009 12:58:23 AM GMT
Sign In or Register to comment.