1 | /*
|
2 | * adc_test.c
|
3 | *
|
4 | * Created: 18.02.2014
|
5 | * Author: Nicolas
|
6 | */
|
7 |
|
8 | #include <stdio.h>
|
9 | #include "../../ioMapping.h"
|
10 | #include "../src_encoder/key.h"
|
11 | #include "../src_avrcom/pgmspace.h"
|
12 | #include "../src_avrcom/delay.h"
|
13 | #include "../src_glcd/glcd_ks0108.h"
|
14 |
|
15 | #ifdef STM32F10x
|
16 | #include "stm32f10x_adc.h"
|
17 | #include "stm32f10x_gpio.h"
|
18 | #include "stm32f10x_rcc.h"
|
19 | #elif defined(STM32F4xx)
|
20 | #error "only for STM32F10x implemented yet"
|
21 | #else
|
22 | #error "unknown MCU"
|
23 | #endif
|
24 |
|
25 |
|
26 | //#define POTI_UPDWN_GPIO GPIOC
|
27 | //#define POTI_UPDWN_Pin GPIO_Pin_3
|
28 | //#define POTI_UPDWM_ADCCH ADC_Channel_13
|
29 |
|
30 |
|
31 | void adc_calib(ADC_TypeDef *ADCx) {
|
32 | ADC_Cmd(ADCx,ENABLE);
|
33 | ADC_ResetCalibration(ADCx);
|
34 | while(ADC_GetResetCalibrationStatus(ADCx));
|
35 | ADC_StartCalibration(ADCx);
|
36 | while(ADC_GetCalibrationStatus(ADCx));
|
37 | ADC_SoftwareStartConvCmd(ADCx,ENABLE);
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 | /* Suchen von I2C-Devices und Darstellen auf LCD */
|
43 | void adc_test(void) {
|
44 | ADC_InitTypeDef ADC_InitStructure;
|
45 | GPIO_InitTypeDef GPIO_InitStructure;
|
46 | uint16_t value;
|
47 |
|
48 | // ADC-Takt max. 14MHz, hier 72MHz / 6 = 12MHz
|
49 | RCC_ADCCLKConfig(RCC_PCLK2_Div6);
|
50 |
|
51 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
|
52 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1,ENABLE);
|
53 |
|
54 | GPIO_InitStructure.GPIO_Pin = POTI_UPDWN_Pin;
|
55 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
56 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
57 | GPIO_Init(POTI_UPDWN_GPIO,&GPIO_InitStructure);
|
58 |
|
59 | ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
60 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
61 | ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigInjecConv_None;
|
62 | ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
63 | ADC_InitStructure.ADC_NbrOfChannel = 1;
|
64 | ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
65 | ADC_Init(ADC1,&ADC_InitStructure);
|
66 |
|
67 | ADC_RegularChannelConfig(ADC1,POTI_UPDWM_ADCCH,1,ADC_SampleTime_1Cycles5);
|
68 |
|
69 | ADC_Cmd(ADC1,ENABLE);
|
70 |
|
71 | ADC_SoftwareStartConvCmd(ADC1,ENABLE);
|
72 |
|
73 | adc_calib(ADC1);
|
74 |
|
75 | printf_P(PSTR("\fADC Test Poti 1 \n\a"));
|
76 |
|
77 | // Kann als Dauerschleife angesehen werden
|
78 | while(!key_getstroke()) {
|
79 |
|
80 | value = ADC_GetConversionValue(ADC1);
|
81 | glcd_setpos(128);
|
82 | printf_P(PSTR("val=%6i\a"),value);
|
83 | delay_us(100);
|
84 | }
|
85 | printf_P(PSTR("\b\b\b\bdone. \a"));
|
86 |
|
87 |
|
88 | return;
|
89 |
|
90 | error:
|
91 |
|
92 | printf_P(PSTR("\nError \a"));
|
93 | while(!key_getstroke());
|
94 | } // end function
|