| Nano100BN Series BSP V3.03.002 The Board Support Package for Nano100BN Series

NuEdu-Basic01_Timer_Ouput_Capture.c
Go to the documentation of this file.
1 /****************************************************************************/
12 #include <stdio.h>
13 #include "NuEdu-Basic01_Timer_Ouput_Capture.h"
14
31 void Initial_Timer_port(void)
32 {
33
34
35 /* Set PB multi-function pins for TM2 external counter pins; TMR3 external capture pins */
36 SYS->GPB_MFP |= SYS_GPB_MFP_PB10_TM2 |SYS_GPB_MFP_PB3_T3EX;
37
38 /* Set ALT MPF settings for TMR0 ~ TMR3 external counter and capture functions */
39 SYS->ALT_MFP |= SYS_ALT_MFP_PB10_TM2|SYS_ALT_MFP_PB3_T3EX;
40
41 /* Set ALT MPF1 settings for TMR3 external capture */
42 SYS->ALT_MFP1 |= SYS_ALT_MFP1_PB3_T3EX;
43 }
44
49 void initial_Timer_Toggle(void)
50 {
51 /* Enable IP clock */
52
53 SYSCLK->APBCLK |= SYSCLK_APBCLK_TMR2_EN_Msk;
54
55 SYSCLK->CLKSEL1 |= SYSCLK_CLKSEL1_TMR2_HCLK;
56
57 /* Reset and stop , TIMER2 counting first */
58
59 _TIMER_RESET(TIMER2);
60
61 /* Configure TCMP values of TIMER0 and TIMER3 */
62 TIMER2->TCMPR = (__XTAL/1000); // For 1000Hz (Equal to 500Hz toggle rate)
63
64 /* Start TIMER0 counting and output T0 frequency - 500 Hz*/
65 TIMER2->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_MODE_TOGGLE | TIMER_TCSR_TDR_EN_Msk | TIMER_TCSR_PRESCALE(1);
66 }
67
72 void initial_Timer_count(void)
73 {
74 /* Enable IP clock */
75 SYSCLK->APBCLK |= SYSCLK_APBCLK_TMR2_EN_Msk;
76
77 SYSCLK->CLKSEL1 |= SYSCLK_CLKSEL1_TMR2_HCLK;
78
79 /* Reset and stop , TIMER2 counting first */
80
81 _TIMER_RESET(TIMER2);
82
83 /* Configure TCMP values of TIMER0 and TIMER3 */
84 TIMER2->TCMPR = (__XTAL/1000); // For 1000Hz (Equal to 500Hz toggle rate)
85
86 /* Start TIMER0 counting and output T0 frequency - 500 Hz*/
87 TIMER2->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_MODE_TOGGLE | TIMER_TCSR_TDR_EN_Msk |TIMER_TCSR_CTB_ENABLE | TIMER_TCSR_PRESCALE(1);
88 }
89
94 void initial_Timer_capture(void)
95 {
96 /* Enable IP clock */
97 SYSCLK->APBCLK |= SYSCLK_APBCLK_TMR3_EN_Msk;
98
99 SYSCLK->CLKSEL1 |= SYSCLK_CLKSEL1_TMR3_HCLK;
100
101 /* Reset and stop , TIMER2 counting first */
102
103 _TIMER_RESET(TIMER3);
104 /* Enable TIMER1 counter and capture function */
105 TIMER1->TCMPR = 0xFFFFFF;
106 TIMER1->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_IE_Msk | TIMER_TCSR_MODE_CONTINUOUS | TIMER_TCSR_CTB_ENABLE |
107 TIMER_TCSR_TDR_EN_Msk | TIMER_TCSR_PRESCALE(1);
108 TIMER1->TEXCON = TIMER_TEXCON_MODE_CAP | TIMER_TEXCON_TEXIEN_ENABLE | TIMER_TEXCON_TEXEN_ENABLE;
109 } /* end of group Nano130_Basic01_FUNCTIONS */
111 /* end of group NuEdu-SDK-Nano130_Basic01 */
113 /* end of group NANO100_Library */
TIMER2
#define TIMER2
Pointer to TIMER2 register structure.
Definition: Nano100Series.h:11671
initial_Timer_count
void initial_Timer_count(void)
This function is enable TM2 count.
Definition: NuEdu-Basic01_Timer_Ouput_Capture.c:72
NuEdu-Basic01_Timer_Ouput_Capture.h
TIMER3
#define TIMER3
Pointer to TIMER3 register structure.
Definition: Nano100Series.h:11672
TIMER1
#define TIMER1
Pointer to TIMER1 register structure.
Definition: Nano100Series.h:11670
initial_Timer_Toggle
void initial_Timer_Toggle(void)
This function is enable TM2 toggle.
Definition: NuEdu-Basic01_Timer_Ouput_Capture.c:49
Initial_Timer_port
void Initial_Timer_port(void)
This function is used to TM2 output and TMR3 capture function.
Definition: NuEdu-Basic01_Timer_Ouput_Capture.c:31
initial_Timer_capture
void initial_Timer_capture(void)
This function is enable TM3 Capture.
Definition: NuEdu-Basic01_Timer_Ouput_Capture.c:94
SYS
#define SYS
Pointer to SYS register structure.
Definition: Nano100Series.h:11692