#ifndef _int_h_ #define _int_h_ #include #include #include #include #include #include #include #include "global.h" #include "util.h" #include "astro.h" /* TIMER-interrupt --------------- prescale 16, = 1,25 Mhz = 800ns, downward count 125 * 0.8us = 100 us = 0,1 ms 65536 - 125 = 65411 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 T3CON = 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 off 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 on | |_ t3otl high at startup T4CON = 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 reload for t3 any signal of t3otl T3 = TIMERRELOAD T4 = TIMERRELOAD IR IE ILVL GLVL T3IC = 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 off 0xa7 167 T3IC = 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 on 0xe7 231 (int vector 0x8C, trap 0x23, group(3), level(9) ) ENCODER-interrupts ------------------ ENCODER 2 ( VE ) CC11IC = 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 off 0xab 171 CC11IC = 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 on 0xeb 235 ( P2.11 int vector 0x6C, trap 0x1B, group(3), level(10) ) CC10IC = 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 off 0xaf 175 CC10IC = 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 on 0xef 239 ( P2.10 int vector 0x68, trap 0x1A, group(3), level(11) ) ENCODER 1 ( HO ) CC9IC = 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 off 0xb3 179 CC9IC = 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 on 0xf3 243 ( P2.9 int vector 0x64, trap 0x19, group(3), level(12) ) CC8IC = 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 1 off 0xb7 183 CC8IC = 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 on 0xf7 247 ( P2.8 int vector 0x60, trap 0x18, group(3), level(13) ) FOR FAST 50 ns sampling for encoders we use EXICON EXICON = 0x0055 int on positive edge P2.8/P2.9/P2.10/P2.11 EXICON = 0x00aa int on negative edge P2.8/P2.9/P2.10/P2.11 EXICON = 0x00ff int on both edges P2.8/P2.9/P2.10/P2.11 **** */ #define TIMERRELOAD 65411 #define TIMERSTOP 1025 #define TIMERSTART 1089 #define TIMERSET 39 #define TIMERINTOFF 167 #define TIMERINTON 231 #define ENC2_1INTOFF 171 #define ENC2_1INTON 235 #define ENC2_0INTOFF 175 #define ENC2_0INTON 239 #define ENC1_1INTOFF 179 #define ENC1_1INTON 243 #define ENC1_0INTOFF 183 #define ENC1_0INTON 247 extern void initTimerInt( void ); extern void startTimerInt( void ); extern void stopTimerInt( void ); extern void initEncoderInts( void ); extern void startEncoderIntsHo( void ); extern void startEncoderIntsVe( void ); extern void stopEncoderInts( void ); extern unsigned char bdata ENC_FLAGS; /* usage of encoders can be switched on/off*/ extern bit ENCHO_USE; extern bit ENCVE_USE; /*idflag for correction from encodervalues for timerint*/ extern bit ENCHO_COR; extern bit ENCVE_COR; /*current direction set automatically by encoderinterrupts*/ /* 0 = RIGHT 1 = LEFT*/ extern bit ENCHO_DIR; /* 0 = UP 1 = DOWN*/ extern bit ENCVE_DIR; /*decides if timerint reacts for ENCHO/VE_COR*/ extern bit ENCHO_CORUSE; extern bit ENCVE_CORUSE; extern unsigned char bdata MOT_FLAGS; extern bit MOTHO_RUN; extern bit MOTVE_RUN; extern bit MOTFR_USE; extern bit MOTHO_DIR; extern bit MOTVE_DIR; extern bit MOTFR_DIR; extern bit MOT_GOTO; extern bit MOT_CORRECTION; /* generally timevariables, used by timer-int, rtc, and for calculation of current startime. */ extern volatile int idata YEAR; extern volatile int idata MONTH; extern volatile int idata DAY; extern volatile int idata HOUR; extern volatile int idata MINUTE; extern volatile int idata SECOND; extern volatile int idata MSECOND; extern volatile int idata TIMER10; extern volatile int idata THISMDAYS; /* numbers of steps per 360 degrees ( 4000, 8000 ....) (default 4000)*/ extern volatile int idata CFG_ENC_HO; extern volatile int idata CFG_ENC_VE; extern volatile int idata ARC10PERENCHO; extern volatile int idata ARC10PERENCVE; /* these are the current pos. of encoders in 1/10 of arcseconds. */ extern volatile long idata ENC_ARC10_HO; extern volatile long idata ENC_ARC10_VE; /* will be calculated from config */ extern volatile long idata HSTEPSHO090; extern volatile long idata HSTEPSHO180; extern volatile long idata HSTEPSHO270; extern volatile long idata HSTEPSHO359; /* these are the real used halfstepkoordinates. */ extern volatile long idata CUR_HSTEPS_HO; extern volatile long idata CUR_HSTEPS_VE; /* The calculated object where to go to ( goto / guiding ) */ extern volatile long idata TRG_HSTEPS_HO; extern volatile long idata TRG_HSTEPS_VE; /* temp. values for quick convertion. */ extern volatile long idata CUR_ARC10_HO; extern volatile long idata CUR_ARC10_VE; extern volatile int idata SPEED_HO; extern volatile int idata SPEED_VE; extern volatile int idata SPEED_FR; extern volatile int idata SPEED_HO_CT; extern volatile int idata SPEED_VE_CT; extern volatile int idata SPEED_FR_CT; extern volatile unsigned char idata hsteps[8]; extern volatile int idata HSTEP_HO; extern volatile int idata HSTEP_VE; extern volatile int idata HSTEP_FR; /* size of arcseconds ( X.XXXXXX ) per halfstep */ extern volatile double idata CFG_HSTS_HO; extern volatile double idata CFG_HSTS_VE; extern volatile double idata CFG_HSTS_FR; /* CALCULATION OF TIMINGG ENCODERS ----------------------------------------------------------- 3760 ns ( 3.8 us ) longest possible usage for an encoderint ----------------------------------------------------------- * 4000 = 15040,000 us = 15.0400 ms = 1.504 % CPU TIME = 150.4 % of 1/10000 sec. absolutely worst case,- 360 manual-move in 1 sec. This is not relevant, because for this motors are off, and no calculation is needed. If the scope moved 360. in min. 2 sec, there is enough place for the timerint For a very nervous guy, a move of max 180 degrees in 1 second can be point as worst case. Normally scope should be moved carefully for max. 90 degrees in 1 second. = 50,133 us = 0.0502 ms = 0.00502 % CPU TIME ( ok, no problem ) goto 360 in 5 minutes, - good worst case for goto = 0.174074 us = 0.000174074 ms = 0.0000174 % CPU TIME ( ok, no problem ) guiding, - the place were heavy calcualtions are needed. TIMERINT abs. min usage: 10 * ~160 ns ( only increasing timer10 ) = 1600 ns = 1.6 us abs. max. usage, whithout using of motors ( only time setting, 31.12 00:00:00, till change of year ) 46 * ~160 ns = ~7360 ns = 7.36 us ( this can only happen 1 time per year ). We avoid a absolutely ( not possible ) worst case, which means, that the additional steering of motors can use 10000 times per second up to 200 opcodes. 200 * ~160ns = 32000 ns = 32 us. 32 + ~3us( average timer) = 35us * 10000 = 350000us = 350ms = 0.35 sec. = 35% CPUTIME (Toghether with encoderints, and a ( uuuuhh ) move of 360 degrees in one second, this can be up to 37 % CPUTIME. ) This is for very fast goto on its absolutely worst case. Now, the same for guiding For this we avoid a max. possible precision of 1 halfstep for 1/10 arcseconds. ( More makes no sense, because the complete calculation depends on 1/10 arcseconds ). This avoids a max. frequence of 150 halfsteps per second. 150 times per second up to 200 opcodes. 200 * ~160ns = 32000 ns, 32us * 150 = 4800us = 4,8 ms ~3us(average timer) * 10000 = 30000us = 30 ms 30 + 4,8 = 34,8 ms = 0.0348 sec. = 3.48 % CPU TIME (the encodertimes during guiding are not relevant for this, because there are only all 21.6 seconds one encoderint with 3.8 us ). There are 96.52% CPU TIME for calculations: This must be min. 30 times per sec. Possibility 1: Practical the calculation of current startime, and the convertion of RA/DEC to ALT/AZ can be handled >32 times per second. 32 = 100% - 3.48% = 30.8864 times per second the calculations are possible ( ok, no problem ) ( Because we have 5% place for all stuff outside the calculations, we can calculate a timerint which uses up to 400 add. opcodes per motorhandling ). Possibility 2: Startime will be calculated once a time before guiding starts. The startime will be increased with every timerint, and only the convertion RA/DEC to AZ/ALT will be done. This convertion alone can be praktically handled 72 times per second. So 72 = 100% - 3.48% = 69.49 times per second the calculation is possible. ( But for this we must sub an amount of time for the additional increasing of startime by the timerint ). With this we can avoid that a calculation of more then 60 times per second is possible. Currently a last end precision of 1/2 arcseonds is enough for us, so we are lucky with the 30 times per second, and using possibility 1. Later we can increase the precision to 1/4 arcseconds, using possibility 2. The last end target, is the using of the new keil-mathroutines, which can practically handle the calculation of startime, and convertion of RA/DEC to ALT/AZ more then 60 times per second, and using possibility 2 a convertion of RA/DEC to ALT/AZ more then 100 times per second. So we have good chances to reach the real precision of 1/10 arcseconds, which is provided by all other parts of the software. ( using a 40 Mhz CPU also makes this possible ). ENCODERINT BREAKS TIMERINT Now the calculation, because this ints have more priority, then the timerint, and will be happened at time, normally the time-int must be done. We test if these ints, are short enough, that the timer int do not blocked, and lose one, or more 1/10000 second steps. timerints are happen 10000 per second. In worst case encoderints can happen 4000 per second. Used max. time for encoderint 3.8 us. = 0.0000038 second. Place for timerint = 0.0001 second. -> There is place for 26.3 encoderints in one timerint Because we avoid timerint uses max. 35us, we use 0.0001 / ( 0.0000038 + 0.000035 ) = 2.5773196 ok, no problem */ /* #define HSTEP1 14 #define HSTEP2 10 #define HSTEP3 11 #define HSTEP4 9 #define HSTEP5 13 #define HSTEP6 5 #define HSTEP7 7 #define HSTEP8 6 */ #define HSTEP1 238 #define HSTEP2 170 #define HSTEP3 187 #define HSTEP4 153 #define HSTEP5 221 #define HSTEP6 85 #define HSTEP7 119 #define HSTEP8 102 /* bin: -- all signals are low-active --- this means a 0 is on, a 1 is off. bit 0, and bit 2 are the first winding bit 1, and bit 3 the second. ( bit 3,2,1,0 for az, and fr, bit 7,6,5,4 for alt ). hstep 1 1110 ( full w1 ) hstep 2 1010 ( half w1,w1 ) hstep 3 1011 ( full w2 ) hstep 4 1001 ( half w1,w2 ) hstep 5 1101 ( full w2 ) hstep 6 0101 ( half w2,w2 ) hstep 7 0111 ( full w2 ) hstep 8 0110 ( half w2,w1 ) */ #endif