Shop OBEX P1 Docs P2 Docs Learn Events
Need help. I DON't know what is going on — Parallax Forums

Need help. I DON't know what is going on

RavenkallenRavenkallen Posts: 1,057
edited 2010-05-12 03:25 in Propeller 1
Hey, guys. I got another problem. Every time i try to add another method/ Object to my program the whole thing acts really strange. AS soon as i erase the method everything goes back to normal. It doesn't matter what method it is, it does it to all of them. I checked the memory and i still got like 6_000 longs left. Is there a limit to the number of methods/ Objects·a program can have? Most of the objects i use, use only one cog. This problem is so weird i don't know what to do. I can add additonal code to a existing method, but once i declare a new one, POOF, it acts retarded......Maybe you guys know something i don't. I can try posting my code if you guys need.....Thanks in advance....sad.gifsad.gifsad.gif

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-10 03:51
    Show us your code. There's not much we can do to help if we can't see what's causing the problem.

    -Phil
  • iQuitiQuit Posts: 78
    edited 2010-05-10 03:52
    You will have to post the code. Without it, we're shooting in the dark.

    Dan := thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "She may not be very pretty now, but she was somebody's baby once." Bugs Bunny
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-10 03:57
    i will post my code tommorow, after i get some much needed sleep. the solution to my problem seems to be ever elusive. i just don't get why it doesn't work. thanks for the quick reply
  • bill190bill190 Posts: 769
    edited 2010-05-10 14:45
    I've had similar problems with all programming in general. And it seems to always turn out to be something simple. But finding the problem can take a *lot* of testing and work.

    What helps me is to isolate the problem. Try adding a different method and see if that also causes a similar problem. Try running that troublesome method by itself or along with other entirely different code.

    (Is it the particular method which is the problem or adding any additional method/object which is the problem.)

    Then if I track the problem down to a particular method/object, THEN I can use fullduplexserial or whatever to display variable values at different points in the program to see what values are or if the program is even getting to that point.

    And if it is not getting to·a certain point like it should, if I can see what the·variables are or if a loop is looping like it should, then I can further track down the problem.

    FYI - I spent a whole day tracking down such a problem the other day. I was reading pulse values. The pulse reading object worked fine by itself, but not when included with my main program. It turned out the pulse reading object was looking for a long pause in the pulses before it would display any values. And my main program did not provide as long of a break in the pulses.

    So the solution was to reduce the wait time for a break in the pulses, then it displayed the pulse values just fine. (Or to add a longer delay between pulses in my program.)

    But it took a *lot* of time and testing to find that problem. I have cogs running all over the place, all sorts of different objects and methods. So my first thought was where do I begin!

    I have another problem now. And I am wondering if all my cogs are running or not. So I think today I will have each cog turn on a separate LED when it runs. Then I will be able to "see" that at least the cogs started.


    ·
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-10 16:29
    Here is the code. Sorry for it being so sloppy. It is still a work in progress. Stupid attachment manager wasn't working again, so i will have to post the whole thing here. AS soon as i add another method or object the thing goes beserk(even if the method has nothing in it). There should be plently of memory left.



    con
    ·_xinfreq = 5_000_000
    ·_clkmode = xtal1 + pll16X
    obj
    Serio: "parallax serial terminal"
    i2crw : "i2c"
    kb: "keyboard"
    decstr: "strtodec"

    var
    byte erase[noparse][[/noparse]2], nextline[noparse][[/noparse]3], chardata
    byte counter,space, counter2, chardata2, txbyte, databyte
    byte tempd, i2csys, i2cdata, Programdata[noparse][[/noparse]4000], datapoint
    long address, addresspointer
    pub systemstart
    erase := string(254, 81)
    nextline := string(254, 69, 60)
    serio.startrxtx(3,4,0,2400)
    kb.start(22, 23)


    ·····················

    serio.str(erase)
    waitcnt(clkfreq + cnt)
    repeat 10
    ·tempd := lookupz(counter: "Welcome to")
    ·serio.char(tempd)
    ·counter++

    counter := 0
    serio.str(nextline)
    repeat 15
    ·tempd := lookupz(counter: "StarRider V 3.0")
    ·serio.char(tempd)
    ·counter++
    counter := 0
    waitcnt(clkfreq * 2 + cnt)
    checki2c··
    menu·······


    pub menu
    counter := 0
    serio.str(erase)
    ·
    waitcnt(clkfreq/100 + cnt)
    repeat 17
    ·tempd := lookupz(counter: "P= Program······ ")
    ·serio.char(tempd)
    ·counter++
    counter := 0
    serio.str(nextline)
    repeat 20
    ·tempd := lookupz(counter: "O= options M= More······ ")
    ·serio.char(tempd)
    ·counter++
    counter := 0
    waitcnt(clkfreq + cnt)
    repeat
    · chardata := 0
    ·
    ·· readkb
    ··
    ·· if chardata == "p"
    ··· serio.str(erase)
    ··· waitcnt(clkfreq/100 + cnt)
    ··· repeat 20
    ···· tempd := lookupz(counter: "Program device······ ")
    ···· serio.char(tempd)
    ···· counter++
    ··· counter := 0
    ··· waitcnt(clkfreq + cnt)
    ··· serio.str(erase)
    ··· waitcnt(clkfreq/100 + cnt)
    ··· repeat 20
    ···· tempd := lookupz(counter: "O= Open N= new······· ")
    ···· serio.char(tempd)
    ···· counter++
    ··· counter := 0
    ··· serio.str(nextline)
    ···· repeat 7
    ····· tempd := lookupz(counter: "B= Back")
    ····· serio.char(tempd)
    ····· counter++
    ···
    ··· repeat
    ···· chardata := 0
    ···· readkb
    ······ if chardata == "b"
    ········ menu
    ······ if chardata == "o"
    ······· serio.str(erase)
    ······· counter := 0
    ······
    ········
    ·········
    ········· repeat 20
    ·········· tempd := lookupz(counter: "Type in file number")
    ·········· serio.char(tempd)
    ·········· counter++
    ··········
    ········· counter := 0·
    ······· repeat
    ··········
    ········· chardata := 0
    ········· readkb
    ·········· if chardata == "1"
    ··········· datapoint := 1
    ··········· editor
    ·········· if chardata == "2"
    ··········· datapoint := 2
    ··········· editor
    ·······
    ·········· if chardata == "3"
    ············ datapoint := 3
    ············ editor
    ·······
    ·······
    ······
    ······
    ······
    ·······
    ······
    ·····

    ····· if chardata == "n"

    ···
    ···
    ··
    ·
    ··

    ··
    ··
    · if chardata == "o"
    ··· serio.str(erase)
    ··· waitcnt(clkfreq/100 + cnt)
    ···· repeat 7
    ····· tempd := lookupz(counter: "Options····· ")·
    ····· serio.char(tempd)
    ····· counter++
    ··· counter := 0
    ··· waitcnt(clkfreq + cnt)
    ··
    ··· serio.str(erase)
    ··· waitcnt(clkfreq/100 + cnt)
    ···· repeat 20
    ····· tempd := lookupz(counter: "E= Erase Mem b= Back")
    ····· serio.char(tempd)
    ····· counter++
    ··· counter := 0
    ··· waitcnt(clkfreq/2 + cnt)
    ···· repeat
    ····· chardata := 0
    ····· readkb
    ······ if chardata == "b"
    ······· menu
    ····· if chardata == "e"
    ······ address := 0
    ······ repeat
    ······· i2crw.write(%10100000, address, 0, 16)
    ······· waitcnt(clkfreq/700 + cnt)
    ······· i2cdata := 0
    ········ if addresspointer == 200
    ········· serio.str(erase)
    ········· addresspointer := 0
    ········· i2cdata := i2crw.read(%10100000, address, 16, 8)
    ········· serio.dec(i2cdata)
    ········· serio.dec(address)
    ······· addresspointer++
    ······· address++
    ········ if address > 10_000
    ········· menu
    ··
    ··
    ··
    · if chardata == "m"
    ·· more
    ········
    ·waitcnt(clkfreq/100 + cnt)









    pri checki2c
    counter := 0
    address := 32_000
    i2crw.init(20,21,0)
    serio.str(erase)
    i2crw.write(%10100000, address, "A", 16)
    waitcnt(clkfreq/100 + cnt)
    i2cdata := i2crw.read(%10100000, address, 16, 8)
    waitcnt(clkfreq/100 + cnt)
    if i2cdata == "A"
    ·repeat 20
    · tempd := lookupz(counter: "Memory device found······ ")
    · serio.char(tempd)
    · counter++
    else
    ·repeat 20
    · tempd := lookupz(counter: "EEPROM not found··· ")
    · serio.char(tempd)
    · counter++

    waitcnt(clkfreq * 2 + cnt)
    counter := 0
    serio.str(erase)·




    pub readkb
    if kb.gotKey
    ·chardata := kb.getKey


    pub More
    counter := 0
    serio.str(erase)
    ·
    waitcnt(clkfreq/100 + cnt)
    repeat 17
    ·tempd := lookupz(counter: "T= Tools B= Back····· ")
    ·serio.char(tempd)
    ·counter++
    counter := 0
    repeat
    · chardata := 0
    ·
    ·· readkb
    ··
    · if chardata == "t"
    ··· serio.str(erase)
    ··· waitcnt(clkfreq/100 + cnt)
    ···· repeat 12
    ····· tempd := lookupz(counter: "Tools······ ")
    ····· serio.char(tempd)
    ····· counter++
    ···· counter := 0
    ·· waitcnt(clkfreq + cnt)
    ·· more·········
    ··
    ··
    · if chardata == "b"
    ·· menu
    ·waitcnt(clkfreq/100 + cnt)·


    pub editor
    serio.str(erase)
    waitcnt(clkfreq + cnt)
    serio.dec(datapoint)
    waitcnt(clkfreq + cnt)
    menu
  • KyeKye Posts: 2,200
    edited 2010-05-10 16:35
    Attachment please.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • TimmooreTimmoore Posts: 1,031
    edited 2010-05-10 16:41
    One place to look is string, it doesn't do what you think it does. It returns a long address of where the string is in memory. you are writing that to a 2/3byte location causing memory overwrites
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-10 16:55
    Hey, kye. I just said that the attachment manager wasn't working, but thanks for the help......
    THANK you timmoore. You are referring to the strings that i have up toward the top. SO they return the long address of where the string is in memory? I acctually had problems with those to. Every time i tried to add another string the whole thing went nuts. So if i took them out would that eliminate the problem. Maybe that is the problem. Do you know of another way to put info into Strings?
  • TimmooreTimmoore Posts: 1,031
    edited 2010-05-10 17:31
    Your symptoms are classic for memory overwrites, 3 common places are 1: stack overrun - you dont have extra cogs - unlikely. 2: arrays 3: typing i.e. wrong types. I looked at your arrays because of 2 but ended up deciding it was 3.
    A string in spin is a null terminated byte array.
    So the following would work, note I have increased the size of the arrays by 1 for the null(0) terminator
    var 
    byte erase[noparse][[/noparse]3], nextline[noparse][[/noparse]4]
     
    pub systemstart
    erase[noparse][[/noparse]0] := 254                  ' erase := string(254, 81)
    
    erase[noparse][[/noparse]1] := 81
    erase[noparse][[/noparse]2] := 0
    nextline[noparse][[/noparse]0] := 254               'nextline := string(254, 69, 60)
    nextline[noparse][[/noparse]1] := 69
    nextline[noparse][[/noparse]2] := 60
    nextline[noparse][[/noparse]3] := 0
    
    
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-10 19:09
    thanks for clarifying. i tried your idea and it works so far. i have not yet tried to add another method, but i will soon. so the string command will overwrite the memory?
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-05-10 19:42
    You could define your strings in a DAT section and print them out using serio.str as follows.

    dat
    erase byte 254, 81, 0
    nextline byte 254, 69, 60, 0
    welcome byte "Welcome to", 0
    starrider byte "StarRider V 3.0", 0
    ...
    serio.str(@erase)
    serio.str(@Welcome)
    serio.str(@nextline)
    serio.str(@starrider)

    Or you could use the string·directive to do it inline.

    serio.str(string(254, 81))
    serio.str(string("Welcom to"))
    serio.str(string(254, 69, 60))
    serio.str(string("StarRider V 3.0"))

    The string directive automatically adds the zero at the end, and it stores the string data within the program instead of in a DAT section.· However, it will create multiple identical strings if you use it with the same string of characters in multiple places in your program.· In that case, it may be better to define the string once in a DAT section.

    Dave
    ·
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-12 02:09
    Thanks a ton guys. I tested your code and it works. No more problems.....WHOO
  • CarolYanCarolYan Posts: 1
    edited 2010-05-12 02:31
    Hi, I am a newbie here, currently doing my final year project but is acing some problems. I would like to ask about the codes on ultrasonic sensor together with the LEDs, when the ultrasonic sensor sensed a motion, the LEDs would start blinking. We have got the codes for the LEDs to blink, but could not find the codes for the ultrasonic sensor and how to connect it on the breadboard with the propeller chip?
  • TimmooreTimmoore Posts: 1,031
    edited 2010-05-12 03:25
    CarolYan, Which ultrasonic sensor? the ping)) there is an object in obex for it, for the srf08 there is also an object, for the vex sensor I dont remember an object on obex but I have an object if its that sensor.
Sign In or Register to comment.