SX Newbie.
Mag748
Posts: 269
I just got my SX Tech tool kit LITE today and I programmed it with·a program I already had written. (It's attached to this post.) It has an ISR that runs when 4 Port B pins change state. I think I wrote the program OK, but it doesn't work at all when running, and when I debug it, the ISR starts without even pressing any of the buttons. Im confused. If anyone has some spare time they would like to spend looking at my program, I would be very greatful.
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
src
15K
Comments
Even though you have the "END" directive at the end of your actual code, I would try removing all the rest of the template code that follows (in other words, get rid of everything after "END") and try again. SASM looks like it is honoring the "END" directive, but see if making this change fixes the problem. Let me know if it fixes the problem or if there is no change.
Thanks, PeterM
Here's my 2 cents worth on a quick read of your program:
In your "initalize" section, you need to determine if the SX is being powered up or waking from sleep.· The pending register is undefined on power-up, so don't use it without clearing it.· Look at the SX Spec. from Ubicom, section 14.
Also, your interrupt routine has no return statement - by jumping out of it, you are filling the stack, but never poping it back off.·This will lead to trouble down the road.
Nate
Anyway, back to the coding...
The ISR's only job is to figure out which button was pressed, and jump to the appropriate routine. How do I do this while having reti's and not "filling the stack, but never poping it back off". I am not sure what that means.
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Freezing:
The freezing has happened to me as well.· Usually I just quit the SX-key application and restart it and all is well.· I do not believe this has anything to do with your program coding.
Stack, pushing and poping:
An interrupt routine is like any other subroutine; you must RETURN from it, or your stack will eventually overflow causing wierd problems.· This, however is not your most pressing problem at this point in time.· This problem will only show up after the interrupt has been called multiple times and the stack overflows.
What you need to work on first:
The most important thing to know, which is not very clearly documented, is:
-When edge detection interrupts are enabled and there· is an edge dectection while SLEEPING,·the·SX starts from the where the RESET directive· of the program points.
-When edge detection interrupts are enabled and there is an edge detection during nornal program running, the SX jumps to $000 to run whatever interrupt routine is there.
In addition, to make things just a little more confusing, when the program starts running from the place where the RESET directive is pointing ("initalize" in your program) it needs to determine if it is starting there because it was woken up (in which case it would check the pending register to see exactly what input woke it up) or if it is starting there because it was powered up (in which case it needs initalize the Pending Register, because·contains just garbage at this point, and then perhaps go to SLEEP.)· To determine if woken up or powering up, check the STATUS register, bit 3 and 4 (See Ubicom Spec. Section 14)
Read The SX-key/Blitz Development System Manual, read the Ubicom Spec., read Exploring the SX Microcontroller with Assembly and BASIC Programming, Unit 7, version 3 (download, Parallax) and let me know if·you still have·questions.
nate
nate
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
did you install the SX-Key IDE from the CD that came with the package? If yes, you better d/l the latest version from the Parallax site. Maybe, the CD contains an older version as the "freezing windows" (with WIN XP) should be fixed in the latest available version.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Guenther: I did install the newest version from the parallax Website, and the problem persists. It’s only annoying, not debilitating though.
Nate: I read all you comments and looked through many virtual stacks of online documentation. I think I may have progress a little. But here is my problem.
·
Before the·SX goes to sleep, the WKPN_B register swap is successful. At least I think, because as far as I am aware, there is no way to watch the actual register. I only saw that placing the W register into a variable resulted in a 0. Now the problem is that after the SX wakes from sleep by a Port B MIWU, the swap fails somehow. The same exact code is used, but this time W equals %1111_1111. This would mean that I pushed every button at the same exact time. I didn't do that. I can't imagine what is happening.
·
I read that the interrupts will not execute while debugging, using step or walk. But while sleeping it did work. So, I don' think that is a problem.
·
Again, the revised code is attached.
·
Thank you very much guys,
Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you very much,
Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sorry it has taken he so long to get back to you, have been busy.· My sugestion would be for you to attempt a simpler version of your program, and then build back up to what you really want.· You will want to make your output routines as simple as possible (LED on/off) as not to possibly add more bugs to the program.
Try your program without using the·SLEEP·feature.· Have main program loop, waiting for an interrupt.· This way you will have a program that powers-up, sets the configuration resgisters as you need them, and then wait for an interrupt.· When that interrupt comes, you know you will be vectored to the $000 location (interrupt while awake, if·interrupt enabled,·will always send you to $000).· All you want to do in the ISR is get·copy of the interupt pending register (and clear it too) then RETURN.
Page 94 of SX-Key/Blitz Development Sytem Manual V2.0 has basic code for this.· After this works for you, try adding features back on again.
nate
Post Edited (Nate) : 1/18/2005 3:31:31 AM GMT