Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
12 | hbuss | 1 | /*####################################################################################### |
2 | MK3Mag 3D-Magnet sensor |
||
19 | killagreg | 3 | !!! THIS IS NOT FREE SOFTWARE !!! |
12 | hbuss | 4 | #######################################################################################*/ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
6 | // + Copyright (c) 05.2008 Holger Buss |
||
7 | // + Thanks to Ilja Fähnrich (P_Latzhalter) |
||
8 | // + Nur für den privaten Gebrauch |
||
9 | // + www.MikroKopter.com |
||
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 11 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
12 | hbuss | 12 | // + mit unserer Zustimmung zulässig |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 14 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
15 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
12 | hbuss | 16 | // + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden |
17 | // + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de |
||
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 19 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
12 | hbuss | 20 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
21 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
22 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
23 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
24 | // + eindeutig als Ursprung verlinkt werden |
||
25 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
26 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
27 | // + Benutzung auf eigene Gefahr |
||
28 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | killagreg | 32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
12 | hbuss | 33 | // + this list of conditions and the following disclaimer. |
34 | // + * PORTING this software (or parts of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
||
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
36 | // + from this software without specific prior written permission. |
||
19 | killagreg | 37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
12 | hbuss | 38 | // + for non-commercial use (directly or indirectly) |
19 | killagreg | 39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
12 | hbuss | 40 | // + with our written permission |
41 | // + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems |
||
42 | // + In case of doubt please contact: info@MikroKopter.de |
||
19 | killagreg | 43 | // + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be |
44 | // + clearly linked as origin |
||
12 | hbuss | 45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
19 | killagreg | 55 | // + POSSIBILITY OF SUCH DAMAGE. |
12 | hbuss | 56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | killagreg | 57 | //#include <stdlib.h> |
58 | #include "analog.h" |
||
1 | ingob | 59 | |
60 | void ADC_Init(void) |
||
61 | { |
||
19 | killagreg | 62 | // set PortC 0,1,2,3 as input |
63 | DDRC &= ~((1<<DDC3)|(1<<DDC2)|(1<<DDC1)|(1<<DDC0)); |
||
64 | // set PortC 0,1,2,3 and 6,7 as tri state |
||
65 | PORTC &= ~((1<<PORTC3)|(1<<PORTC2)|(1<<PORTC1)|(1<<PORTC0)); |
||
66 | |||
67 | // port PD5 and PD6 control the current direction of the test coils of the sensors |
||
68 | DDRD |= ((1<<DDD5)|(1<<DDD6)); |
||
69 | FLIP_LOW; |
||
70 | |||
71 | // disable internal reference voltage and right adjust bits in ADCW |
||
72 | ADMUX = 0x00; |
||
73 | // clear start conversion bit (ADSC = 0) |
||
74 | // disable ADC Auto Trigger Enable (ADATE = 0) |
||
75 | // disable interrupt (ADIE = 0) |
||
76 | ADCSRA &= ~((1<<ADSC)|(1<<ADATE)|(1<<ADIE)); |
||
77 | // Enable ADC (ADEN = 1) with SYSCLK/128 (ADPS2 = 1, ADPS1 = 1, ADPS0 = 1) and clear ready flag (ADIF = 1) |
||
78 | ADCSRA |= ((1<<ADEN)|(1<<ADIF)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)); |
||
79 | ADMUX = 0x00; // select ADC0 |
||
80 | ADCSRA |= (1<<ADSC); // start conversion |
||
1 | ingob | 81 | } |
82 | |||
83 | |||
19 | killagreg | 84 | uint16_t ADC_GetValue(ADChannel_t channel) |
1 | ingob | 85 | { |
19 | killagreg | 86 | uint16_t value = 0; |
87 | ADMUX = channel; // set muxer bits |
||
88 | ADCSRA |= (1<<ADIF); // clear ready-flag |
||
89 | ADCSRA |= (1<<ADSC); // start conversion |
||
90 | while (((ADCSRA & (1<<ADIF)) == 0)); // wait for end of conversion |
||
91 | value = ADCW; // read adc result |
||
92 | return(value); |
||
1 | ingob | 93 | } |
94 | |||
95 | |||
96 |