jump to the wrong page
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.
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.
Comments
Are you calling Move_V from assembly or from SX/B ?
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Move_V is called from SX/B
Instead of :
You should have:
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
·
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
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