Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | #include "main.h" |
2 | |||
3 | volatile unsigned int CountMilliseconds = 0; |
||
4 | volatile static unsigned int tim_main; |
||
5 | volatile unsigned char UpdateMotor = 0; |
||
6 | volatile unsigned int cntKompass = 0; |
||
7 | volatile unsigned int beeptime = 0; |
||
8 | int ServoValue = 0; |
||
136 | salvo | 9 | //Salvo 8.9.2007 |
143 | salvo | 10 | volatile uint8_t Kompass_Neuer_Wert= 0; |
136 | salvo | 11 | volatile unsigned int Kompass_Value_Old = 0; |
12 | // Salvo End |
||
162 | salvo | 13 | //Salvo 21.9.2007 |
14 | short unsigned int Kompass_present= 0; //>0 bedeutet dass der Kompass vorhanden ist |
||
15 | // Salvo End |
||
1 | ingob | 16 | enum { |
17 | STOP = 0, |
||
18 | CK = 1, |
||
19 | CK8 = 2, |
||
20 | CK64 = 3, |
||
21 | CK256 = 4, |
||
22 | CK1024 = 5, |
||
23 | T0_FALLING_EDGE = 6, |
||
24 | T0_RISING_EDGE = 7 |
||
25 | }; |
||
26 | |||
162 | salvo | 27 | // Aenderungen von Peter Muehlenbrock ("Salvo") Stand 21.9.2007 |
156 | salvo | 28 | /* |
29 | Driftkompensation fuer Gyros verbessert |
||
162 | salvo | 30 | Linearsensor mit fixem Neutralwert |
31 | Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsubhaengige Kompassfunktion |
||
156 | salvo | 32 | */ |
1 | ingob | 33 | SIGNAL (SIG_OVERFLOW0) // 8kHz |
34 | { |
||
35 | static unsigned char cnt_1ms = 1,cnt = 0; |
||
36 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
||
37 | |||
38 | if(!cnt--) |
||
39 | { |
||
162 | salvo | 40 | if (Kompass_present > 0) Kompass_present--; //Runterzaehlen. Wenn 0 ist der Kompass nicht vorhanden |
1 | ingob | 41 | cnt = 9; |
42 | cnt_1ms++; |
||
43 | cnt_1ms %= 2; |
||
44 | if(!cnt_1ms) UpdateMotor = 1; |
||
45 | CountMilliseconds++; |
||
46 | if(Timeout) Timeout--; |
||
47 | } |
||
48 | |||
49 | if(beeptime > 1) |
||
50 | { |
||
51 | beeptime--; |
||
52 | PORTD |= (1<<2); |
||
53 | } |
||
54 | else |
||
55 | PORTD &= ~(1<<2); |
||
56 | |||
136 | salvo | 57 | // if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
1 | ingob | 58 | { |
59 | if(PINC & 0x10) |
||
60 | { |
||
61 | cntKompass++; |
||
62 | } |
||
63 | else |
||
64 | { |
||
65 | if((cntKompass) && (cntKompass < 4000)) |
||
66 | { |
||
162 | salvo | 67 | // Salvo Kompassoffset 30.8.2007 und 21.9.2007 *********** |
68 | Kompass_present = 255; |
||
157 | salvo | 69 | Kompass_Value_Old = KompassValue; |
104 | salvo | 70 | KompassValue = cntKompass -KOMPASS_OFFSET; |
71 | |||
72 | if (KompassValue < 0) |
||
73 | { |
||
74 | KompassValue += 360; |
||
75 | } |
||
76 | if (KompassValue >= 360) |
||
77 | { |
||
78 | KompassValue -= 360; |
||
79 | } |
||
80 | // Salvo End |
||
1 | ingob | 81 | } |
82 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
156 | salvo | 83 | //Salvo 13.9.2007 Ok Erkennung des Magnetkompasses |
136 | salvo | 84 | Kompass_Neuer_Wert = 1; |
156 | salvo | 85 | // Salvo End |
136 | salvo | 86 | cntKompass = 0; |
1 | ingob | 87 | } |
88 | } |
||
89 | } |
||
90 | |||
91 | |||
92 | void Timer_Init(void) |
||
93 | { |
||
94 | tim_main = SetDelay(10); |
||
95 | TCCR0B = CK8; |
||
96 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
97 | OCR0A = 0; |
||
98 | OCR0B = 120; |
||
99 | TCNT0 = -TIMER_RELOAD_VALUE; // reload |
||
100 | //OCR1 = 0x00; |
||
101 | |||
102 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
||
103 | TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
||
104 | |||
105 | // TIMSK2 |= _BV(TOIE2); |
||
106 | TIMSK2 |= _BV(OCIE2A); |
||
107 | |||
108 | TIMSK0 |= _BV(TOIE0); |
||
109 | OCR2A = 10; |
||
110 | TCNT2 = 0; |
||
111 | |||
112 | } |
||
113 | |||
114 | // ----------------------------------------------------------------------- |
||
115 | |||
116 | unsigned int SetDelay (unsigned int t) |
||
117 | { |
||
118 | // TIMSK0 &= ~_BV(TOIE0); |
||
119 | return(CountMilliseconds + t + 1); |
||
120 | // TIMSK0 |= _BV(TOIE0); |
||
121 | } |
||
122 | |||
123 | // ----------------------------------------------------------------------- |
||
124 | char CheckDelay(unsigned int t) |
||
125 | { |
||
126 | // TIMSK0 &= ~_BV(TOIE0); |
||
127 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
128 | // TIMSK0 |= _BV(TOIE0); |
||
129 | } |
||
130 | |||
131 | // ----------------------------------------------------------------------- |
||
132 | void Delay_ms(unsigned int w) |
||
133 | { |
||
134 | unsigned int akt; |
||
135 | akt = SetDelay(w); |
||
136 | while (!CheckDelay(akt)); |
||
137 | } |
||
138 | |||
139 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
140 | // Servo ansteuern |
||
141 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
142 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
||
143 | { |
||
144 | static unsigned char timer = 10; |
||
145 | |||
146 | if(!timer--) |
||
147 | { |
||
148 | TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
||
149 | ServoValue = Parameter_ServoNickControl; |
||
150 | if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
151 | else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
152 | |||
153 | if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
||
154 | else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
||
155 | |||
143 | salvo | 156 | // DebugOut.Analog[10] = ServoValue; |
1 | ingob | 157 | OCR2A = ServoValue;// + 75; |
158 | timer = EE_Parameter.ServoNickRefresh; |
||
159 | } |
||
160 | else |
||
161 | { |
||
162 | TCCR2A =3; |
||
163 | PORTD&=~0x80; |
||
164 | } |
||
165 | } |