2017-02-16 11:44 AM
// Configure timer 2
RCC_APB1ENR.TIM2EN = 1; TIM2_CR1.CEN = 0; TIM2_CR2.TI1S = 0; TIM2_PSC = ENCODER_TIM_PSC; TIM2_ARR = ENCODER_TIM_RELOAD; TIM2_CR1 |= 0x10;// Configure input capture
TIM2_CCMR1_Input |= 0x01; TIM2_CCER.CC1P = 0; TIM2_CCER.CC1NP = 0; TIM2_CCER.CC1E = 1; TIM2_DIER.CC1IE = 1;Question: how do I define input PC1 as TI1 for timer 2
thanks!
#period-measurementSolved! Go to Solution.
2017-02-16 11:49 AM
In GPIO. Select AF in GPIOC_MODER, and then look into the table in DS to find out which AF is TIM2 and set that into GPIOC_AFRL/AFRH (AFRL here).
2017-02-16 11:49 AM
In GPIO. Select AF in GPIOC_MODER, and then look into the table in DS to find out which AF is TIM2 and set that into GPIOC_AFRL/AFRH (AFRL here).
2017-02-18 11:39 AM
Gib Text oder eine Webadresse ein oder
https://translate.google.com/?tr=f&hl=de
.https://translate.google.com/?tr=t&hl=de
https://ssl.gstatic.com/translate/arrow_ltr.png
MEHR ÜBERSETZEN
Fehler bei der Übersetzung
Is working !
Many Thanks!
2017-02-20 10:48 AM
New problem, measuring unstable due to internal oscillator!
I want to use an external oscillator for Timer 2:
GPIO_Alternate_Function_Enable(&_GPIO_MODULE_TIM2_CH1_PA0); // Configure alternate function for A0 as Timer 2 Channel 1
TIM2_CCMR1_Input |= 0x01; // Set capture channel 1 as input on TI1 (CC1S = 01) TIM2_CCER.CC1P = 0; // Set capture on rising edge event TIM2_CCER.CC1NP = 0;Tim2_CCMR1_Input |= 0x100; // for Extern Clock - Set IC2 as input on TI2 (SS2S = 01)
TIM2_CCER.CC2P = 0; // Set Extern Clock rising edge event TIM2_CCER.CC2NP = 0; TIM2_SMCR.SMS = 0x111; // Set Timer External Clock Mode 1GPIOA_MODER|=0x800; // Port-A Pin-5 AF alternate Funktion mode
GPIOA_AFRL|=0x100000; // AF1 Port-A Pin-5 TIM2_CCER.CC1E = 1; // Enable capture on channel 1 TIM2_DIER.CC1IE = 1; // Enable interrupt on capture channel 1Have no idea how I can link TI2 to a physical input pin and whether the combination of Timer Capure Mode and external ckock is possible
2017-02-20 04:13 PM
To use CH2 of TIM2 as an external clock:
- don't enable another TIM2_CH1 pin (PA5)
- do enable as AF a TIM2_CH2 pin (e.g. PA1) and set it to AF1
- don't enable input capture for CH2 ( Tim2_CCMR1_Input |= 0x100;)
- select TI2FP2 (which is the filtered version of CH2, see timer's block diagram) as Slave Mode Input, TIMx_SMCR.TS= 0b110
- not 0x111 but 0b111 (if your compiler supports it, or simply 7) in TIM2_SMCR.SMS = 0x111; to select extern clock mode 1
JW