1 | static void TIM_Configuration(void) {
|
2 |
|
3 |
|
4 | RCC_ClocksTypeDef RCC_Clocks;
|
5 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
6 | TIM_OCInitTypeDef TIM_OCInitStructure;
|
7 | TIM_ICInitTypeDef TIM_ICInitStructure;
|
8 |
|
9 | SystemInit();
|
10 |
|
11 | RCC_GetClocksFreq(&RCC_Clocks);
|
12 |
|
13 | /* SystTick configuration: an interrupt every 10ms */
|
14 | SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100);
|
15 |
|
16 | /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
|
17 | /* The Localtime should be updated during the Ethernet packets processing */
|
18 | NVIC_SetPriority(SysTick_IRQn, 1);
|
19 |
|
20 | /* TIM 2 configuration: --> ? Hz ------------------------------------------------------------------ */
|
21 |
|
22 | /* Time base configuration */
|
23 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
24 | TIM_TimeBaseStructure.TIM_Period = 1000 - 1;
|
25 | TIM_TimeBaseStructure.TIM_Prescaler = 72000000 / 1000 - 1;
|
26 | TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
27 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
28 | TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
29 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
|
30 |
|
31 | /* Master Configuration in PWM1 Mode */
|
32 | TIM_OCStructInit(&TIM_OCInitStructure);
|
33 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
|
34 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
35 | TIM_OCInitStructure.TIM_Pulse = 100;
|
36 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
|
37 | TIM_OC2Init(TIM2, &TIM_OCInitStructure); /* Channel 2 */
|
38 |
|
39 | // // TODO: wird dies benötigt?
|
40 | // TIM_OC2FastConfig(TIM2, TIM_OCFast_Enable);
|
41 |
|
42 | TIM_ICStructInit(&TIM_ICInitStructure); /* TIM Input Capture Init structure definition */
|
43 | TIM_SelectOnePulseMode(TIM2, TIM_OPMode_Single); /* One Pulse Mode selection */
|
44 |
|
45 | /* Slave Mode selection: TIM2 --> sync with ITR1 */
|
46 | TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Trigger); /* Slave Mode selection: Trigger Mode */
|
47 | TIM_SelectInputTrigger(TIM2, TIM_TS_ITR1); /* Input Trigger selection */
|
48 |
|
49 | /* Select the Master Slave Mode */
|
50 | TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
|
51 |
|
52 | /* Master Mode selection */
|
53 | TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_OC2Ref);
|
54 |
|
55 | /* TIM enable counter */
|
56 | TIM_Cmd(TIM2, ENABLE);
|
57 | }
|
58 |
|
59 |
|
60 | static void ADC_Configuration(void) {
|
61 |
|
62 | ADC_InitTypeDef ADC_InitStructure;
|
63 | /* Put everything back to power-on defaults */
|
64 | ADC_DeInit(ADC1);
|
65 |
|
66 | /* ADC1 configuration ------------------------------------------------------*/
|
67 | ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
68 | ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
69 | ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
70 | ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; // todo:
|
71 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
72 | ADC_InitStructure.ADC_NbrOfChannel = 1;
|
73 | ADC_Init(ADC1, &ADC_InitStructure);
|
74 |
|
75 | /* ADC1 regular channel14 configuration - ADC_Channel 4 = pin A4 --> Board PA3 (ADC12_IN4)*/
|
76 | ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_41Cycles5);
|
77 |
|
78 | /* Enable ADC1 DMA */
|
79 | ADC_DMACmd(ADC1, ENABLE);
|
80 |
|
81 | /* Enable ADC1 external trigger */
|
82 | ADC_ExternalTrigConvCmd(ADC1, ENABLE);
|
83 |
|
84 | /* Enable ADC1 */
|
85 | ADC_Cmd(ADC1, ENABLE);
|
86 |
|
87 | /* Enable ADC1 reset calibration register */
|
88 | ADC_ResetCalibration(ADC1);
|
89 | /* Check the end of ADC1 reset calibration register */
|
90 | while(ADC_GetResetCalibrationStatus(ADC1));
|
91 |
|
92 | /* Start ADC1 calibration */
|
93 | ADC_StartCalibration(ADC1);
|
94 | /* Check the end of ADC1 calibration */
|
95 | while(ADC_GetCalibrationStatus(ADC1));
|
96 |
|
97 | }
|