Hallo,
ich habe einen Code Programmiert, der es mir erlauben soll, ein PWM
Signal erzeugen soll.
Es klappt auch, aber das Verhältnis zwischen High (Duty Cycle) und Low
Phase ist entgegen dem, was ich erwartet habe. Ich verstehe nicht
wieso...
Hier der Code:
######################################################################
######################################################################
1 | #include <stdint.h>
|
2 | #include <stdbool.h>
|
3 | #include "stm32f446xx.h"
|
4 | #include "system_stm32f4xx.h"
|
5 | #define GPIO_PIN_15_ALS_AF1 (1U) << 28
|
6 |
|
7 | int main(void)
|
8 | {
|
9 | // Initialisierungen
|
10 |
|
11 | // Konfiguration der GPIO A
|
12 | RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
13 | GPIOA->MODER |= GPIO_MODER_MODER15_1;
|
14 | GPIOA->AFR[1] |= GPIO_PIN_15_ALS_AF1;
|
15 |
|
16 | // Konfiguration des Timers2
|
17 | RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
18 |
|
19 | // TIM2: Kanal 1 = Output
|
20 | TIM2->CCMR1 &= ~(TIM_CCMR1_CC1S_Msk);
|
21 |
|
22 | // TIM2: Kanal 1 = PWM-Output
|
23 | TIM2->CCMR1 |= TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2;
|
24 |
|
25 | // Aktiviere Preload-Funktion
|
26 | TIM2->CCMR1 |= TIM_CCMR1_OC1PE;
|
27 |
|
28 | TIM2->CCER |= TIM_CCER_CC1E;
|
29 | TIM2->CCER &= ~(TIM_CCER_CC1P); // active High
|
30 |
|
31 | // Starten / Aktivieren des Timers
|
32 | TIM2->CR1 |= TIM_CR1_CEN;
|
33 |
|
34 | // Einstellung des PreScalers des Timer2
|
35 | TIM2->PSC = (1600 - 1);
|
36 |
|
37 | TIM2->ARR = (200 - 1);
|
38 |
|
39 | TIM2->CCR1 = 21;
|
40 |
|
41 | // --> Der Timer wird auf 0 gestellt (resettet)
|
42 | TIM2->CNT = 0;
|
43 |
|
44 | /* Loop forever */
|
45 | while (1)
|
46 | {
|
47 | // Do nothing
|
48 | }
|
49 |
|
50 | return 0;
|
51 | }
|
######################################################################
######################################################################
Kann mir da einer helfen?
Danke.
schöne Grüße