forked from hjd1964/OnStep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialize.ino
552 lines (477 loc) · 17.7 KB
/
Initialize.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
// -----------------------------------------------------------------------------------
// Functions for initializing pins, variables, and timers on startup
void Init_Startup_Values() {
// initialize some fixed-point values
amountGuideAxis1.fixed=0;
amountGuideAxis2.fixed=0;
guideAxis1.fixed=0;
guideAxis2.fixed=0;
accPecGuideHA.fixed=0;
fstepAxis1.fixed=0;
fstepAxis2.fixed=0;
origTargetAxis1.fixed = 0;
cli();
targetAxis1.part.m = 90L*(long)StepsPerDegreeAxis1; targetAxis1.part.f = 0;
posAxis1 = 90L*(long)StepsPerDegreeAxis1;
trueAxis1 = 90L*(long)StepsPerDegreeAxis1;
targetAxis2.part.m = 90L*(long)StepsPerDegreeAxis2; targetAxis2.part.f = 0;
posAxis2 = 90L*(long)StepsPerDegreeAxis2;
trueAxis2 = 90L*(long)StepsPerDegreeAxis2;
sei();
// default values for state variables
pierSide = PierSideNone;
dirAxis1 = 1;
dirAxis2 = 1;
defaultDirAxis2 = defaultDirAxis2EInit;
if (latitude>0) defaultDirAxis1 = defaultDirAxis1NCPInit; else defaultDirAxis1 = defaultDirAxis1SCPInit;
newTargetRA = 0;
newTargetDec = 0;
newTargetAlt = 0;
newTargetAzm = 0;
origTargetAxis1.fixed = 0;
origTargetAxis2 = 0;
// initialize alignment
alignNumStars = 0;
alignThisStar = 0;
indexAxis1 = 0;
indexAxis1Steps = 0;
indexAxis2 = 0;
indexAxis2Steps = 0;
#ifdef MOUNT_TYPE_ALTAZM
Align.init();
#endif
GeoAlign.init();
// reset meridian flip control
#ifdef MOUNT_TYPE_GEM
meridianFlip = MeridianFlipAlways;
#endif
#ifdef MOUNT_TYPE_FORK
meridianFlip = MeridianFlipAlign;
#endif
#ifdef MOUNT_TYPE_FORK_ALT
meridianFlip = MeridianFlipNever;
#endif
#ifdef MOUNT_TYPE_ALTAZM
meridianFlip = MeridianFlipNever;
#endif
// where we are
homeMount = false;
atHome = true;
lastError = ERR_NONE;
// reset tracking and rates
cli();
trackingState = TrackingNone;
lastTrackingState = TrackingNone;
timerRateAxis1 = SiderealRate;
timerRateAxis2 = SiderealRate;
sei();
}
void Init_Pins() {
#ifdef ESP8266_CONTROL_ON
pinMode(Axis1_Aux,OUTPUT); // ESP8266 GPIO0
digitalWrite(Axis1_Aux,HIGH); delay(20); // Run mode
pinMode(Axis2_Aux,OUTPUT); // ESP8266 RST
digitalWrite(Axis2_Aux,LOW); delay(200); // Reset, if LOW
digitalWrite(Axis2_Aux,HIGH); // Reset, inactive HIGH
#endif
// initialize the stepper control pins Axis1 and Axis2
pinMode(Axis1StepPin,OUTPUT);
pinMode(Axis1DirPin,OUTPUT);
#ifdef Axis2GndPin
pinMode(Axis2GndPin,OUTPUT);
digitalWrite(Axis2GndPin,LOW);
#endif
pinMode(Axis2StepPin,OUTPUT);
pinMode(Axis2DirPin,OUTPUT);
// override any status LED and set the reset pin HIGH
#if defined(W5100_ON) && defined(__ARM_Teensy3__)
#ifdef STATUS_LED_PINS_ON
#undef STATUS_LED_PINS_ON
#endif
#ifdef STATUS_LED_PINS
#undef STATUS_LED_PINS
#endif
pinMode(RstPin,OUTPUT);
digitalWrite(RstPin,LOW);
delay(500);
digitalWrite(RstPin,HIGH);
#endif
// light status LED (provides GND)
#ifdef STATUS_LED_PINS_ON
pinMode(LEDnegPin,OUTPUT);
digitalWrite(LEDnegPin,LOW);
// sometimes +5v is provided on a pin
#ifdef LEDposPin
pinMode(LEDposPin,OUTPUT);
digitalWrite(LEDposPin,HIGH);
#endif
LED_ON=true;
#endif
// light status LED (provides pwm'd GND for polar reticule)
#ifdef STATUS_LED_PINS
pinMode(LEDnegPin,OUTPUT);
digitalWrite(LEDnegPin,LOW);
// sometimes +5v is provided on a pin
#ifdef LEDposPin
pinMode(LEDposPin,OUTPUT);
digitalWrite(LEDposPin,HIGH);
#endif
analogWrite(LEDnegPin,STATUS_LED_PINS);
LED_ON=true;
#endif
// light reticule LED
#ifdef RETICULE_LED_PINS
#if defined(__ARM_Teensy3__) && !defined(ALTERNATE_PINMAP_ON)
#ifdef STATUS_LED_PINS_ON
#undef STATUS_LED_PINS_ON
#endif
#ifdef STATUS_LED_PINS
#undef STATUS_LED_PINS
#endif
#endif
pinMode(ReticulePin,OUTPUT);
analogWrite(ReticulePin,reticuleBrightness);
#endif
// light second status LED (provides just GND)
#ifdef STATUS_LED2_PINS_ON
pinMode(LEDneg2Pin,OUTPUT);
digitalWrite(LEDneg2Pin,LOW);
LED2_ON=false;
#endif
// light second status LED (provides pwm'd GND for polar reticule)
#ifdef STATUS_LED2_PINS
pinMode(LEDneg2Pin,OUTPUT);
digitalWrite(LEDneg2Pin,LOW);
analogWrite(LEDneg2Pin,STATUS_LED2_PINS);
#endif
// ready the sound/buzzer pin
#ifndef BUZZER_OFF
pinMode(TonePin,OUTPUT);
digitalWrite(TonePin,LOW);
#endif
// provide 5V power to stepper drivers if requested
#ifdef POWER_SUPPLY_PINS_ON
pinMode(Axis15vPin,OUTPUT);
digitalWrite(Axis15vPin,HIGH);
pinMode(Axis25vPin,OUTPUT);
digitalWrite(Axis25vPin,HIGH);
#endif
// PEC index sense
#ifdef PEC_SENSE_ON
pinMode(PecPin,INPUT);
#endif
#ifdef PEC_SENSE_PULLUP
pinMode(PecPin,INPUT_PULLUP);
#endif
// limit switch sense
#ifdef LIMIT_SENSE_ON
pinMode(LimitPin,INPUT_PULLUP);
#endif
// ST4 interface
#ifdef ST4_ON
pinMode(ST4RAw,INPUT);
pinMode(ST4RAe,INPUT);
pinMode(ST4DEn,INPUT);
pinMode(ST4DEs,INPUT);
#endif
#ifdef ST4_PULLUP
pinMode(ST4RAw,INPUT_PULLUP);
pinMode(ST4RAe,INPUT_PULLUP);
pinMode(ST4DEn,INPUT_PULLUP);
pinMode(ST4DEs,INPUT_PULLUP);
#endif
// inputs for stepper drivers fault signal
#ifndef AXIS1_FAULT_OFF
#if defined(__ARM_Teensy3__) && defined(ALTERNATE_PINMAP_ON)
#ifdef AXIS1_FAULT_LOW
pinMode(Axis1_FAULT,INPUT_PULLUP);
#endif
#ifdef AXIS1_FAULT_HIGH
pinMode(Axis1_FAULT,INPUT_PULLDOWN);
#endif
#else
pinMode(Axis1_FAULT,INPUT);
#endif
#endif
#ifndef AXIS2_FAULT_OFF
#if defined(__ARM_Teensy3__) && defined(ALTERNATE_PINMAP_ON)
#ifdef AXIS2_FAULT_LOW
pinMode(Axis2_FAULT,INPUT_PULLUP);
#endif
#ifdef AXIS1_FAULT_HIGH
pinMode(Axis2_FAULT,INPUT_PULLDOWN);
#endif
#else
pinMode(Axis2_FAULT,INPUT);
#endif
#endif
// initialize and disable the stepper drivers
pinMode(Axis1_EN,OUTPUT);
pinMode(Axis2_EN,OUTPUT);
StepperModeTrackingInit();
// if the stepper driver mode select pins are wired in, program any requested micro-step mode
#if !defined(MODE_SWITCH_BEFORE_SLEW_ON) && !defined(MODE_SWITCH_BEFORE_SLEW_SPI)
// automatic mode switching during slews, initialize micro-step mode
#ifdef AXIS1_MODE
if ((AXIS1_MODE & 0b001000)==0) { pinMode(Axis1_M0,OUTPUT); digitalWrite(Axis1_M0,(AXIS1_MODE & 1)); } else { pinMode(Axis1_M0,INPUT); }
if ((AXIS1_MODE & 0b010000)==0) { pinMode(Axis1_M1,OUTPUT); digitalWrite(Axis1_M1,(AXIS1_MODE>>1 & 1)); } else { pinMode(Axis1_M1,INPUT); }
if ((AXIS1_MODE & 0b100000)==0) { pinMode(Axis1_M2,OUTPUT); digitalWrite(Axis1_M2,(AXIS1_MODE>>2 & 1)); } else { pinMode(Axis1_M2,INPUT); }
#endif
#ifdef AXIS2_MODE
if ((AXIS2_MODE & 0b001000)==0) { pinMode(Axis2_M0,OUTPUT); digitalWrite(Axis2_M0,(AXIS2_MODE & 1)); } else { pinMode(Axis2_M0,INPUT); }
if ((AXIS2_MODE & 0b010000)==0) { pinMode(Axis2_M1,OUTPUT); digitalWrite(Axis2_M1,(AXIS2_MODE>>1 & 1)); } else { pinMode(Axis2_M1,INPUT); }
if ((AXIS2_MODE & 0b100000)==0) { pinMode(Axis2_M2,OUTPUT); digitalWrite(Axis2_M2,(AXIS2_MODE>>2 & 1)); } else { pinMode(Axis2_M2,INPUT); }
#endif
#endif
#ifdef PPS_SENSE_ON
pinMode(PpsPin,INPUT);
#endif
#ifdef PPS_SENSE_PULLUP
pinMode(PpsPin,INPUT_PULLUP);
#endif
#if defined(PPS_SENSE_ON) || defined(PPS_SENSE_PULLUP)
#if defined(__AVR_ATmega2560__)
attachInterrupt(PpsInt,ClockSync,RISING);
#elif defined(__ARM_Teensy3__)
attachInterrupt(PpsPin,ClockSync,RISING);
#elif defined(__ARM_TI_TM4C__)
attachInterrupt(PpsPin,ClockSync,RISING);
#endif
#endif
}
void Init_ReadEEPROM_Values() {
// get the site information, if a GPS were attached we would use that here instead
currentSite=EEPROM.read(EE_currentSite); if (currentSite>3) currentSite=0; // site index is valid?
latitude=EEPROM_readFloat(EE_sites+(currentSite)*25+0);
#ifdef MOUNT_TYPE_ALTAZM
celestialPoleAxis2=AltAzmDecStartPos;
if (latitude<0) celestialPoleAxis1=180L; else celestialPoleAxis1=0L;
#else
if (latitude<0) celestialPoleAxis2=-90.0; else celestialPoleAxis2=90.0;
#endif
cosLat=cos(latitude/Rad);
sinLat=sin(latitude/Rad);
if (latitude>0) defaultDirAxis1 = defaultDirAxis1NCPInit; else defaultDirAxis1 = defaultDirAxis1SCPInit;
longitude=EEPROM_readFloat(EE_sites+(currentSite)*25+4);
timeZone=EEPROM.read(EE_sites+(currentSite)*25+8)-128;
timeZone=decodeTimeZone(timeZone);
EEPROM_readString(EE_sites+(currentSite)*25+9,siteName);
// update starting coordinates to reflect NCP or SCP polar home position
startAxis1 = celestialPoleAxis1*(long)StepsPerDegreeAxis1;
startAxis2 = celestialPoleAxis2*(double)StepsPerDegreeAxis2;
cli();
targetAxis1.part.m = startAxis1;
targetAxis1.part.f = 0;
posAxis1 = startAxis1;
trueAxis1 = startAxis1;
targetAxis2.part.m = startAxis2;
targetAxis2.part.f = 0;
posAxis2 = startAxis2;
trueAxis2 = startAxis2;
sei();
// get date and time from EEPROM, start keeping time
JD=EEPROM_readFloat(EE_JD);
LMT=EEPROM_readFloat(EE_LMT);
#ifdef RTC_DS3234
rtc.begin(DS3234_CS_PIN); rtc.update();
if ((rtc.year()>=0) && (rtc.month()<=99) && (rtc.month()>=1) && (rtc.month()<=12) && (rtc.date()>=1) && (rtc.date()<=31) &&
(rtc.hour()>=0) && (rtc.hour()<=23) && (rtc.minute()>=0) && (rtc.minute()<=59) && (rtc.second()>=0) && (rtc.second()<=59)) {
int y1=rtc.year(); if (y1>11) y1=y1+2000; else y1=y1+2100;
JD=julian(y1,rtc.month(),rtc.date());
LMT=(rtc.hour()+(rtc.minute()/60.0)+(rtc.second()/3600.0));
rtc.writeSQW(SQW_SQUARE_1);
}
#endif
UT1=LMT+timeZone;
update_lst(jd2last(JD,UT1,false));
// get the minutes past meridian east/west
#ifdef MOUNT_TYPE_GEM
minutesPastMeridianE=round(((EEPROM.read(EE_dpmE)-128)*60.0)/15.0); if (abs(minutesPastMeridianE)>180) minutesPastMeridianE=60;
minutesPastMeridianW=round(((EEPROM.read(EE_dpmW)-128)*60.0)/15.0); if (abs(minutesPastMeridianW)>180) minutesPastMeridianW=60;
#endif
// override if specified in Config.h
#ifdef MinutesPastMeridianE
minutesPastMeridianE=MinutesPastMeridianE;
#endif
#ifdef MinutesPastMeridianW
minutesPastMeridianW=MinutesPastMeridianW;
#endif
// get the min. and max altitude
minAlt=EEPROM.read(EE_minAlt)-128;
maxAlt=EEPROM.read(EE_maxAlt);
#ifdef MOUNT_TYPE_ALTAZM
if (maxAlt>87) maxAlt=87;
#endif
// get the backlash amounts
backlashAxis2=EEPROM_readInt(EE_backlashAxis2);
backlashAxis1=EEPROM_readInt(EE_backlashAxis1);
// get the PEC status
pecStatus =EEPROM.read(EE_pecStatus);
pecRecorded=EEPROM.read(EE_pecRecorded); if (!pecRecorded) pecStatus=IgnorePEC;
for (int i=0; i<PECBufferSize; i++) pecBuffer[i]=EEPROM.read(EE_pecTable+i);
wormSensePos=EEPROM_readLong(EE_wormSensePos);
#ifdef PEC_SENSE_OFF
wormSensePos=0;
pecStatus=IgnorePEC;
#endif
// get the Park status
parkSaved=EEPROM.read(EE_parkSaved);
parkStatus=EEPROM.read(EE_parkStatus);
// get the pulse-guide rate
currentPulseGuideRate=EEPROM.read(EE_pulseGuideRate); if (currentPulseGuideRate>GuideRate1x) currentPulseGuideRate=GuideRate1x;
// get the Goto rate and constrain values to the limits (1/2 to 2X the MaxRate,) maxRate is in 16MHz clocks but stored in micro-seconds
maxRate=EEPROM_readInt(EE_maxRate)*16;
if (maxRate<(MaxRate/2L)*16L) maxRate=(MaxRate/2L)*16L;
if (maxRate>(MaxRate*2L)*16L) maxRate=(MaxRate*2L)*16L;
#if !defined(RememberMaxRate_ON) && !defined(REMEMBER_MAX_RATE_ON)
if (maxRate!=MaxRate*16L) { maxRate=MaxRate*16L; EEPROM_writeInt(EE_maxRate,(int)(maxRate/16L)); }
#endif
SetAccelerationRates(maxRate); // set the new acceleration rate
// get autoMeridianFlip
#if defined(MOUNT_TYPE_GEM) && defined(REMEMBER_AUTO_MERIDIAN_FLIP_ON)
autoMeridianFlip=EEPROM.read(EE_autoMeridianFlip);
#endif
// get meridian flip pause at home
#if defined(MOUNT_TYPE_GEM) && defined(REMEMBER_PAUSE_HOME_ON)
pauseHome=EEPROM.read(EE_pauseHome);
#endif
// set the default guide rate, 16x sidereal
setGuideRate(GuideRate16x);
enableGuideRate(GuideRate16x);
}
void Init_EEPROM_Values() {
// EEPROM automatic initialization
long autoInitKey = initKey;
long thisAutoInitKey;
if (INIT_KEY) EEPROM_writeLong(EE_autoInitKey,autoInitKey);
thisAutoInitKey=EEPROM_readLong(EE_autoInitKey);
if (autoInitKey!=thisAutoInitKey) {
// init the site information, lat/long/tz/name
EEPROM.write(EE_currentSite,0);
latitude=0; longitude=0;
for (int l=0; l<4; l++) {
EEPROM_writeFloat(EE_sites+(l)*25+0,latitude);
EEPROM_writeFloat(EE_sites+(l)*25+4,longitude);
EEPROM.write(EE_sites+(l)*25+8,128);
EEPROM.write(EE_sites+(l)*25+9,0);
}
// init the date and time January 1, 2013. 0 hours LMT
JD=2456293.5;
LMT=0.0;
EEPROM_writeFloat(EE_JD,JD);
EEPROM_writeFloat(EE_LMT,LMT);
// init the minutes past meridian east/west
EEPROM.write(EE_dpmE,round((minutesPastMeridianE*15.0)/60.0)+128);
EEPROM.write(EE_dpmW,round((minutesPastMeridianW*15.0)/60.0)+128);
// init the min and max altitude
minAlt=-10;
maxAlt=85;
EEPROM.write(EE_minAlt,minAlt+128);
EEPROM.write(EE_maxAlt,maxAlt);
// init (clear) the backlash amounts
EEPROM_writeInt(EE_backlashAxis2,0);
EEPROM_writeInt(EE_backlashAxis1,0);
// init the PEC status, clear the index and buffer
EEPROM.write(EE_pecStatus,IgnorePEC);
EEPROM.write(EE_pecRecorded,false);
for (int l=0; l<PECBufferSize; l++) EEPROM.write(EE_pecTable+l,128);
wormSensePos=0;
EEPROM_writeLong(EE_wormSensePos,wormSensePos);
// init the Park status
EEPROM.write(EE_parkSaved,false);
EEPROM.write(EE_parkStatus,NotParked);
// init the pulse-guide rate
EEPROM.write(EE_pulseGuideRate,GuideRate1x);
// init the default maxRate
if (maxRate<2L*16L) maxRate=2L*16L; if (maxRate>10000L*16L) maxRate=10000L*16L;
EEPROM_writeInt(EE_maxRate,(int)(maxRate/16L));
// init autoMeridianFlip
EEPROM.write(EE_autoMeridianFlip,autoMeridianFlip);
// init the sidereal tracking rate, use this once - then issue the T+ and T- commands to fine tune
// 1/16uS resolution timer, ticks per sidereal second
EEPROM_writeLong(EE_siderealInterval,siderealInterval);
// finally, stop the init from happening again
EEPROM_writeLong(EE_autoInitKey,autoInitKey);
// clear the pointing model
saveAlignModel();
// disable OnTrack/Refraction dual axis mode
EEPROM.write(EE_onTrackDec,0);
}
}
void Init_Start_Timers() {
#if defined(__ARM_TI_TM4C__)
// need to initialise timers before using SetSiderealClockRate
// all timers are 32 bits
// timer 1A is used instead of itimer1
// timer 2A is used instead of itimer3
// timer 3A is used instead of itimer4
// Enable Timer 1 Clock
SysCtlPeripheralEnable(Sysctl_Periph_Timer1);
// Configure Timer Operation as Periodic
TimerConfigure(Timer1_base, TIMER_CFG_PERIODIC);
// register interrupt without editing the startup Energia file
//IntRegister( INT_TIMER1A, TIMER1_COMPA_vect );
TimerIntRegister(Timer1_base, TIMER_A, TIMER1_COMPA_vect );
// Enable Timer 1A interrupt
IntEnable(Int_timer1);
// Timer 1A generate interrupt when Timeout occurs
TimerIntEnable(Timer1_base, TIMER_TIMA_TIMEOUT);
// Configure Timer Frequency - initialize the timers that handle the sidereal clock, RA, and Dec
SetSiderealClockRate(siderealInterval);
// Start Timer 1A
TimerEnable(Timer1_base, TIMER_A);
// we also initialise timer 2A and 3A here as they may get used uninitialised from
// the interrupt for timer 1 if it gets triggered in the meantime
// we will not start them yet though
// Enable Timer 2 and 3 Clocks
SysCtlPeripheralEnable(Sysctl_Periph_Timer3);
SysCtlPeripheralEnable(Sysctl_Periph_Timer4);
// Configure Timer Operation as Periodic
TimerConfigure(Timer3_base, TIMER_CFG_PERIODIC);
TimerConfigure(Timer4_base, TIMER_CFG_PERIODIC);
// register interrupts without editing the startup Energia file
//IntRegister( INT_TIMER2A, TIMER3_COMPA_vect );
//IntRegister( INT_TIMER3A, TIMER4_COMPA_vect );
TimerIntRegister(Timer3_base, TIMER_A, TIMER3_COMPA_vect );
TimerIntRegister(Timer4_base, TIMER_A, TIMER4_COMPA_vect );
// Enable Timer 2A and 3A interrupts
IntEnable(Int_timer3);
IntEnable(Int_timer4);
// Timer 2A and 3A generate interrupt when Timeout occurs
TimerIntEnable(Timer3_base, TIMER_TIMA_TIMEOUT);
TimerIntEnable(Timer4_base, TIMER_TIMA_TIMEOUT);
//IntMasterEnable(); // not sure if needed, it works without
#else
// initialize the timers that handle the sidereal clock, RA, and Dec
SetSiderealClockRate(siderealInterval);
#endif
// wait for the sidereal clock to tick
delay(15);
#if defined(__AVR_ATmega2560__)
TCCR3B = (1 << WGM12) | (1 << CS11); // ~0 to 0.032 seconds (31 steps per second minimum, granularity of timer is 0.5uS) /8 pre-scaler
TCCR3A = 0;
TIMSK3 = (1 << OCIE3A);
TCCR4B = (1 << WGM12) | (1 << CS11); // ~0 to 0.032 seconds (31 steps per second minimum, granularity of timer is 0.5uS) /8 pre-scaler
TCCR4A = 0;
TIMSK4 = (1 << OCIE4A);
#elif defined(__ARM_Teensy3__)
// set the system timer for millis() to the second highest priority
SCB_SHPR3 = (32 << 24) | (SCB_SHPR3 & 0x00FFFFFF);
itimer3.begin(TIMER3_COMPA_vect, (float)128 * 0.0625);
itimer4.begin(TIMER4_COMPA_vect, (float)128 * 0.0625);
// set the 1/100 second sidereal clock timer to run at the second highest priority
NVIC_SET_PRIORITY(IRQ_PIT_CH0, 32);
// set the motor timers to run at the highest priority
NVIC_SET_PRIORITY(IRQ_PIT_CH1, 0);
NVIC_SET_PRIORITY(IRQ_PIT_CH2, 0);
#elif defined(__ARM_TI_TM4C__)
TimerLoadSet(Timer3_base, TIMER_A, (int) (F_BUS / 1000000 * 128 * 0.0625));
TimerLoadSet(Timer4_base, TIMER_A, (int) (F_BUS / 1000000 * 128 * 0.0625));
// Start Timer 2A and 3A
TimerEnable(Timer3_base, TIMER_A);
TimerEnable(Timer4_base, TIMER_A);
IntPrioritySet(Int_timer1, 1);
IntPrioritySet(Int_timer3, 0);
IntPrioritySet(Int_timer4, 0);
#endif
}