SX28 Memory Problem

Alex-MAlex-M Posts: 9
edited 2010-11-07 - 14:12:02 in Microcontrollers
Hi!

I have a problem with the memory in the SX28. I'm using the SX-Key v3.3.0.
If I open the "Memory usage" (under "Run" in the menu), it looks like this:

Page 0 - 0 to 551
lllllllllllllllllllllllllllllllllllllllll 489 bytes
Page 1 - 512 to 1023
l_______________l 0 bytes
Page 2 - 1024 to 1535
l_______________l 0 bytes
Page 3 - 1536 to 2047
l_______________l 1 bytes


So the program works fine, but I removed a lot of code to make it work! If I put it back i got memory usage on "Page 1" and the program do not work!

Do I need to tell the SX-Key that I using "Page 1"? Or do I need to put somthing in the code to make "Page 1" work?


Thanks in advace
Alex-M

Comments

  • Dave HeinDave Hein Posts: 5,907
    edited 2010-11-03 - 08:51:25
    It's been a while since I programmed the SX, but I think your problem is caused by the fact that calls and jumps are normally done within a page. You should use the long version of the jump and call instructions by adding an "@ character before the label. Instead of doing a jmp label1" you should do "jmp @label1". For a call do "call @sub1" and use "retp" instead of "ret".

    Subroutine calls are a bit tricky because the target address must be in the first half of the page. I normally put a jump table at the beginning of my program and do my calls through the jump table. I always use the long version for jumps and calls even though most of my jumps and calls may be in the same page. It's just easier for me to not have to worry about page boundaires.

    Keep in mind that long jumps take an extra cycle, and they will change the timing of the loops. This is important to remember for timing loops.

    Dave
  • Alex-MAlex-M Posts: 9
    edited 2010-11-03 - 09:20:27
    Thanks, but I'm using the BASIC not the asembly.

    I seen other programs that works fine and the are using 2 or 3 pages and I can't nind any thing special in there code.

    Some times the program works for like a minute.

    In the beginig of the program it tests a LED for 1 sec but somtimes (when the program works) the LED is on for 2 to 5 sec instead of 1 sec. (In the code "PAUSE 1000")
  • RobotWorkshopRobotWorkshop Posts: 2,300
    edited 2010-11-03 - 11:00:11
    I've run into similar issues with SX/B when the program code was long enough to spam multiple banks of memory. Often re-arranging some of the code can correct it. In my case I was able to pull out several sections of code and make them subroutines which I moved toward the end of the program. Calling the subroutine didn't have any issues spanning a bank of code.

    It may be an option that works for you. If not and your code is something you can post then others can try to reproduce the problem to help find a way around it.

    Robert
  • Dave HeinDave Hein Posts: 5,907
    edited 2010-11-03 - 11:10:01
    I did most of my SX coding in assembly, and I didn't use SX/B very much. However, I seem to recall there is an issue with the location of subroutine declarations. I believe they should all be at the beginning of the code so that the jump table is built in the first half of page 0.

    It would help if you post your code. Otherwise, we can only guess about what the problem is. Hopefully, someone more familiar with SX/B will respond soon.
  • Alex-MAlex-M Posts: 9
    edited 2010-11-03 - 14:04:05
    This is the orginal code. I tryed to removw some of the buttons so I only have 10 buttons instead of 16. And when I do that all works perfectly fine. I think it's because I only using "Page 0".


    'Panel 16ch Tx
    'Version 1.0


    'Config
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000

    'I/O
    Sio PIN RA.0
    Spkr PIN RA.2

    BtnAll PIN RA.1
    Btn1 PIN RB.0
    Btn2 PIN RB.1
    Btn3 PIN RB.2
    Btn4 PIN RB.3
    Btn5 PIN RB.4
    Btn6 PIN RB.5
    Btn7 PIN RB.6
    Btn8 PIN RB.7
    Btn9 PIN RC.0
    Btn10 PIN RC.1
    Btn11 PIN RC.2
    Btn12 PIN RC.3
    Btn13 PIN RC.4
    Btn14 PIN RC.5
    Btn15 PIN RC.6
    Btn16 PIN RC.7



    'Variablar
    Cmd VAR Byte

    Btn1_State VAR Bit
    Btn2_State VAR Bit
    Btn3_State VAR Bit
    Btn4_State VAR Bit
    Btn5_State VAR Bit
    Btn6_State VAR Bit
    Btn7_State VAR Bit
    Btn8_State VAR Bit
    Btn9_State VAR Bit
    Btn10_State VAR Bit
    Btn11_State VAR Bit
    Btn12_State VAR Bit
    Btn13_State VAR Bit
    Btn14_State VAR Bit
    Btn15_State VAR Bit
    Btn16_State VAR Bit


    PROGRAM Start
    Start:

    '

    Main:
    'BtnLed/Read
    INPUT Btn1
    IF Btn1 = 1 THEN GOTO Btn1_Click

    IF Btn1_State = 1 THEN
    HIGH Btn1
    ENDIF

    INPUT Btn2
    IF Btn2 = 1 THEN GOTO Btn2_Click
    IF Btn2_State = 1 THEN
    HIGH Btn2
    ENDIF

    INPUT Btn3
    IF Btn3 = 1 THEN GOTO Btn3_Click
    IF Btn3_State = 1 THEN
    HIGH Btn3
    ENDIF

    INPUT Btn4
    IF Btn4 = 1 THEN GOTO Btn4_Click
    IF Btn4_State = 1 THEN
    HIGH Btn4
    ENDIF

    INPUT Btn5
    IF Btn5 = 1 THEN GOTO Btn5_Click
    IF Btn5_State = 1 THEN
    HIGH Btn5
    ENDIF

    INPUT Btn6
    IF Btn6 = 1 THEN GOTO Btn6_Click
    IF Btn6_State = 1 THEN
    HIGH Btn6
    ENDIF

    INPUT Btn7
    IF Btn7 = 1 THEN GOTO Btn7_Click
    IF Btn7_State = 1 THEN
    HIGH Btn7
    ENDIF

    INPUT Btn8
    IF Btn8 = 1 THEN GOTO Btn8_Click
    IF Btn8_State = 1 THEN
    HIGH Btn8
    ENDIF

    INPUT Btn9
    IF Btn9 = 1 THEN GOTO Btn9_Click
    IF Btn9_State = 1 THEN
    HIGH Btn9
    ENDIF

    INPUT Btn10
    IF Btn10 = 1 THEN GOTO Btn10_Click
    IF Btn10_State = 1 THEN
    HIGH Btn10
    ENDIF

    INPUT Btn11
    IF Btn11 = 1 THEN GOTO Btn11_Click
    IF Btn11_State = 1 THEN
    HIGH Btn11
    ENDIF

    INPUT Btn12
    IF Btn12 = 1 THEN GOTO Btn12_Click
    IF Btn12_State = 1 THEN
    HIGH Btn12
    ENDIF

    INPUT Btn13
    IF Btn13 = 1 THEN GOTO Btn13_Click
    IF Btn13_State = 1 THEN
    HIGH Btn13
    ENDIF

    INPUT Btn14
    IF Btn14 = 1 THEN GOTO Btn14_Click
    IF Btn14_State = 1 THEN
    HIGH Btn14
    ENDIF

    INPUT Btn15
    IF Btn15 = 1 THEN GOTO Btn15_Click
    IF Btn15_State = 1 THEN
    HIGH Btn15
    ENDIF

    INPUT Btn16
    IF Btn16 = 1 THEN GOTO Btn16_Click
    IF Btn16_State = 1 THEN
    HIGH Btn16
    ENDIF

    PAUSE 1

    GOTO Main
    '

    Btn1_Click:
    IF Btn1_State = 1 THEN
    Btn1_State = 0
    Cmd = 010
    ELSE
    Btn1_State = 1
    Cmd = 011
    ENDIF
    GOTO Send
    '

    Btn2_Click:
    IF Btn2_State = 1 THEN
    Btn2_State = 0
    Cmd = 020
    ELSE
    Btn2_State = 1
    Cmd = 021
    ENDIF
    GOTO Send
    '

    Btn3_Click:
    IF Btn3_State = 1 THEN
    Btn3_State = 0
    Cmd = 030
    ELSE
    Btn3_State = 1
    Cmd = 031
    ENDIF
    GOTO Send
    '

    Btn4_Click:
    IF Btn4_State = 1 THEN
    Btn4_State = 0
    Cmd = 040
    ELSE
    Btn4_State = 1
    Cmd = 041
    ENDIF
    GOTO Send
    '

    Btn5_Click:
    IF Btn5_State = 1 THEN
    Btn5_State = 0
    Cmd = 050
    ELSE
    Btn5_State = 1
    Cmd = 051
    ENDIF
    GOTO Send
    '

    Btn6_Click:
    IF Btn6_State = 1 THEN
    Btn6_State = 0
    Cmd = 060
    ELSE
    Btn6_State = 1
    Cmd = 061
    ENDIF
    GOTO Send
    '

    Btn7_Click:
    IF Btn7_State = 1 THEN
    Btn7_State = 0
    Cmd = 070
    ELSE
    Btn7_State = 1
    Cmd = 071
    ENDIF
    GOTO Send
    '

    Btn8_Click:
    IF Btn8_State = 1 THEN
    Btn8_State = 0
    Cmd = 080
    ELSE
    Btn8_State = 1
    Cmd = 081
    ENDIF
    GOTO Send
    '

    Btn9_Click:
    IF Btn9_State = 1 THEN
    Btn9_State = 0
    Cmd = 090
    ELSE
    Btn9_State = 1
    Cmd = 091
    ENDIF
    GOTO Send
    '

    Btn10_Click:
    IF Btn10_State = 1 THEN
    Btn10_State = 0
    Cmd = 100
    ELSE
    Btn10_State = 1
    Cmd = 101
    ENDIF
    GOTO Send
    '

    Btn11_Click:
    IF Btn11_State = 1 THEN
    Btn11_State = 0
    Cmd = 110
    ELSE
    Btn11_State = 1
    Cmd = 111
    ENDIF
    GOTO Send
    '

    Btn12_Click:
    IF Btn12_State = 1 THEN
    Btn12_State = 0
    Cmd = 120
    ELSE
    Btn12_State = 1
    Cmd = 121
    ENDIF
    GOTO Send
    '

    Btn13_Click:
    IF Btn13_State = 1 THEN
    Btn13_State = 0
    Cmd = 130
    ELSE
    Btn13_State = 1
    Cmd = 131
    ENDIF
    GOTO Send
    '

    Btn14_Click:
    IF Btn14_State = 1 THEN
    Btn14_State = 0
    Cmd = 140
    ELSE
    Btn14_State = 1
    Cmd = 141
    ENDIF
    GOTO Send
    '

    Btn15_Click:
    IF Btn15_State = 1 THEN
    Btn15_State = 0
    Cmd = 150
    ELSE
    Btn15_State = 1
    Cmd = 151
    ENDIF
    GOTO Send
    '

    Btn16_Click:
    IF Btn16_State = 1 THEN
    Btn16_State = 0
    Cmd = 160
    ELSE
    Btn16_State = 1
    Cmd = 161
    ENDIF
    GOTO Send
    '


    Send:
    SEROUT Sio, T9600, Cmd
    PAUSE 500
    GOTO Main
    '



    END
  • ZootZoot Posts: 2,226
    edited 2010-11-03 - 17:02:53
    You don't have any subroutines, so it can't be because the jump table is too larger.

    Seems like it should be OK, though I haven't had a chance to check it in the current compiler yet.

    What version of SX/B are you using?
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Alex-MAlex-M Posts: 9
    edited 2010-11-03 - 17:45:27
    I'm using v3.2.3 and v3.3.0 (have 2 computers).

    I looked at other programs that are very large and I can't see any special comands. And they works fine.
  • ZootZoot Posts: 2,226
    edited 2010-11-03 - 18:24:00
    I was asking what version of the SX/B compiler, not the version of the SX-Key software and IDE. You can tell the version number (among other ways) by looking at the top of the output .src file of the final compiled application -- the SX/B compiler version appears at the top (most recent 2.x).
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Dave HeinDave Hein Posts: 5,907
    edited 2010-11-03 - 18:43:25
    I compiled your SX/B code, and I looked at the generated assembly code. I didn't see any problems related to paging. How does the program fail when you use 16 buttons? Maybe it's related to the codes you send out the serial port.

    Are you expecting ASCII codes on the serial port. You are sending numbers larger than 128 for buttons 13 through 16. These numbers have the most significant bit set. What kind of device is at the other end of the serial port?
  • Alex-MAlex-M Posts: 9
    edited 2010-11-04 - 08:42:57
    Sorry, here you go:

    ; *** COMPILED WITH SX/B VERSION 1.51.03 09/21/2006 ***
  • Alex-MAlex-M Posts: 9
    edited 2010-11-04 - 09:08:29
    I hanven't tryed the whole system yet, I only tryed one button (Btn9).
    Every button have an LED. When I press a button it shuld lit up it's own LED. But some times it stucks in on or off state. And it takes a minute or so for the program to start.

    The numbers(Cmd = 141 (Ch14 ON)) are sent to a nother sx28 that controls the rest of the system. Nothing to worry about now.

    Here is a nother code I used to test if i cuold control buttons this way, and it works perfectly fine:

    'Namn


    'Config
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000

    'I/O
    Spkr PIN RA.1
    Btn1 PIN RC.0
    Led1 PIN RC.1

    'Variablar
    i VAR Byte
    Btnspd VAR Byte
    Mode1 VAR Byte
    Btn VAR Byte


    PROGRAM Start
    Start:
    Mode1 = 0


    Main:
    IF Mode1 = 1 THEN
    HIGH Btn1
    ENDIF

    INPUT Btn1

    IF Btn1 = 1 THEN
    GOTO Btn1_Click
    ENDIF

    GOTO Main



    Btn1_Click:
    IF Mode1 = 1 THEN
    Mode1 = 0
    LOW Led1
    ELSE
    Mode1 = 1
    HIGH Led1
    ENDIF

    PAUSE 500
    GOTO Main



    END
  • ZootZoot Posts: 2,226
    edited 2010-11-04 - 11:30:37
    I'm really curious about which version of SX/B you are using -- if memory serves, older versions did not handle automatic program paging as well as SX/B 2.x.
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Alex-MAlex-M Posts: 9
    edited 2010-11-04 - 11:57:39
    This is what's in the .SRC
    ; *** COMPILED WITH SX/B VERSION 1.51.03 09/21/2006 ***

    The softwere I use when i'm programing the SX28 is SX-Key v3.3.0
  • Dave HeinDave Hein Posts: 5,907
    edited 2010-11-04 - 12:07:52
    Zoot wrote: »
    I was asking what version of the SX/B compiler, not the version of the SX-Key software and IDE. You can tell the version number (among other ways) by looking at the top of the output .src file of the final compiled application -- the SX/B compiler version appears at the top (most recent 2.x).
    I downloaded and installed the latest version of the SX-Key software, and it uses SX/B version 1.51.03 dated 9/21/2006. How do you update SX/B to the most recent 2.x version?
  • hover1hover1 Posts: 1,927
    edited 2010-11-04 - 12:18:50
    Dave Hein wrote: »
    I downloaded and installed the latest version of the SX-Key software, and it uses SX/B version 1.51.03 dated 9/21/2006. How do you update SX/B to the most recent 2.x version?

    I found 2.00.31 in the old forums:

    http://forums.parallaxinc.com/forums/default.aspx?f=7&m=323767

    and the new forums:

    http://forums.parallax.com/showthread.php?t=109886

    Jim
    I have three propellers
  • RobotWorkshopRobotWorkshop Posts: 2,300
    edited 2010-11-04 - 14:31:03
    One of the "Sticky" threads (the last one in the list) contains just about all the details on the the latest version of SX/B.

    Robert
  • ZootZoot Posts: 2,226
    edited 2010-11-04 - 17:44:01
    I would try it with the most recent compiler.
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Alex-MAlex-M Posts: 9
    edited 2010-11-05 - 09:43:24
    YES!!!!!!!!!!!

    I think I know what the problem is!
    I only tested 1 chanel (ch9) and I have only one 10k resistor on that chanel I'm testing. The other chanels is not conected to any thing so they don't know if the are 1 or 0. So they act randomly and the program is working with setting the state on all the other chanels instead of setting ch9.(Btn9_State)

    If I conect all buttons maby It works.

    That's my theory.
  • Alex-MAlex-M Posts: 9
    edited 2010-11-07 - 14:12:02
    Just whana say thanks for the help from you guys.

    :)
Sign In or Register to comment.