Shop OBEX P1 Docs P2 Docs Learn Events
SX/B compiler error / address 295 is not whithin lower half of memory page? — Parallax Forums

SX/B compiler error / address 295 is not whithin lower half of memory page?

ProfessorwizProfessorwiz Posts: 153
edited 2007-08-29 13:29 in General Discussion
High all, I'm writing one of my first larger programs for the SX, it's not huge but I'm getting this error

Line 238, error 44, pass2: Address 295 is not within lower half of memory page

Here's the program.. Sorry for the poor programming syntex I am working on it.· Any help would be appriciated.· I think one of the first things to do is make a subroutine for the pause command.· Other than that?

Russ

' =========================================================================
'
'·· File...... PhotoTimer
'·· Purpose... Help take time lapse photos
'·· Author....· Russell Wizinsky
'·· E-mail....· russw@professorwiz.com
'·· Started...· 4/16/07 for the Basic stamp
'·revision..· 8/20/07 for the Parallax SX Chip
'·· Updated...· 8/26/07

' =========================================================================

'
' Program Description
'
' Program will close shutter switch at set timed intervals.·
' One button will adjust the timing,
' timing will be shown as a number 0-9 on the 7 segment display
' When start button is depressed camera will start taking photos
' When start button is depressed again.· Camera will stop and
' 7 segment display will flash out count of how many pictures it took
' until the adjust button is pressed again.
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000

'
' IO Pins
'
'RC Pins for Output for 7 Segment Display
'RB0 Pin for Pushbutton for start
'RB1 Change timing of shutter
'RB2 Output for Test LED
'RB3 Solid state Cmos switch
Segments··PIN·RC··output·'7 Segment display
StartButton··PIN·RB.0·INPUT·'PushButton Switch
TimeButton··Pin·RB.1·Input·'PushButton Switch
Shutter···Pin·RB.2·output·'Output to Cmos switch
'
' Constants
'
ISPRESSED ··CON·1·'FOR ACTIVE-HIGH INPUT
ISNOTPRESSED·CON·0
ISOpen···Con 1·'Shutter is opened
IsClosed··Con·0·'Shutter is closed
'
' Variables
'
idx····VAR······ BYTE·' Index for Data of 7 Segment display
counter··· ··VAR··············· Word ' timing variable
time····· ··VAR··············· Word ' variable for rc time
del1····· ··VAR··············· Word ' Delay Variable
pics······ ··VAR··············· Word ' Number of pictures taken
' =========================================================================
· PROGRAM Start
' =========================================================================

'
'··········· PROGRAM CODE
'
Start:
'gosub DisplayTiming
·Do
··read dig_map + counter, segments
··If TimeButton = ispressed then
···do
···loop until TimeButton = isnotpressed
···Inc counter
···If counter = 10 then
····counter = 0
···Endif
···Pause 250
··EndIf
·loop until· StartButton = ispressed
·Do
·loop until StartButton = isnotpressed·'Don't start until button is released
·gosub calctime·······'Calculate time between pictures
·gosub takepics·······'Trigger the shutter at calcuated time
·gosub dispcount·······'Display how many pictures where taken

Pause 1000
goto start


'
'··········· SUBROUTINES
'
····························
calctime:······················· 'Caclulate time between frames selected by pushbutton
··· IF counter = 0 THEN
·del1 = 1····· 'Time interval 1 sec
··· ENDIF
·IF counter = 1 THEN
·del1 = 2····· 'Time interval 2 sec
··· ENDIF
·IF counter = 2 THEN
·del1 = 3····· 'Time interval 3 sec
·ENDIF···
·IF counter = 3 THEN
·del1 = 5····· 'Time interval 5 sec
·ENDIF···
·IF counter = 4 THEN
·del1 = 10···· 'Time interval 10 sec
··· ENDIF
·IF counter = 5 THEN
·del1 = 20···· 'Time interval 20 sec
·ENDIF
··· IF counter = 6 THEN
·del1 = 30···· 'Time interval 30 sec
·ENDIF
··· IF counter = 7 THEN
·del1 = 50···· 'Time interval 50 sec
·ENDIF
··· IF counter = 8 THEN
·del1 = 100··· 'Time interval 100 sec
·ENDIF
··· IF counter = 9 THEN
·del1 = 120··· 'Time interval 120 sec
·ENDIF
RETURN
TakePics:········'Trigger the shutter at calcuated time
Do
Shutter = ISOpen
pause 50
Shutter = ISClosed
pause del1

loop until· StartButton = ispressed
RETURN
DispCount:········'Display how many pictures where taken
RETURN

'
' end of form

'
'data
'
DIG_MAP:
··'· BAFG.CDE
·DATA ·%11100111·'0
·DATA·%10000100·'1
·DATA·%11010011·'2
·DATA·%11010110·'3
·DATA·%10110100·'4
·DATA·%01110110·'5
·DATA·%01110111·'6
·DATA·%11000100·'7
·DATA·%11110111·'8
·DATA·%11110110·'9

Comments

  • PJMontyPJMonty Posts: 983
    edited 2007-08-28 00:55
    Russ,

    Check out this link:

    http://forums.parallax.com/showthread.php?p=594708

    It's a thread on this forum that explains the problem you're having. Also, check out the sticky at the top of this forum titled Best SX Threads index ....updated 7-11-07. Lots of good info there, including the answer to your problem.

    Thanks,
    PeterM
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-08-28 01:00
    If you declare your subroutines first SX/B will take care of the boundaries for you. I expect this will quickly solve your problem! Consult the help file under Reference | Definitions | Subroutine Declaration for further information.

    Note that toward the end of that help section you find this statement, “Subroutines do not have to be declared, but doing so allows the subroutine code to be placed anywhere in the listing (without declaration the code must be in the first half of a code page)”.

    - Sparks
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-28 01:20
    Thanks for the quick replies, after using the delay in the Practical SX/B it removed that error and added another.· I will work thought the program and properly declare my subs.

    I added the delay used in page 95, I declared it as a sub.· Declared the tmpW1 as a word variable, and it's giving me a INVALID PARAMETER "_PARAMCNT".·


    'USE:· DELAY_MS ms
    '-- 'ms' is delay in milliseconds, 1 - 65535

    SUB DELAY_MS
    ·if _PARAMCNT = 1 then
    ··tmpW1 = _PARAM1
    ·else
    ··tmpW1 = _WPARAM12
    ·endif
    ·pause tmpW1
    ·ENDSUB
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-28 01:26
    PJMonty
    I looked though the thread you had pointed me to and I couldn't see where the problem came up except when someone was using interupts. I'm not using any of those. I did scan though the best of and just didn't see anything that pointed me to that problem.
    Russ
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-08-28 01:39
    Russ,

    The special aliases such as “__PARAMCNT” start with TWO underscore characters. Some fonts make this particularly difficult to observe.

    - Sparks
  • PJMontyPJMonty Posts: 983
    edited 2007-08-28 01:44
    Russ,

    It's there, but it's not the most obvious thing to find. Look for the group called "SX error messages and quirks."

    Then look for the topic called "SX-B code page-Addresses ...."

    BTW, the first link I provided is the direct link to "SX-B code page-Addresses ...."

    Thanks,
    PeterM
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-28 11:35
    Thanks for the help!· I've gotten past those errors, and have declared all the subs.· Another bug seems to have snuk in though, as it's giving me a Endif without an if in the main subroutine.· This worked fine before, and I don't see where I have an extra endif.

    Here's the updated code.

    ' =========================================================================
    '
    '·· File...... PhotoTimer
    '·· Purpose... Help take time lapse photos
    '·· Author....· Russell Wizinsky
    '·· E-mail....· russw@professorwiz.com
    '·· Started...· 4/16/07 for the Basic stamp
    '·· revision..· 8/20/07 for the Parallax SX Chip
    '·· Updated...· 8/28/07

    ' =========================================================================

    '
    ' Program Description
    '
    ' Program will close shutter switch at set timed intervals.·
    ' One button will adjust the timing,
    ' timing will be shown as a number 0-9 on the 7 segment display
    ' When start button is depressed camera will start taking photos
    ' When start button is depressed again.· Camera will stop and
    ' 7 segment display will flash out count of how many pictures it took
    ' until the adjust button is pressed again.
    '
    ' Device Settings
    '
    DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ··········· 4_000_000

    '
    ' IO Pins
    '
    'RC Pins for Output for 7 Segment Display
    'RB0 Pin for Pushbutton for start
    'RB1 Change timing of shutter
    'RB2 Output for Test LED
    'RB3 Solid state Cmos switch
    Segments··PIN·RC·output·'7 Segment display
    StartButton··PIN·RB.0·INPUT·'PushButton Switch
    TimeButton··PIN·RB.1·Input·'PushButton Switch
    testled···PIN·RB.2·output·'Test LED
    Shutter···PIN·RB.3·output·'Output to Cmos switch
    '
    ' Constants
    '
    ISPRESSED ··CON·1·'FOR ACTIVE-HIGH INPUT
    ISNOTPRESSED·CON·0
    ISOpen···Con 1·'Shutter is opened
    IsClosed··Con·0·'Shutter is closed
    '
    ' Variables
    '
    idx····VAR······ BYTE·' Index for Data of 7 Segment display
    counter··· ··VAR··············· Word ' timing variable
    time····· ··VAR··············· Word ' variable for rc time
    del1····· ··VAR··············· Word ' Delay Variable
    pics······ ··VAR··············· Word ' Number of pictures taken
    tmpW1···VAR······ Word ' Delay in MS
    '
    '· Subroutines DECLARATIONS
    '
    DELAY_MS··SUB···1,2
    TakePics··SUB···0
    Dispcount··SUB···0
    calctime··SUB···0
    '
    '· Subroutines
    '
    'USE:· DELAY_MS ms
    '-- 'ms' is delay in milliseconds, 1 - 65535
    SUB DELAY_MS
    ·if __PARAMCNT = 1 then
    ··tmpW1 = __PARAM1
    ·else
    ··tmpW1 = __WPARAM12
    ·endif
    ·pause tmpW1
    ·ENDSUB
    '
    SUB DispCount········'Display how many pictures where taken
    ENDSUB
    '
    SUB calctime··············
    ··· IF counter = 0 THEN
    ·del1 = 1····· 'Time interval 1 sec
    ··· ENDIF
    ·IF counter = 1 THEN
    ·del1 = 2····· 'Time interval 2 sec
    ··· ENDIF
    ·IF counter = 2 THEN
    ·del1 = 3····· 'Time interval 3 sec
    ·ENDIF···
    ·IF counter = 3 THEN
    ·del1 = 5····· 'Time interval 5 sec
    ·ENDIF···
    ·IF counter = 4 THEN
    ·del1 = 10···· 'Time interval 10 sec
    ··· ENDIF
    ·IF counter = 5 THEN
    ·del1 = 20···· 'Time interval 20 sec
    ·ENDIF
    ··· IF counter = 6 THEN
    ·del1 = 30···· 'Time interval 30 sec
    ·ENDIF
    ··· IF counter = 7 THEN
    ·del1 = 50···· 'Time interval 50 sec
    ·ENDIF
    ··· IF counter = 8 THEN
    ·del1 = 100··· 'Time interval 100 sec
    ·ENDIF
    ··· IF counter = 9 THEN
    ·del1 = 120··· 'Time interval 120 sec
    ·ENDIF
    ENDSUB
    '
    SUB TakePics········'Trigger the shutter at calcuated time
    Do
    Shutter = ISOpen
    DELAY_MS 50
    Shutter = ISClosed
    DELAY_MS del1
    loop until· StartButton = ispressed
    ENDSUB
    ' =========================================================================
    · PROGRAM Start
    ' =========================================================================

    '
    '··········· PROGRAM CODE
    '
    Start:
    'gosub DisplayTiming
    ·Do
    ··read dig_map + counter, segments
    ··If TimeButton = ispressed then
    ···do
    ···loop until TimeButton = isnotpressed
    ···Inc counter
    ···If counter = 10 then
    ····counter = 0
    ···Endif
    ···DELAY_MS 250
    ··EndIf
    ·loop until· StartButton = ispressed
    ·Do
    ·loop until StartButton = isnotpressed·'Don't start until button is released
    ·gosub calctime·······'Calculate time between pictures
    ·gosub takepics·······'Trigger the shutter at calcuated time
    ·gosub dispcount·······'Display how many pictures where taken

    DELAY_MS 1000
    goto start


    '
    'data
    '
    DIG_MAP:
    ··'· BAFG.CDE
    ·DATA ·%11100111·'0
    ·DATA·%10000100·'1
    ·DATA·%11010011·'2
    ·DATA·%11010110·'3
    ·DATA·%10110100·'4
    ·DATA·%01110110·'5
    ·DATA·%01110111·'6
    ·DATA·%11000100·'7
    ·DATA·%11110111·'8
    ·DATA·%11110110·'9
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-28 12:06
    One, update,
    If I comment out the lines with the nested if then statement it compiles fine.?!

    Start:

    'DisplayTiming + change timing
    Do
    read dig_map + counter, segments
    If TimeButton = ispressed then
    do
    loop until TimeButton = isnotpressed
    Inc counter
    'If counter = 10 then
    ' counter = 0
    'ENDIF
    DELAY_MS 250
    EndIf
    loop until StartButton = ispressed
    Do
    loop until StartButton = isnotpressed 'Don't start until button is released
    gosub calctime 'Calculate time between pictures
    gosub takepics 'Trigger the shutter at calcuated time
    gosub dispcount 'Display how many pictures where taken


    DELAY_MS 1000
    goto start
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-28 13:14
    Last update, for a while anyways, rebooted and endif problem went away. Weird..
    Russ
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-28 14:14
    You might consider converting your CalcTime subroutine to a function so that you can pass it a value and have it return a value.

    FUNC CALC_TIME
      tmpB1 = __PARAM1
      LOOKUP tmpB1, 1, 2, 3, 5, 10, 20, 30, 50, 100, 120, tmpB1
      RETURN tmpB1
      ENDFUNC
    


    You could also use READ instead of LOOKUP if you wanted to have a bigger table of time values.

    In use, you'd do this:

    counter = CALC_TIME del1
    


    For the greatest code re-use you'll want to avoid using global variables in your subroutines and functions -- instead, pass values back and forth as parameters.
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-29 01:08
    JohnnyMac,

    I added the lines in, and it's giving me an invalid number of parameters on the line that calls it up. It makes good sense to make reusable code, and I knew there had to be a cleverer way to do what I was doing.· Thanks for the tip, and any help you can give me what I did wrong.



    Here's the main loop

    'DisplayTiming + change timing
    ·Do
    ··read dig_map + counter, segments
    ··If TimeButton = ispressed then
    ···do
    ···loop until TimeButton = isnotpressed
    ···Inc counter
    ···IF counter = 10 then
    ····counter = 0
    ····DELAY_MS 1
    ···ENDIF
    ···DELAY_MS 250
    ··EndIf
    ·loop until· StartButton = ispressed
    ·Do
    ·loop until StartButton = isnotpressed·'Don't start until button is released
    ·counter = CALC_TIME·del1····'Calculate time between pictures
    ·takepics·······'Trigger the shutter at calcuated time
    ·dispcount·······'Display how many pictures where taken



    DELAY_MS 1000
    goto start




    Here's the Function section:

    '
    '· FUNCTIONS
    '

    FUNC CALC_TIME
    ·TMPB1 = __PARAM1
    ·LOOKUP TMPB1, 1, 2, 3, 5, 10, 20, 30, 50, 100, 120, TMPB1
    ·RETURN TMPB1
    ·ENDFUNC
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-29 01:41
    During my morning coffee I re-crafted your program -- or what I think you want -- as an exercise. Have a look. It uses the decimal point on the display to indicate 10s when the picture count exceeds nine. The only thing I moved to a subroutine is the DELAY_MS because delays are required in several locations.
  • ProfessorwizProfessorwiz Posts: 153
    edited 2007-08-29 10:41
    Wow, very neat.· I appriciate the bit of a different approach.· I was trying perhaps too hard to make everything into a subroutine, and make everything reusable.

    In this line

    ······· READ Dig_Map + idx, Segments
    ······· Segments.3 = 1

    I assume that the Segments.3 would change the digit for the dot which would be the 3rd one over in Binary correct?· Sorry for a simple question, still learning.

    Russ
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-29 13:29
    That line should -- based on you DATA table for the digits -- activate the decimal point LED on your display. Segments.3 is the same thing a RC.3
Sign In or Register to comment.