1 | void Config_Timer_TIM2(TIM_TimeBaseInitTypeDef *TIM_TimeBaseStructure, NVIC_InitTypeDef *NVIC_InitStructure)
|
2 | {
|
3 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
4 |
|
5 |
|
6 | /* Enable the Timer2 Interrupt */
|
7 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
8 |
|
9 | NVIC_InitStructure->NVIC_IRQChannel = TIM2_IRQn; // configure the Timer2 interrupts
|
10 | NVIC_InitStructure->NVIC_IRQChannelPreemptionPriority = 0x0F; // sets the priority group of the TIMER2 interrupts
|
11 | NVIC_InitStructure->NVIC_IRQChannelSubPriority = 0; // set the subpriority inside the group
|
12 | NVIC_InitStructure->NVIC_IRQChannelCmd = ENABLE; // TIMER2 interrupts are globally enabled
|
13 | NVIC_Init(NVIC_InitStructure);
|
14 |
|
15 | /* Configure Timer which is every 1 ms active*/
|
16 | TIM_DeInit(TIM2);
|
17 | TIM_TimeBaseStructInit(TIM_TimeBaseStructure);
|
18 |
|
19 | /* Time base configuration */
|
20 | TIM_TimeBaseStructure->TIM_Prescaler = 360 - 1; // 72 MHz / 360 = 200 khz
|
21 | TIM_TimeBaseStructure->TIM_Period = 200 - 1; // (1/200khz) * 200 = 1 ms;
|
22 | TIM_TimeBaseStructure->TIM_ClockDivision = TIM_CKD_DIV1;
|
23 | TIM_TimeBaseStructure->TIM_CounterMode = TIM_CounterMode_Up;
|
24 | TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure);
|
25 |
|
26 | //TIM_PrescalerConfig(TIM2, 360-1 , TIM_PSCReloadMode_Immediate);
|
27 |
|
28 | /* Enable TIM2 Update Interrupt */
|
29 | TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
30 |
|
31 | /* Enable TIM2 */
|
32 | TIM_Cmd(TIM2,ENABLE);
|
33 | }
|
34 |
|
35 | void Config_Timer_TIM3(TIM_TimeBaseInitTypeDef *TIM_TimeBaseStructure, NVIC_InitTypeDef *NVIC_InitStructure)
|
36 | {
|
37 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
38 |
|
39 | /* Enable the Timer3 Interrupt */
|
40 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
41 |
|
42 | NVIC_InitStructure->NVIC_IRQChannel = TIM3_IRQn; // configure the Timer2 interrupts
|
43 | NVIC_InitStructure->NVIC_IRQChannelPreemptionPriority = 0 ; // sets the priority group of the TIMER2 interrupts
|
44 | NVIC_InitStructure->NVIC_IRQChannelSubPriority = 0; // set the subpriority inside the group
|
45 | NVIC_InitStructure->NVIC_IRQChannelCmd = ENABLE; // TIMER3 interrupts are globally enabled
|
46 | NVIC_Init(NVIC_InitStructure);
|
47 |
|
48 | /* Configure Timer which is every 5 ms active*/
|
49 | TIM_DeInit(TIM3);
|
50 | TIM_TimeBaseStructInit(TIM_TimeBaseStructure);
|
51 |
|
52 | /* Time base configuration */
|
53 | TIM_TimeBaseStructure->TIM_Prescaler = 1800 - 1; // 72 MHz / 1800 = 40 khz
|
54 | TIM_TimeBaseStructure->TIM_Period = 200 - 1; // (1/400khz) * 200 = 5 ms;
|
55 | TIM_TimeBaseStructure->TIM_ClockDivision = TIM_CKD_DIV1;
|
56 | TIM_TimeBaseStructure->TIM_CounterMode = TIM_CounterMode_Up;
|
57 | TIM_TimeBaseInit(TIM3, TIM_TimeBaseStructure);
|
58 |
|
59 | /* Enable TIM2 Update Interrupt */
|
60 | TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
|
61 |
|
62 |
|
63 |
|
64 | void TIM2_IRQHandler(void)
|
65 | {
|
66 |
|
67 | Display_Adc_Value(Line7,Black,Line3,Green,ADC1);
|
68 | Display_Adc_Value(Line8,Black,Line5,Blue,ADC2);
|
69 |
|
70 | TIM_ClearITPendingBit(TIM2, TIM_IT_Update); //Update Interrupt
|
71 | }
|
72 |
|
73 | void TIM3_IRQHandler(void)
|
74 | {
|
75 |
|
76 | UARTSend("CV", 1);
|
77 | // if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
|
78 | // {
|
79 | //
|
80 | // }
|
81 | TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //Update Interrupt
|
82 | }
|