Subversion Repositories NaviCtrl

Rev

Rev 213 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
135 killagreg 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
171 ingob 6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
135 killagreg 7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 ingob 28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
135 killagreg 29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + this list of conditions and the following disclaimer.
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.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
171 ingob 43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
135 killagreg 44
//
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
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include "91x_lib.h"
58
#include "uart1.h"
59
#include "analog.h"
147 killagreg 60
#include "timer1.h"
136 killagreg 61
#include "config.h"
135 killagreg 62
 
63
AnalogData_t AnalogData;
64
 
65
void ADC_IRQHandler(void)
66
{
195 killagreg 67
        IENABLE;
68
 
135 killagreg 69
        if(ADC_GetFlagStatus(ADC_FLAG_ECV) == SET)
70
        {
154 killagreg 71
                ADC_ClearFlag(ADC_FLAG_ECV);
135 killagreg 72
                AnalogData.Ch1 = ADC_GetConversionValue(ADC_Channel_1);
73
                AnalogData.Ch2 = ADC_GetConversionValue(ADC_Channel_2);
74
                AnalogData.Ch3 = ADC_GetConversionValue(ADC_Channel_3);
75
                AnalogData.Ch4 = ADC_GetConversionValue(ADC_Channel_4);
76
                AnalogData.Ch5 = ADC_GetConversionValue(ADC_Channel_5);
77
                AnalogData.Ch6 = ADC_GetConversionValue(ADC_Channel_6);
78
                AnalogData.Ch7 = ADC_GetConversionValue(ADC_Channel_7);
79
        }
195 killagreg 80
        IDISABLE;
135 killagreg 81
}
82
 
83
void Analog_Init(void)
84
{
182 killagreg 85
        ADC_InitTypeDef   ADC_InitStructure;
135 killagreg 86
 
87
        UART1_PutString("\r\n ADC init...");
182 killagreg 88
 
135 killagreg 89
        SCU_APBPeriphClockConfig(__GPIO4, ENABLE); // Enable the GPIO4 Clock
182 killagreg 90
 
135 killagreg 91
        ADC_DeInit(); // reset register to default values
182 killagreg 92
 
135 killagreg 93
        // configure port 4 pins as analog inputs
94
        GPIO_ANAPinConfig(GPIO_ANAChannel1, ENABLE);
95
        GPIO_ANAPinConfig(GPIO_ANAChannel2, ENABLE);
96
        GPIO_ANAPinConfig(GPIO_ANAChannel3, ENABLE);
97
        GPIO_ANAPinConfig(GPIO_ANAChannel4, ENABLE);
98
        GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);
99
        GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);
100
        GPIO_ANAPinConfig(GPIO_ANAChannel7, ENABLE);
101
 
102
        ADC_Cmd(ENABLE); // power on the ADC
103
        ADC_StandbyModeCmd(DISABLE); // disable Standby Mode
182 killagreg 104
        ADC_StructInit(&ADC_InitStructure);
135 killagreg 105
        ADC_InitStructure.ADC_Channel_1_Mode = ADC_NoThreshold_Conversion;
106
        ADC_InitStructure.ADC_Channel_2_Mode = ADC_NoThreshold_Conversion;
107
        ADC_InitStructure.ADC_Channel_3_Mode = ADC_NoThreshold_Conversion;
108
        ADC_InitStructure.ADC_Channel_4_Mode = ADC_NoThreshold_Conversion;
109
        ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
110
        ADC_InitStructure.ADC_Channel_6_Mode = ADC_NoThreshold_Conversion;
111
        ADC_InitStructure.ADC_Channel_7_Mode = ADC_NoThreshold_Conversion;
141 killagreg 112
        ADC_InitStructure.ADC_Select_Channel = ADC_Channel_1;
135 killagreg 113
        ADC_InitStructure.ADC_Scan_Mode = ENABLE; // convert all selected channels
141 killagreg 114
        ADC_InitStructure.ADC_Conversion_Mode = ADC_Single_Mode;
135 killagreg 115
        ADC_Init(&ADC_InitStructure);
116
 
117
        ADC_PrescalerConfig(255);  // PCLK/255  (24MHz/255 = 94.1kHZ )
118
        ADC_ITConfig(ADC_IT_ECV, ENABLE); // enable end of conversion IRQ
182 killagreg 119
 
136 killagreg 120
        VIC_Config(ADC_ITLine, VIC_IRQ, PRIORITY_ADC);
135 killagreg 121
        VIC_ITCmd(ADC_ITLine, ENABLE);
122
 
123
        UART1_PutString("ok");
124
}
139 killagreg 125
 
126
void Analog_Deinit(void)
127
{
128
        VIC_ITCmd(ADC_ITLine, DISABLE);
129
        ADC_ConversionCmd(ADC_Conversion_Stop);
130
        ADC_ITConfig(ADC_IT_ECV, DISABLE); // disable end of conversion IRQ
131
        ADC_Cmd(DISABLE); // power down the ADC
132
        ADC_DeInit(); // reset register to default values
133
}
146 killagreg 134
 
135
void Analog_Update(void)
136
{
147 killagreg 137
        static u32 AnalogTimer = 0;
138
 
139
        if(CheckDelay(AnalogTimer))
140
        {
141
                AnalogTimer = SetDelay(25);
142
                ADC_ConversionCmd(ADC_Conversion_Start);
143
        }
146 killagreg 144
}