Shop OBEX P1 Docs P2 Docs Learn Events
10/10 is 1..... right? — Parallax Forums

10/10 is 1..... right?

CannibalRoboticsCannibalRobotics Posts: 535
edited 2010-05-05 21:45 in Propeller 1
I have this little snippet of SPIN that is misbehaving. For all values of 'val' between 0 and 99, the value that arrives in cf.drawlevel is an integer truncated·val/10 which is correct, ie. if Val = 40 going in, the Val arriving is 40/10 or 4. This works fine for everything except 10.
If the value coming in through SingVol is Val=10, the arrival data·at cf.drawlevel 10 also?
10/10 is 1 right?
Pub SingVol(Chan,Val)  '' Sets volume in I2C format and updates displays     
        SetVol(Chan,Val)    
        cb.SetControl(44 + Chan,Val)
        val := val / 10            
        cf.drawlevel(val)

confused.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-05 14:47
    Yes, 10/10 is 1. You'll have to look elsewhere for your problem.
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2010-05-05 14:59
    Thanks Mike! LOL
    Any other suggestions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Signature space for rent!
    Send $1 to CannibalRobotics.com.
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-05-05 15:53
    Does val = Val ?
  • bill190bill190 Posts: 769
    edited 2010-05-05 16:24
    What helps me the most with problem like this is to "see" what is going on.

    Display what the values are at various points. See what is happening to a variable at different points.

    For the propeller, I use the FullDuplexSerial object to display values on the Parallax serial terminal.

    Might want to search these forums to read more about using that object. But here are the "ingredients"...

    A fast clock speed...

    CON
    · _xinfreq = 5_000_000····················
    · _clkmode = xtal1 + pll16x

    Include the object and rename it to "Debug"...

    OBJ
    · Debug : "FullDuplexSerial"

    Start the object by placing this·in the PUB section...

    Debug.start(31, 30, 0, 115200)

    Then you can display things on the terminal like this...

    Debug.str(string("Hi There!"))

    Display the value in decimal of the variable tenthsec...
    Debug.dec(tenthsec)

    Carrage return...
    Debug.tx(Debug#CR)

    Load the program to EEPROM,·get your serial terminal up and click on enable, set the baud to 115200.

    Then click reset on the propeller.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-05-05 20:59
    If you have a prop pin to spare and a TV (or monitor) with video input (yellow RCA) you can also use my Debug_1pinTV and use the same idea for displaying variables as bill suggests, but on the TV. See the obex under tools debug..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2010-05-05 21:26
    Well, it works but I'm still stumped. So I changed
    Pub SingVol(Chan,val) '' Sets volume in I2C format and updates displays     
            SetVol(Chan,val)    
            cb.SetControl(44 + Chan,val)
            val := val/10         
            cf.drawlevel(val)
            
    

    To

    Pub SingVol(Chan,val) '' Sets volume in I2C format and updates displays     
            SetVol(Chan,val)    
            cb.SetControl(44 + Chan,val) 
            cf.drawlevel(val)
    

    and
    PUB DrawLevel(Level)
      
     case Level
      0:...   
    

    to
    PUB DrawLevel(Level)
      Level := Level/10
      
     case Level
      0:...   
    

    ·And it works. Seems to me that moving this operation from one cog to another should not change the outcome of the math?


    PS: There is a 'debug' statement at the end of the 'case' showing me what the value is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Signature space for rent!
    Send $1 to CannibalRobotics.com.

    Post Edited (CannibalRobotics) : 5/5/2010 9:47:52 PM GMT
  • lonesocklonesock Posts: 917
    edited 2010-05-05 21:45
    I'm guessing something is stepping on the memory where 'val' lives in the 1st cog, and that it happens during the time it would have taken to parse and execute the /10 command. try executing a waitcnt delay in place of the /10 line?

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
Sign In or Register to comment.