Rev 1612 | Rev 1775 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1612 | Rev 1634 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt werden |
18 | // + eindeutig als Ursprung verlinkt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | #include <inttypes.h> |
51 | #include <inttypes.h> |
52 | #include <avr/io.h> |
52 | #include <avr/io.h> |
53 | #include <avr/interrupt.h> |
53 | #include <avr/interrupt.h> |
54 | #include "eeprom.h" |
54 | #include "eeprom.h" |
55 | #include "analog.h" |
55 | #include "analog.h" |
56 | 56 | ||
57 | #ifdef USE_MK3MAG |
57 | #ifdef USE_MK3MAG |
58 | #include "mk3mag.h" |
58 | #include "mk3mag.h" |
59 | #endif |
59 | #endif |
60 | 60 | ||
61 | volatile uint16_t CountMilliseconds = 0; |
61 | volatile uint16_t CountMilliseconds = 0; |
62 | volatile uint8_t runFlightControl = 0; |
62 | volatile uint8_t runFlightControl = 0; |
63 | volatile uint16_t cntKompass = 0; |
63 | volatile uint16_t cntKompass = 0; |
64 | volatile uint16_t BeepTime = 0; |
64 | volatile uint16_t BeepTime = 0; |
65 | volatile uint16_t BeepModulation = 0xFFFF; |
65 | volatile uint16_t BeepModulation = 0xFFFF; |
66 | 66 | ||
67 | #ifdef USE_NAVICTRL |
67 | #ifdef USE_NAVICTRL |
68 | volatile uint8_t SendSPI = 0; |
68 | volatile uint8_t SendSPI = 0; |
69 | #endif |
69 | #endif |
70 | 70 | ||
71 | /***************************************************** |
71 | /***************************************************** |
72 | * Initialize Timer 0 |
72 | * Initialize Timer 0 |
73 | *****************************************************/ |
73 | *****************************************************/ |
74 | // timer 0 is used for the PWM generation to control the offset voltage at the air pressure sensor |
74 | // timer 0 is used for the PWM generation to control the offset voltage at the air pressure sensor |
75 | // Its overflow interrupt routine is used to generate the beep signal and the flight control motor update rate |
75 | // Its overflow interrupt routine is used to generate the beep signal and the flight control motor update rate |
76 | void timer0_init(void) { |
76 | void timer0_init(void) { |
77 | uint8_t sreg = SREG; |
77 | uint8_t sreg = SREG; |
78 | 78 | ||
79 | // disable all interrupts before reconfiguration |
79 | // disable all interrupts before reconfiguration |
80 | cli(); |
80 | cli(); |
81 | 81 | ||
82 | // Configure speaker port as output. |
82 | // Configure speaker port as output. |
83 | 83 | ||
84 | if(BoardRelease == 10) { // Speaker at PD2 |
84 | if(BoardRelease == 10) { // Speaker at PD2 |
85 | DDRD |= (1<<DDD2); |
85 | DDRD |= (1<<DDD2); |
86 | PORTD &= ~(1<<PORTD2); |
86 | PORTD &= ~(1<<PORTD2); |
87 | } else { // Speaker at PC7 |
87 | } else { // Speaker at PC7 |
88 | DDRC |= (1<<DDC7); |
88 | DDRC |= (1<<DDC7); |
89 | PORTC &= ~(1<<PORTC7); |
89 | PORTC &= ~(1<<PORTC7); |
90 | } |
90 | } |
91 | 91 | ||
92 | // set PB3 and PB4 as output for the PWM used as offset for the pressure sensor |
92 | // set PB3 and PB4 as output for the PWM used as offset for the pressure sensor |
93 | DDRB |= (1<<DDB4)|(1<<DDB3); |
93 | DDRB |= (1<<DDB4)|(1<<DDB3); |
94 | PORTB &= ~((1<<PORTB4)|(1<<PORTB3)); |
94 | PORTB &= ~((1<<PORTB4)|(1<<PORTB3)); |
95 | 95 | ||
96 | // Timer/Counter 0 Control Register A |
96 | // Timer/Counter 0 Control Register A |
97 | 97 | ||
98 | // Waveform Generation Mode is Fast PWM (Bits WGM02 = 0, WGM01 = 1, WGM00 = 1) |
98 | // Waveform Generation Mode is Fast PWM (Bits WGM02 = 0, WGM01 = 1, WGM00 = 1) |
99 | // Clear OC0A on Compare Match, set OC0A at BOTTOM, noninverting PWM (Bits COM0A1 = 1, COM0A0 = 0) |
99 | // Clear OC0A on Compare Match, set OC0A at BOTTOM, noninverting PWM (Bits COM0A1 = 1, COM0A0 = 0) |
100 | // Clear OC0B on Compare Match, set OC0B at BOTTOM, (Bits COM0B1 = 1, COM0B0 = 0) |
100 | // Clear OC0B on Compare Match, set OC0B at BOTTOM, (Bits COM0B1 = 1, COM0B0 = 0) |
101 | TCCR0A &= ~((1<<COM0A0)|(1<<COM0B0)); |
101 | TCCR0A &= ~((1<<COM0A0)|(1<<COM0B0)); |
102 | TCCR0A |= (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
102 | TCCR0A |= (1<<COM0A1)|(1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
103 | 103 | ||
104 | // Timer/Counter 0 Control Register B |
104 | // Timer/Counter 0 Control Register B |
105 | 105 | ||
106 | // set clock divider for timer 0 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz |
106 | // set clock divider for timer 0 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz |
107 | // i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz |
107 | // i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz |
108 | // hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz |
108 | // hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz |
109 | 109 | ||
110 | // divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0) |
110 | // divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0) |
111 | TCCR0B &= ~((1<<FOC0A)|(1<<FOC0B)|(1<<WGM02)); |
111 | TCCR0B &= ~((1<<FOC0A)|(1<<FOC0B)|(1<<WGM02)); |
112 | TCCR0B = (TCCR0B & 0xF8)|(0<<CS02)|(1<<CS01)|(0<<CS00); |
112 | TCCR0B = (TCCR0B & 0xF8)|(0<<CS02)|(1<<CS01)|(0<<CS00); |
113 | 113 | ||
114 | // initialize the Output Compare Register A & B used for PWM generation on port PB3 & PB4 |
114 | // initialize the Output Compare Register A & B used for PWM generation on port PB3 & PB4 |
115 | OCR0A = 0; // for PB3 |
115 | OCR0A = 0; // for PB3 |
116 | OCR0B = 120; // for PB4 |
116 | OCR0B = 120; // for PB4 |
117 | 117 | ||
118 | // init Timer/Counter 0 Register |
118 | // init Timer/Counter 0 Register |
119 | TCNT0 = 0; |
119 | TCNT0 = 0; |
120 | 120 | ||
121 | // Timer/Counter 0 Interrupt Mask Register |
121 | // Timer/Counter 0 Interrupt Mask Register |
122 | // enable timer overflow interrupt only |
122 | // enable timer overflow interrupt only |
123 | TIMSK0 &= ~((1<<OCIE0B)|(1<<OCIE0A)); |
123 | TIMSK0 &= ~((1<<OCIE0B)|(1<<OCIE0A)); |
124 | TIMSK0 |= (1<<TOIE0); |
124 | TIMSK0 |= (1<<TOIE0); |
125 | 125 | ||
126 | SREG = sreg; |
126 | SREG = sreg; |
127 | } |
127 | } |
128 | 128 | ||
129 | /*****************************************************/ |
129 | /*****************************************************/ |
130 | /* Interrupt Routine of Timer 0 */ |
130 | /* Interrupt Routine of Timer 0 */ |
131 | /*****************************************************/ |
131 | /*****************************************************/ |
132 | ISR(TIMER0_OVF_vect) { // 9765.625 Hz |
132 | ISR(TIMER0_OVF_vect) { // 9765.625 Hz |
133 | static uint8_t cnt_1ms = 1,cnt = 0; |
133 | static uint8_t cnt_1ms = 1,cnt = 0; |
134 | uint8_t Beeper_On = 0; |
134 | uint8_t Beeper_On = 0; |
135 | 135 | ||
136 | #ifdef USE_NAVICTRL |
136 | #ifdef USE_NAVICTRL |
137 | if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done |
137 | if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done |
138 | #endif |
138 | #endif |
139 | 139 | ||
140 | if(!cnt--) { // every 10th run (9.765kHz/10 = 976Hz) |
140 | if(!cnt--) { // every 10th run (9.765kHz/10 = 976Hz) |
141 | cnt = 9; |
141 | cnt = 9; |
142 | cnt_1ms++; |
142 | cnt_1ms^=1; |
143 | cnt_1ms %= 2; |
- | |
144 | if(!cnt_1ms) runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz) |
143 | if(!cnt_1ms) runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz) |
145 | CountMilliseconds++; // increment millisecond counter |
144 | CountMilliseconds++; // increment millisecond counter |
146 | } |
145 | } |
147 | 146 | ||
148 | // beeper on if duration is not over |
147 | // beeper on if duration is not over |
149 | if(BeepTime) { |
148 | if(BeepTime) { |
150 | BeepTime--; // decrement BeepTime |
149 | BeepTime--; // decrement BeepTime |
151 | if(BeepTime & BeepModulation) Beeper_On = 1; |
150 | if(BeepTime & BeepModulation) Beeper_On = 1; |
152 | else Beeper_On = 0; |
151 | else Beeper_On = 0; |
153 | } |
152 | } |
154 | else { // beeper off if duration is over |
153 | else { // beeper off if duration is over |
155 | Beeper_On = 0; |
154 | Beeper_On = 0; |
156 | BeepModulation = 0xFFFF; |
155 | BeepModulation = 0xFFFF; |
157 | } |
156 | } |
158 | 157 | ||
159 | // if beeper is on |
158 | // if beeper is on |
160 | if(Beeper_On) { |
159 | if(Beeper_On) { |
161 | // set speaker port to high. |
160 | // set speaker port to high. |
162 | if(BoardRelease == 10) PORTD |= (1<<PORTD2); // Speaker at PD2 |
161 | if(BoardRelease == 10) PORTD |= (1<<PORTD2); // Speaker at PD2 |
163 | else PORTC |= (1<<PORTC7); // Speaker at PC7 |
162 | else PORTC |= (1<<PORTC7); // Speaker at PC7 |
164 | } else { // beeper is off |
163 | } else { // beeper is off |
165 | // set speaker port to low |
164 | // set speaker port to low |
166 | if(BoardRelease == 10) PORTD &= ~(1<<PORTD2);// Speaker at PD2 |
165 | if(BoardRelease == 10) PORTD &= ~(1<<PORTD2);// Speaker at PD2 |
167 | else PORTC &= ~(1<<PORTC7);// Speaker at PC7 |
166 | else PORTC &= ~(1<<PORTC7);// Speaker at PC7 |
168 | } |
167 | } |
169 | 168 | ||
170 | #ifndef USE_NAVICTRL |
169 | #ifndef USE_NAVICTRL |
171 | // update compass value if this option is enabled in the settings |
170 | // update compass value if this option is enabled in the settings |
172 | if(staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE|CFG_GPS_ACTIVE)) { |
171 | if(staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE|CFG_GPS_ACTIVE)) { |
173 | #ifdef USE_MK3MAG |
172 | #ifdef USE_MK3MAG |
174 | MK3MAG_Update(); // read out mk3mag pwm |
173 | MK3MAG_Update(); // read out mk3mag pwm |
175 | #endif |
174 | #endif |
176 | } |
175 | } |
177 | #endif |
176 | #endif |
178 | } |
177 | } |
179 | 178 | ||
180 | // ----------------------------------------------------------------------- |
179 | // ----------------------------------------------------------------------- |
181 | uint16_t SetDelay (uint16_t t) { |
180 | uint16_t SetDelay (uint16_t t) { |
182 | return(CountMilliseconds + t - 1); |
181 | return(CountMilliseconds + t - 1); |
183 | } |
182 | } |
184 | 183 | ||
185 | // ----------------------------------------------------------------------- |
184 | // ----------------------------------------------------------------------- |
186 | int8_t CheckDelay(uint16_t t) { |
185 | int8_t CheckDelay(uint16_t t) { |
187 | return(((t - CountMilliseconds) & 0x8000) >> 8); // check sign bit |
186 | return(((t - CountMilliseconds) & 0x8000) >> 8); // check sign bit |
188 | } |
187 | } |
189 | 188 | ||
190 | // ----------------------------------------------------------------------- |
189 | // ----------------------------------------------------------------------- |
191 | void Delay_ms(uint16_t w) { |
190 | void Delay_ms(uint16_t w) { |
192 | uint16_t t_stop = SetDelay(w); |
191 | uint16_t t_stop = SetDelay(w); |
193 | while (!CheckDelay(t_stop)); |
192 | while (!CheckDelay(t_stop)); |
194 | } |
193 | } |
195 | 194 | ||
196 | // ----------------------------------------------------------------------- |
195 | // ----------------------------------------------------------------------- |
197 | void Delay_ms_Mess(uint16_t w) { |
196 | void Delay_ms_Mess(uint16_t w) { |
198 | uint16_t t_stop; |
197 | uint16_t t_stop; |
199 | t_stop = SetDelay(w); |
198 | t_stop = SetDelay(w); |
200 | while (!CheckDelay(t_stop)) { |
199 | while (!CheckDelay(t_stop)) { |
201 | if(analogDataReady) { |
200 | if(analogDataReady) { |
202 | analogDataReady = 0; |
201 | analogDataReady = 0; |
203 | analog_start(); |
202 | analog_start(); |
204 | } |
203 | } |
205 | } |
204 | } |
206 | } |
205 | } |
207 | 206 |