When exactly does the Interrupt routine start running in an SX/B program.
![RobotWorkshop](https://forums.parallax.com/uploads/userpics/915/nCTRZ4MIBWKDB.jpg)
I don't recall seeing this question come up before but when exactly does the Interrupt routine as defined in an SX/B program really start executing? Does it wait until after the housekeeping stuff is done like configuring the I/O ports, etc or does it fire up right away?
Suppose you want to hold off starting up the ISR routine for a little bit when your program starts. Would it be best to just set a flag in the ISR, let it run, and use that to tell the ISR to do its job? Or, would you want to disable the interrupts until you are ready for them.
One case in particular is when using a program on the SX chip with a background UART in the ISR. If it is connected to another device which is powered at the same time and the device may misbehave by sending junk as it starts then it would be reasonable to put in a delay or otherwise tell the background serial code to ignore anything on the line for a second or so after power is applied.
This is one issue I just ran across when using an SX48 for a new project. I wired up a display to show any data sent to it on the serial line. I noticed a couple garbage characters on power up and if I can add a delay before the ISR starts that should fix that issue.
Best Regards,
Robert
Suppose you want to hold off starting up the ISR routine for a little bit when your program starts. Would it be best to just set a flag in the ISR, let it run, and use that to tell the ISR to do its job? Or, would you want to disable the interrupts until you are ready for them.
One case in particular is when using a program on the SX chip with a background UART in the ISR. If it is connected to another device which is powered at the same time and the device may misbehave by sending junk as it starts then it would be reasonable to put in a delay or otherwise tell the background serial code to ignore anything on the line for a second or so after power is applied.
This is one issue I just ran across when using an SX48 for a new project. I wired up a display to show any data sent to it on the serial line. I noticed a couple garbage characters on power up and if I can add a delay before the ISR starts that should fix that issue.
Best Regards,
Robert
Comments
For your situation, I would make the pin an INPUT, then after you get the variables setup make it an OUTPUT.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Start:
AIO = %00000111 ' Setup port A
BIO = %10000111 ' Setup port B
' Setup variables to initial values
Main:
' Main program code here....
Goto Main
Would the ISR start as soon as it hits the start of the program or wait until it gets to the main portion of the program? I'm still not 100% clear at what point the ISR is enabled when the chip is powered up.
The pin in question is already an input to start with. The issue is that the SX48 seems to receive some garbage from the other end when everything starts up. I think that if I can tell it to hold off looking at the pin after a reset or power up that should fix it.
Robert
Then of course, it is presumed that the RTCC itself will have some kind of -W value written to it at the end of the ISR so that the next iteration is run when it is supposed to.
In SX/B, the startup code automatically sets the options reg. properly, calculates prescaler and RETIW (thank you, Bean!), so unless your program is pure assembly, you can't get control over WHEN this happens at reset or after a powerdown. If you look at the list file from an SX/B program you'll see it in the assembly in the startup code, in the order Bean mentions.
Using NOSTARTUP leaves file registers and such in their startup state, but will *still* set up the ports and options, btw.
(Bean, correct me if I'm wrong on any of this...)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
For the moment I may just use a flag that the ISR routine can check right upon entry to see if it is suppose to be active. After a slight delay in the main body of the program I can just toggle on that flag so that the ISR routine can just fall through and run normally.
Only a few more issues to shake out and another old robot will be working again...
Best Regards,
Robert
There's a tradeoff there, for sure -- I use a lot of ASM in my SX/B programs, but I like having SX/B as the overall framework -- highly convenient esp. for the mainline program. IMO, SX/B generates *really* nice and efficient code for something that is "auto-generated" assembly (Bean is the man!).
But if a program is taken out of the SX/B environment, you can generally make things *very* compact, gain a bit more control over subtler features, AND claim back global variable space used by the PARAM vars defined in SX/B. I guess it's always question of what the needs of the project are.
Bean -- how difficult would it be to extend the NOSTARTUP directive to allow for setting/not-setting vars, AND/OR setting/not-setting options, AND/OR setting/not-setting ports and such? Rather than ports/options always being setup and vars being the optional aspect?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·