Shop OBEX P1 Docs P2 Docs Learn Events
jump to the wrong page — Parallax Forums

jump to the wrong page

paolopaolo Posts: 17
edited 2008-03-17 17:22 in General Discussion
Hello,

I'm having a very strange problem with the SX48.
I'll try to explain what's happening:

The chip is used to control a disc loading robot with two DC motors, one solenoid and four optical sensors.
The program is written in SXB, and uses a small time-based ISR written in assembler.

Here is the description of the problem:

The program uses a subroutine (MoveToPosition_Y) that moves vertically the loading arm until it reaches certain position.
This subroutine calls the "Move_V" subroutine which gives power to the motor and programs a timer in PWM mode for the speed control.
The problem is that "Move_V"· is never called from the MoveToPosition_Y sub.

Using the debugger, I've inserted a break-point in the·compiler generated code where the jump to the actual address of Move_V is coded.
I've attached a picture that shows the status of the registers as soon as the break-point pops up.
As you can see, the last executed instruction should be "PAGE 800", but the STATUS register does not have the correct value, and points instead to a wrong page.
As a result, the following jump instruction loads the PC with the wrong address.

The strange thing is that if I insert a NOP at any point in the code before calling the Move_V sub, the program works perfectly.

I'm really getting crazy because I cannot find out the cause of this strange behavior.

I'm using the SX-Key ver. 3.2
SASM DLL ver. 1.51.07
SX-B ver. 1.51.03
SXSim ver. 2.08.05

Does anybody have an idea?
I can post the full source code if needed.

Thank you.
827 x 853 - 116K

Comments

  • BeanBean Posts: 8,129
    edited 2008-03-17 11:35
    Please post the source code.

    Are you calling Move_V from assembly or from SX/B ?

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • paolopaolo Posts: 17
    edited 2008-03-17 11:38
    Hi Bean,

    Move_V is called from SX/B
  • paolopaolo Posts: 17
    edited 2008-03-17 11:39
    Here is the source code
  • BeanBean Posts: 8,129
    edited 2008-03-17 12:37
    I don't know if this is what is causing the problem, but you should use "SUB Move_V" and "ENDSUB".
    Instead of :
    Move_V: 'USES: Temp1
     Moveing_V = 1
     if toUp = 1 then
      Down_Move = 0
      Up_Move = 1
     else
      Up_Move = 0
      Down_Move = 1  
     endif
     SetPower 'temp1
     return 
    
    

    You should have:
    SUB Move_V 'USES: Temp1 (note NO colon)
     Moveing_V = 1
     if toUp = 1 then
      Down_Move = 0
      Up_Move = 1
     else
      Up_Move = 0
      Down_Move = 1  
     endif
     SetPower 'temp1
    ENDSUB
     
    

    All of your SUBs and FUNCs should be this way. This let's the compiler understand that this is a subroutine and not just part of the main code.

    Change these and see if that fixes the problem.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • paolopaolo Posts: 17
    edited 2008-03-17 15:00
    Thank you Bean for your suggestion.

    I've changed the code with SUB/FUNC·- ENDSUB/ENDFUNC and·the program·has started to work fine.

    BUT: I've looked at the list and I've found that the new address of the·subroutine·MoveToPosition_Y was 80C, while in the·previous version·of the program the subroutine was located at address 808.
    I've then removed a couple of instructions at the beginning of the program in order to·have this subroutine·located at the same address of the previous not-working version.
    I've tested this new version and... it didn't work!
    The problem is still the same: the PAGE instruction does not seem to correctly set·the page bits in the·status register·before jumping to·the Move_V subroutine.

    Note that Move_V·works fine when called from subroutins others than MoveToPosition_Y.

    I've attached this new version of the program.

    Thank you.
    Paolo
  • paolopaolo Posts: 17
    edited 2008-03-17 17:22
    Hi,
    I've probably found the problem.
    I've changed the frequency from 20Mhz to 50Mhz and the program started to work.
    I suspect there's some noise problem with the layout of the board.

    Thank you for the time you have spent on this issue.

    Paolo
Sign In or Register to comment.