Hallo zusammen
Ich habe gerade ein neues Problem und zwar möchte ich den timer 15 mit
einem TriggerSignal starten, bei dem ein Signal im Kanal 2 dann
möglichst mit wenig Verzögerung (fast mode enabled) high geht.
Ich möchte dabei einen einzigen Puls bestimmter Länge.
Ich bin so vorgegangen, dass ich zuerst die GPIO Definition vorgenommen
und dann die Base Konfiguration des Timers festgelegt habe.
Daduch, dass ich das Minimum Delay möchte,
enable ich nur den Timer15 Clock
und defniere die Periode im ARR
Den Compare Wert lasse ich weg, da dieser nicht gebraucht wird
Den Repetition Counter lasse ich auch weg, wird nicht gebraucht.
wähle die Clock division= 1;
und den Prescaler = 0;
dann wähle ich Trigger Mode (SMS) und wähle den Trigger (TS) im SMCR
setze das OPM bit für one pulse
und setze das UG bit
dann fehlen noch die Polarität OC2P für rising edge,
den Kanal auf Ausgang-> OC2S
und wähle PWM mode 2 -> Sprung von 0 auf 1.
Das Enable Bit CC2E setze ich später per Software.
Jetzt müsste es doch eigentlich tun, ich kann aber nichts messen.
Es tut weder per Timerstart mittels Software noch per high Signal auf
PB15. Was stimmt da nicht?
Code:
1 | void Init_Timer15(uint8_t Presc, uint16_t period)
|
2 | {
|
3 |
|
4 |
|
5 | /**TIM1 GPIO Configuration */
|
6 |
|
7 | /* GPIO Ports Clock Enable */
|
8 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
9 |
|
10 |
|
11 | GPIO_InitTypeDef GPIO_InitStruct;
|
12 | /**
|
13 | PB14 ------> TIM15_CH1 External Trigger function
|
14 | PB15 ------> TIM15_CH2
|
15 |
|
16 | */
|
17 | GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
|
18 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
19 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
20 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
21 | GPIO_InitStruct.Alternate = GPIO_AF14_TIM15;
|
22 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
23 |
|
24 |
|
25 | /* Timer configuration */
|
26 | /* Configure register bits for Channel 2*/
|
27 | TIM15->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2M; /* Ensure bits of OC2M are cleared*/
|
28 | TIM15->CCMR1 &= (uint16_t)~TIM_CCMR1_CC2S; /* Set CC2 as output */
|
29 | TIM15->CCMR1 |= TIM_OCMODE_PWM2_CH2; /* OC2 is low until CCR2, with PWM mode 2 the polarity is set*/
|
30 | TIM15->CCER &= (uint16_t)~TIM_CCER_CC2P; /* Reset CC2P register for detection rising edge - TI1F_ED*/
|
31 |
|
32 | TIM15->CCMR1 |= TIM_CCMR1_OC2FE; /* Enable the fast mode for minimum delay after Trigger*/
|
33 |
|
34 |
|
35 | /* General configuration for all Timer 15 Channels 1-4*/
|
36 | RCC->APB2ENR |= RCC_APB2ENR_TIM15EN; /* Peripheral clock enable */
|
37 | TIM15->SMCR &= ~TIM_SMCR_SMS; /* Clear SMS before setting TS bits */
|
38 | TIM15->SMCR |= TIM_SMCR_TS_2; /* Trigger selection TI1F_ED - Filtered Timer Input 1*/
|
39 | TIM15->SMCR |= TIM_SMCR_SMS_1 | TIM_SMCR_SMS_2; /* Slave mode selection - Trigger mode is selected */
|
40 |
|
41 | /* Timer15 base unit configuration*/
|
42 | TIM15->CR1 &= ~TIM_CR1_CKD; /* Set CKD -> clock division to 1 */
|
43 | TIM15->PSC = Presc; /* Set the Prescaler value */
|
44 | TIM15->ARR = period - 1; /* Set the Auto-reload value*/
|
45 | TIM15->EGR |= TIM_EGR_UG; /* Generate an update event to reload Prescaler and Repetition counter value immediately*/
|
46 | TIM15->CR1 |= TIM_CR1_OPM; /* Activate the one pulse mode*/
|
47 | }
|