Rev 863 | Details | Compare with Previous | 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; |
||
173 | holgerb | 8 | unsigned int BeepMuster = 0xffff; |
1 | ingob | 9 | int ServoValue = 0; |
876 | DarkRider | 10 | unsigned char ucBeeperActive=1; |
1 | ingob | 11 | |
12 | enum { |
||
13 | STOP = 0, |
||
14 | CK = 1, |
||
15 | CK8 = 2, |
||
16 | CK64 = 3, |
||
17 | CK256 = 4, |
||
18 | CK1024 = 5, |
||
19 | T0_FALLING_EDGE = 6, |
||
20 | T0_RISING_EDGE = 7 |
||
21 | }; |
||
22 | |||
23 | |||
24 | SIGNAL (SIG_OVERFLOW0) // 8kHz |
||
25 | { |
||
26 | static unsigned char cnt_1ms = 1,cnt = 0; |
||
173 | holgerb | 27 | unsigned char pieper_ein = 0; |
1 | ingob | 28 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
29 | |||
30 | if(!cnt--) |
||
31 | { |
||
32 | cnt = 9; |
||
33 | cnt_1ms++; |
||
34 | cnt_1ms %= 2; |
||
35 | if(!cnt_1ms) UpdateMotor = 1; |
||
36 | CountMilliseconds++; |
||
37 | } |
||
38 | |||
39 | if(beeptime > 1) |
||
40 | { |
||
173 | holgerb | 41 | beeptime--; |
42 | if(beeptime & BeepMuster) |
||
43 | { |
||
876 | DarkRider | 44 | if(ucBeeperActive) pieper_ein = 1; |
863 | DarkRider | 45 | EXT1OUT_INV_OFF; |
173 | holgerb | 46 | } |
863 | DarkRider | 47 | else |
48 | { |
||
876 | DarkRider | 49 | if(ucBeeperActive) pieper_ein = 0; |
863 | DarkRider | 50 | EXT1OUT_INV_ON; |
51 | } |
||
1 | ingob | 52 | } |
173 | holgerb | 53 | else |
54 | { |
||
863 | DarkRider | 55 | EXT1OUT_INV_ON; |
173 | holgerb | 56 | pieper_ein = 0; |
876 | DarkRider | 57 | ucBeeperActive=1; |
173 | holgerb | 58 | BeepMuster = 0xffff; |
59 | } |
||
60 | |||
61 | |||
62 | if(pieper_ein) |
||
63 | { |
||
64 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
||
65 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
||
66 | } |
||
1 | ingob | 67 | else |
173 | holgerb | 68 | { |
69 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
||
70 | else PORTC &= ~(1<<7); |
||
71 | } |
||
72 | |||
1 | ingob | 73 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
74 | { |
||
75 | if(PINC & 0x10) |
||
76 | { |
||
77 | cntKompass++; |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | if((cntKompass) && (cntKompass < 4000)) |
||
82 | { |
||
83 | KompassValue = cntKompass; |
||
84 | } |
||
85 | // if(cntKompass < 10) cntKompass = 10; |
||
86 | // KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L; |
||
87 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
88 | cntKompass = 0; |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
876 | DarkRider | 93 | void setBeeperActive(unsigned char ucVal) |
94 | { |
||
95 | ucBeeperActive=ucVal; |
||
96 | } |
||
1 | ingob | 97 | |
98 | void Timer_Init(void) |
||
99 | { |
||
100 | tim_main = SetDelay(10); |
||
101 | TCCR0B = CK8; |
||
102 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
103 | OCR0A = 0; |
||
104 | OCR0B = 120; |
||
304 | ingob | 105 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
1 | ingob | 106 | //OCR1 = 0x00; |
107 | |||
108 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
||
109 | TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
||
110 | |||
111 | // TIMSK2 |= _BV(TOIE2); |
||
112 | TIMSK2 |= _BV(OCIE2A); |
||
113 | |||
114 | TIMSK0 |= _BV(TOIE0); |
||
115 | OCR2A = 10; |
||
116 | TCNT2 = 0; |
||
117 | |||
118 | } |
||
119 | |||
120 | // ----------------------------------------------------------------------- |
||
121 | |||
122 | unsigned int SetDelay (unsigned int t) |
||
123 | { |
||
124 | // TIMSK0 &= ~_BV(TOIE0); |
||
125 | return(CountMilliseconds + t + 1); |
||
126 | // TIMSK0 |= _BV(TOIE0); |
||
127 | } |
||
128 | |||
129 | // ----------------------------------------------------------------------- |
||
130 | char CheckDelay(unsigned int t) |
||
131 | { |
||
132 | // TIMSK0 &= ~_BV(TOIE0); |
||
133 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
134 | // TIMSK0 |= _BV(TOIE0); |
||
135 | } |
||
136 | |||
137 | // ----------------------------------------------------------------------- |
||
138 | void Delay_ms(unsigned int w) |
||
139 | { |
||
140 | unsigned int akt; |
||
141 | akt = SetDelay(w); |
||
142 | while (!CheckDelay(akt)); |
||
143 | } |
||
144 | |||
395 | hbuss | 145 | void Delay_ms_Mess(unsigned int w) |
146 | { |
||
147 | unsigned int akt; |
||
148 | akt = SetDelay(w); |
||
149 | while (!CheckDelay(akt)) ANALOG_ON; |
||
150 | } |
||
151 | |||
1 | ingob | 152 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
153 | // Servo ansteuern |
||
154 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
155 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
||
156 | { |
||
157 | static unsigned char timer = 10; |
||
158 | |||
159 | if(!timer--) |
||
160 | { |
||
161 | TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
||
162 | ServoValue = Parameter_ServoNickControl; |
||
163 | if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
164 | else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
165 | |||
166 | if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
||
167 | else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
||
168 | |||
169 | OCR2A = ServoValue;// + 75; |
||
170 | timer = EE_Parameter.ServoNickRefresh; |
||
171 | } |
||
172 | else |
||
173 | { |
||
174 | TCCR2A =3; |
||
175 | PORTD&=~0x80; |
||
176 | } |
||
177 | } |