In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: Hi All; There is of course another way to deal with ISR timings. Often I need to exit the ISR from various different points, and sometimes it is a calculated exit, and it might not be convenient to have the value loaded in W to restore the RTCC. So, what can be done in those cases, is to write the desired restore value directly into the RTCC as soon as the ISR is entered, and from that point on, the number of steps to an exit is immaterial as the RTCC reload issue has already been dealt with. In doing this, it it importamt to realize that immediately after writing to the RTCC, its value is frozen for 3 (or was it 2?) instructions before it continues counting on subsequent instructions, hence a slight adjustment needs to be made for that. If I recall correctly, for this technique to be used as the first 2 lines in the ISR, I believe the code reads as: INTPERIOD EQU -100 ;for a 100 instruction, 2 uSec tick at 50 MHz ISR MOV W,#INTPERIO+8 ;negative interrupt period plus 8 overhead instruction ticks = -100+8 = -92 MOV RTCC,W ;sets the rtcc for the next interrupt time, and RTCC can now be ignored from this point ...... ; ...... ;any arbitrary code RETI ;exit the ISR without any further regard to the RTCC; do NOT use RETIW If for some reason, this RTCC treatment cannot be at the first 2 lines in the ISR, hence it must be dealt with further doen, then for every INSTUCTION downward, the "overhead" value must be increased by one. Normally I use the standard RETIW approach to exiting ISR, but on occasion, in complicated situations, the technique described here is more convenient. Also, please be aware that if you test this out, single stepping the SX Key in DEBUG mode, you can see the "frozen" RTCC value after it has been written, BUT the displayed value is incorrect by one count. Unfortunately just now I can't recall if it is one high or one low. Just another of the neat tricks you can do with an SX. Cheers, Peter (pjv) ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=84910#m85070 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)