Forum: Mikrocontroller und Digitale Elektronik Puls funktioniert nur für einen Kanal


von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo

Ich habe gerade einen wiederholten Puls generiert und diesen erfolgreich 
getestet. Für weitere Kanäle habe ich dann das Programm erweitert.
Wenn ich jetzt das Oszilloskop an die jeweiligen Pins anschliesse, 
bekomme ich kein Signal heraus. Könnte mir jemand sagen, was ich mit der 
Erweiterung des Codes nicht berücksichtigt habe?
Vielen Dank schon mal

Hier ist der Code:
Die Erweiterung betrifft
/* Configure register bits for Channel 2*/
bis
/* Configure register bits for Channel 4*/
1
void initTimer1(uint8_t Presc, uint8_t period, uint16_t PulseN){
2
   
3
      /* Configure register bits for Channel 1*/
4
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1M;                /* Reset bits of OC1M register*/
5
   TIM1->CCER = TIM_CCER_CC1E;                              /* Enable the Compare output channel 1 */
6
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S;                /* Set CC1 as output */
7
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC1P;                  /* Reset CC1P register */
8
   
9
     /* Configure register bits for Channel 2*/
10
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2M;                /* Reset bits of OC2M register*/
11
   TIM1->CCER |= TIM_CCER_CC2E;                             /* Enable the Compare output channel 2 */
12
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC2S;                /* Set CC2 as output */
13
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC2P;                  /* Reset CC2P register */
14
   
15
     /* Configure register bits for Channel 3*/
16
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3M;                /* Reset bits of OC3M register*/
17
   TIM1->CCER |= TIM_CCER_CC3E;                             /* Enable the Compare output channel 3 */
18
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC3S;                /* Set CC3 as output */
19
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC3P;                  /* Reset CC3P register */
20
   
21
     /* Configure register bits for Channel 4*/
22
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4M;                /* Reset bits of OC4M register*/
23
   TIM1->CCER |= TIM_CCER_CC4E;                             /* Enable the Compare output channel 4 */
24
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC4S;                /* Set CC4 as output */
25
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC4P;                  /* Reset CC4P register */
26
   
27
   /* General configuration for all Timer 1 Channels 1-4*/
28
   RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;                      /* Peripheral clock enable */ 
29
   TIM1->CCMR1 |= TIM_OCMODE_PWM2;                          /* OCx is high until CCRx */   
30
   TIM1->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);               /* Reset bits of CMS (Edge-aligned mode) and DIR generally */
31
   TIM1->CR1 |= TIM_COUNTERMODE_UP;                         /* Select the up counter mode */
32
   TIM1->CR1 &= ~TIM_CR1_CKD;                               /* Erase bits of CKD */
33
   TIM1->CR1 |= TIM_CLOCKDIVISION_DIV1;                     /* Set the clock division to 1*/
34
   TIM1->PSC = Presc;                                       /* Set the Prescaler value */
35
   TIM1->ARR = period - 1;                                  /* Set the Auto-reload value*/
36
   TIM1->RCR = PulseN - 1;                                  /* Set the repetition counter value*/
37
   TIM1->CCR1 = period/2;                                   /* Set the compare value channel 1*/
38
   TIM1->EGR = TIM_EGR_UG;                                  /* Generate an update event to reload Prescaler and Repetition counter value immediately*/
39
   TIM1->CR1 |= TIM_CR1_OPM;                                /* Activate the one pulse mode*/
40
   TIM1->CCER |= TIM_OCPOLARITY_HIGH;                       /* Set the Output Compare Polarity to High */
41
   TIM1->SMCR = RESET;                                      /* Configure the Internal Clock Source*/
42
   TIM1->BDTR |= TIM_BDTR_MOE;                              /* Enable the TIM main Output */
43
   
44
}

: Bearbeitet durch User
von Sascha W. (sascha-w)


Lesenswert?

Hallo,

es wäre ja genial wenn du verraten würdest um was für einen Controller 
es sich handelt.

Sascha

von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo Sascha

Sorry ich habe das total vergessen voller Konzentration auf die Aufgabe.
Es ist das Nucleo L476RG.

von Matthias S. (Firma: matzetronics) (mschoeldgen)


Lesenswert?

Das ist ein STM32.
Ich vermisse allerdings die Pinkonfiguration. Dort ist es nötig, die 
Alternativfunktion für alle benutzten PWM Pins zu setzen.

von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo Matthias

Ich habe die Pinkonfiguration schon als Alternativfunktion drin.
Es funktioniert ja für CH1 auch, also muss das schon passen, zumal ich 
die Konfiguration über CubeMx gemacht habe.

Aber trotzdem zur Info:
Ich habe den Timer1 CH1-4 als Output Compare drin.

und der Code für die Pinkonfiguration folgendermassen:
(was ich mich allerdings frage ist, warum ich hier die Definitionen für 
PinA8, A9, A10 und A11 für die Timer CH1-4 nirgends als alternative 
Funktionen sehe??
Kann mir einer erklären warum bzw. wo das geschieht?
1
static void MX_GPIO_Init(void)
2
{
3
4
  GPIO_InitTypeDef GPIO_InitStruct;
5
6
  /* GPIO Ports Clock Enable */
7
  __HAL_RCC_GPIOC_CLK_ENABLE();
8
  __HAL_RCC_GPIOA_CLK_ENABLE();
9
10
  /*Configure GPIO pin Output Level */
11
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
12
13
  /*Configure GPIO pin : PC13 */
14
  GPIO_InitStruct.Pin = GPIO_PIN_13;
15
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
16
  GPIO_InitStruct.Pull = GPIO_NOPULL;
17
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
18
19
  /*Configure GPIO pin : PA0 */
20
  GPIO_InitStruct.Pin = GPIO_PIN_0;
21
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
22
  GPIO_InitStruct.Pull = GPIO_NOPULL;
23
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
24
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
25
26
  /*Configure GPIO pin : PC10 */
27
  GPIO_InitStruct.Pin = GPIO_PIN_10;
28
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
29
  GPIO_InitStruct.Pull = GPIO_NOPULL;
30
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
31
32
}
1
Edit: (schon gefunden: hier)
2
3
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
4
{
5
6
  GPIO_InitTypeDef GPIO_InitStruct;
7
  if(htim->Instance==TIM1)
8
  {
9
  /* USER CODE BEGIN TIM1_MspPostInit 0 */
10
11
  /* USER CODE END TIM1_MspPostInit 0 */
12
  
13
    /**TIM1 GPIO Configuration    
14
    PA8     ------> TIM1_CH1
15
    PA9     ------> TIM1_CH2
16
    PA10     ------> TIM1_CH3
17
    PA11     ------> TIM1_CH4 
18
    */
19
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11;
20
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
21
    GPIO_InitStruct.Pull = GPIO_NOPULL;
22
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
23
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
24
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
25
26
  /* USER CODE BEGIN TIM1_MspPostInit 1 */
27
28
  /* USER CODE END TIM1_MspPostInit 1 */
29
  }
30
31
}

: Bearbeitet durch User
von Hans-Georg L. (h-g-l)


Lesenswert?

Steht in deiner Main im Abschnitt usercode 2  ?

HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_1);
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_2);
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_3);
HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_4);

von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo Hans

Nein steht nur das initTimer1(); drin
Wenn ich die 4 Zeilen hinzufüge, geht nicht einmal mehr Kanal 1
1
void Enable_Counter_Timer1()
2
{
3
   if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 0) {
4
      
5
      TIM1->CR1 |= TIM_CR1_CEN; 
6
      
7
   }   
8
}
1
/* USER CODE END 0 */
2
3
int main(void)
4
{
5
6
  /* USER CODE BEGIN 1 */
7
8
  /* USER CODE END 1 */
9
10
  /* MCU Configuration----------------------------------------------------------*/
11
12
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
13
  HAL_Init();
14
15
  /* Configure the system clock */
16
  SystemClock_Config();
17
18
  /* Initialize all configured peripherals */
19
  MX_GPIO_Init();
20
  MX_TIM1_Init();
21
22
  /* USER CODE BEGIN 2 */
23
   
24
  User_Init_Timer1(0, 16, 1027);
25
26
  /* USER CODE END 2 */
27
28
  /* Infinite loop */
29
  /* USER CODE BEGIN WHILE */
30
  while (1)
31
  {
32
     
33
      Enable_Counter_Timer1();
34
     
35
  /* USER CODE END WHILE */
36
37
  /* USER CODE BEGIN 3 */
38
39
  }
40
  /* USER CODE END 3 */
41
42
}

Edit: Die Funktion initTimer1(); habe ich übrigens zu 
User_Init_Timer1(0, 16, 1027); umbenannt... nicht, dass sich jemand 
unnötig beschwert ;)

: Bearbeitet durch User
von Hans-Georg L. (h-g-l)


Lesenswert?

Also ich habe die Erfahrung gemacht, das man alle Kanäle extra starten 
muss

also wie angegeben mit der HAL funktion

HAL_TIM_OC_Start(&htim1,TIM_CHANNEL_X);



Oder 2. Möglichkeit

alle Kanäle freigeben

TIM1->CCER |= TIM_CCER_CC1E;
TIM1->CCER |= TIM_CCER_CC2E;
TIM1->CCER |= TIM_CCER_CC3E;
TIM1->CCER |= TIM_CCER_CC4E;

und dann Zähler starten

TIM1->CR1  |= TIM_CR1_CEN;


PWM läuft doch durch da must du nicht dauernd den timer in der while 
schleife neu starten ...

: Bearbeitet durch User
von Matthias S. (Firma: matzetronics) (mschoeldgen)


Lesenswert?

Ich sehe jetzt immer noch nicht, wo du die eigentlichen PWM Werte für 
die Kanäle setzt, also die Besetzung von TIM1->CCR1 bis TIM1->CCR4. Wenn 
da eine null drin steht, kommt da auch nix.
Wohlgemerkt musst du Preload freigeben, wenn du den Wert in CCRn nochmal 
ändern willst. Das passiert dann bei einem Update Event.

: Bearbeitet durch User
von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo Hans

Genau die 2. Möglichkeit mache ich ja immer jeweils in der 2. Zeile.
1
  /* Configure register bits for Channel 1*/
2
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1M;                /* Reset bits of OC1M register*/
3
   TIM1->CCER |= TIM_CCER_CC1E;                              /* Enable the Compare output channel 1 */
4
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S;                /* Set CC1 as output */
5
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC1P;                  /* Reset CC1P register */
6
   
7
     /* Configure register bits for Channel 2*/
8
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2M;                /* Reset bits of OC2M register*/
9
   TIM1->CCER |= TIM_CCER_CC2E;                             /* Enable the Compare output channel 2 */
10
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC2S;                /* Set CC2 as output */
11
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC2P;                  /* Reset CC2P register */
12
   
13
     /* Configure register bits for Channel 3*/
14
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3M;                /* Reset bits of OC3M register*/
15
   TIM1->CCER |= TIM_CCER_CC3E;                             /* Enable the Compare output channel 3 */
16
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC3S;                /* Set CC3 as output */
17
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC3P;                  /* Reset CC3P register */
18
   
19
     /* Configure register bits for Channel 4*/
20
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4M;                /* Reset bits of OC4M register*/
21
   TIM1->CCER |= TIM_CCER_CC4E;                             /* Enable the Compare output channel 4 */
22
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC4S;                /* Set CC4 as output */
23
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC4P;                  /* Reset CC4P register */

Den Counter Enable habe ich deshalb in der Schleife, weil ich diesen 
immer zum Testen über einen Schalter starten will.
Der Puls wird ja so oft wiederholt wie der Wert im Wiederholregister und 
dann wird CEN gestoppt.


@Matthias

Ich hätte jetzt gehofft, dass es das ist, wobei du Recht hast, ich muss 
ja die Compare values auch für die anderen Kanäle definieren.
Das habe ich jetzt auch angepasst, aber auch dann tut es nicht..
Ich bin langsam überfragt..
1
void User_Init_Timer1(uint8_t Presc, uint8_t period, uint16_t PulseN){
2
   
3
      /* Configure register bits for Channel 1*/
4
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1M;                /* Reset bits of OC1M register*/
5
   TIM1->CCER |= TIM_CCER_CC1E;                              /* Enable the Compare output channel 1 */
6
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S;                /* Set CC1 as output */
7
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC1P;                  /* Reset CC1P register */
8
   TIM1->CCR1 = period/2;                                   /* Set the compare value channel 1*/
9
   
10
     /* Configure register bits for Channel 2*/
11
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2M;                /* Reset bits of OC2M register*/
12
   TIM1->CCER |= TIM_CCER_CC2E;                             /* Enable the Compare output channel 2 */
13
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC2S;                /* Set CC2 as output */
14
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC2P;                  /* Reset CC2P register */
15
   TIM1->CCR2 = period/2;                                   /* Set the compare value channel 2*/
16
   
17
     /* Configure register bits for Channel 3*/
18
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3M;                /* Reset bits of OC3M register*/
19
   TIM1->CCER |= TIM_CCER_CC3E;                             /* Enable the Compare output channel 3 */
20
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC3S;                /* Set CC3 as output */
21
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC3P;                  /* Reset CC3P register */
22
   TIM1->CCR3 = period/2;                                   /* Set the compare value channel 3*/
23
   
24
     /* Configure register bits for Channel 4*/
25
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4M;                /* Reset bits of OC4M register*/
26
   TIM1->CCER |= TIM_CCER_CC4E;                             /* Enable the Compare output channel 4 */
27
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC4S;                /* Set CC4 as output */
28
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC4P;                  /* Reset CC4P register */
29
   TIM1->CCR4 = period/2;                                   /* Set the compare value channel 4*/
30
   
31
   /* General configuration for all Timer 1 Channels 1-4*/
32
   RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;                      /* Peripheral clock enable */ 
33
   TIM1->CCMR1 |= TIM_OCMODE_PWM2;                          /* OCx is high until CCRx */   
34
   TIM1->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);               /* Reset bits of CMS (Edge-aligned mode) and DIR generally */
35
   TIM1->CR1 |= TIM_COUNTERMODE_UP;                         /* Select the up counter mode */
36
   TIM1->CR1 &= ~TIM_CR1_CKD;                               /* Erase bits of CKD */
37
   TIM1->CR1 |= TIM_CLOCKDIVISION_DIV1;                     /* Set the clock division to 1*/
38
   TIM1->PSC = Presc;                                       /* Set the Prescaler value */
39
   TIM1->ARR = period - 1;                                  /* Set the Auto-reload value*/
40
   TIM1->RCR = PulseN - 1;                                  /* Set the repetition counter value*/
41
   TIM1->EGR = TIM_EGR_UG;                                  /* Generate an update event to reload Prescaler and Repetition counter value immediately*/
42
   TIM1->CR1 |= TIM_CR1_OPM;                                /* Activate the one pulse mode*/
43
   TIM1->CCER |= TIM_OCPOLARITY_HIGH;                       /* Set the Output Compare Polarity to High */
44
   TIM1->SMCR = RESET;                                      /* Configure the Internal Clock Source*/
45
   TIM1->BDTR |= TIM_BDTR_MOE;                              /* Enable the TIM main Output */
46
   
47
}

: Bearbeitet durch User
von D. I. (Firma: Fa) (buell)


Lesenswert?

Guten Morgen zusammen

Ich habe das Programm jeweils mit
TIM1->CCR1 = period/2;                                   /* Set the 
compare value channel 1*/
erweitert.

Es funktioniert für Kanal 1 weiterhin, aber für die anderen nicht.
Hat keiner eine Idee was am oberen Code nicht stimmen könnte?

PS: Wäre schön, wenn mir das mit dem Preload jemand erklären könnte. Im 
Reference Manual ist das für mich nicht so verständlich erklärt. Was tut 
der Preload denn genau? Es reicht doch wenn der Wert im CCR1-4 drin 
steht.

"Wohlgemerkt musst du Preload freigeben, wenn du den Wert in CCRn 
nochmal
ändern willst. Das passiert dann bei einem Update Event."

Schöne Grüsse

: Bearbeitet durch User
von Hans-Georg L. (h-g-l)


Lesenswert?

Schau dir doch einfach mit dem Debugger den Unterschied der Register von 
Kanal 1 zu den anderen an ...

von D. I. (Firma: Fa) (buell)


Lesenswert?

Hallo Hans

Super Tipp, danke.
Ich habe jetzt das Problem raus. Ich habe mit dem Befehl

TIM1->CCMR1 |= TIM_OCMODE_PWM2;                          /* OC1 is high 
until CCR1 */

den PWM2 Mode für den Kanal 1 gesetzt. Das fehlt nun für all die übrigen 
Kanäle und war im vorigen Code nicht enthalten. Ich hätte mich als ich 
im Manual las, mich auch direkt fragen können, warum das nicht variiert 
und kanalabhängig ist, aber ich meine wie soll ich das auch sehen wenn 
im stm32l4xx_hal_tim.h lediglich die Definition für den Kanal 1 drin 
ist?
So bin ich nicht sofort auf die Idee gekommen auch für die anderen 
Kanäle den PWM2 Mode zu setzen.

1
/** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM Modes
2
  * @{
3
  */
4
#define TIM_OCMODE_TIMING                   ((uint32_t)0x0000)
5
#define TIM_OCMODE_ACTIVE                   ((uint32_t)TIM_CCMR1_OC1M_0)
6
#define TIM_OCMODE_INACTIVE                 ((uint32_t)TIM_CCMR1_OC1M_1)
7
#define TIM_OCMODE_TOGGLE                   ((uint32_t)TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0)
8
#define TIM_OCMODE_PWM1                     ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1)
9
#define TIM_OCMODE_PWM2                     ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0)
10
#define TIM_OCMODE_FORCED_ACTIVE            ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0)
11
#define TIM_OCMODE_FORCED_INACTIVE          ((uint32_t)TIM_CCMR1_OC1M_2)


Ich hätte jetzt das #define TIM_OCMODE_PWM2 zu #define 
TIM_OCMODE_PWM2_CH1 gemacht und die restlichen definiert..
TIM_OCMODE_PWM2_CH2 dann als #define TIM_OCMODE_PWM2_CH2 
((uint32_t)TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_0) etc. 
defnieren.

Sprich so:
1
/* USER CODE BEGIN PV */
2
/* Private variables ---------------------------------------------------------*/
3
#define TIM_OCMODE_PWM2_CH1                      TIM_OCMODE_PWM2
4
#define TIM_OCMODE_PWM2_CH2                     ((uint32_t)TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_0)
5
#define TIM_OCMODE_PWM2_CH3                     ((uint32_t)TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0)
6
#define TIM_OCMODE_PWM2_CH4                     ((uint32_t)TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_0)
7
/* USER CODE END PV */
1
void User_Init_Timer1(uint8_t Presc, uint8_t period, uint16_t PulseN){
2
   
3
      /* Configure register bits for Channel 1*/
4
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1M;                /* Reset bits of OC1M register*/
5
   TIM1->CCER |= TIM_CCER_CC1E;                             /* Enable the Compare output channel 1 */
6
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S;                /* Set CC1 as output */
7
   TIM1->CCMR1 |= TIM_OCMODE_PWM2;                          /* OC1 is high until CCR1 */  
8
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC1P;                  /* Reset CC1P register */
9
   TIM1->CCR1 = period/2;                                   /* Set the compare value channel 1*/
10
   
11
   
12
     /* Configure register bits for Channel 2*/
13
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2M;                /* Reset bits of OC2M register*/
14
   TIM1->CCER |= TIM_CCER_CC2E;                             /* Enable the Compare output channel 2 */
15
   TIM1->CCMR1 &= (uint16_t)~TIM_CCMR1_CC2S;                /* Set CC2 as output */
16
   TIM1->CCMR1 |= TIM_OCMODE_PWM2_CH2;                      /* OC2 is high until CCR2 */ 
17
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC2P;                  /* Reset CC2P register */
18
   TIM1->CCR2 = period/2;                                   /* Set the compare value channel 2*/
19
   
20
   
21
     /* Configure register bits for Channel 3*/
22
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3M;                /* Reset bits of OC3M register*/
23
   TIM1->CCER |= TIM_CCER_CC3E;                             /* Enable the Compare output channel 3 */
24
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC3S;                /* Set CC3 as output */
25
   TIM1->CCMR2 |= TIM_OCMODE_PWM2_CH3;                      /* OC2 is high until CCR2 */ 
26
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC3P;                  /* Reset CC3P register */
27
   TIM1->CCR3 = period/2;                                   /* Set the compare value channel 3*/
28
   
29
     /* Configure register bits for Channel 4*/
30
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4M;                /* Reset bits of OC4M register*/
31
   TIM1->CCER |= TIM_CCER_CC4E;                             /* Enable the Compare output channel 4 */
32
   TIM1->CCMR2 &= (uint16_t)~TIM_CCMR2_CC4S;                /* Set CC4 as output */
33
   TIM1->CCMR2 |= TIM_OCMODE_PWM2_CH4;                      /* OC2 is high until CCR2 */ 
34
   TIM1->CCER &= (uint16_t)~TIM_CCER_CC4P;                  /* Reset CC4P register */
35
   TIM1->CCR4 = period/2;                                   /* Set the compare value channel 4*/
36
   
37
     /* General configuration for all Timer 1 Channels 1-4*/
38
   RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;                      /* Peripheral clock enable */  
39
   TIM1->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);               /* Reset bits of CMS (Edge-aligned mode) and DIR generally */
40
   TIM1->CR1 |= TIM_COUNTERMODE_UP;                         /* Select the up counter mode */
41
   TIM1->CR1 &= ~TIM_CR1_CKD;                               /* Erase bits of CKD */
42
   TIM1->CR1 |= TIM_CLOCKDIVISION_DIV1;                     /* Set the clock division to 1*/
43
   TIM1->PSC = Presc;                                       /* Set the Prescaler value */
44
   TIM1->ARR = period - 1;                                  /* Set the Auto-reload value*/
45
   TIM1->RCR = PulseN - 1;                                  /* Set the repetition counter value*/
46
   TIM1->EGR = TIM_EGR_UG;                                  /* Generate an update event to reload Prescaler and Repetition counter value immediately*/
47
   TIM1->CR1 |= TIM_CR1_OPM;                                /* Activate the one pulse mode*/
48
   TIM1->CCER |= TIM_OCPOLARITY_HIGH;                       /* Set the Output Compare Polarity to High */
49
   TIM1->SMCR = RESET;                                      /* Configure the Internal Clock Source*/
50
   TIM1->BDTR |= TIM_BDTR_MOE;                              /* Enable the TIM main Output */
51
   
52
}

Dann funktionierts, aber bei der nächsten Anpassung mittels einer neuen 
Codegeneration würde es mir alles wieder löschen.
Wie würdet ihr das machen? Und in welchem Teil fügt man im main defines 
hin. Ich habe das im Moment ja wie man sieht im private variables, aber 
das macht ja keinen Sinn.

Schöne Grüsse

: Bearbeitet durch User
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.