Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work 🤝
Learn & Grow 📚
Contribute Experience & Expertise 🔧
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design 💡
Embedded Software 💻
Edge Networking
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

Trouble Generating PWM Signal on STM32 NUCLEO-F207ZG Using Low-Level Register Programming

I’m programming an STM32 NUCLEO-F207ZG board and trying to output a PWM signal on pin PE_9 (D6) to drive an LED. I’m using low-level register programming (no HAL/LL drivers). However, the LED is not responding, and I don’t see a PWM signal on the pin.

Here’s the code I’m using:

// Enable timer 1 clock
RCC->APB2ENR |= BIT0;

// Set output mode for PWM
TIM1->CCMR1 |= BIT5 | BIT6;

// Set period
TIM1->ARR = 0x0000FFFF;

// Set duty cycle
TIM1->CCR1 = 0x00007FFF;

// Enable preload
TIM1->CCMR1 |= BIT3;
TIM1->CR1 |= BIT7;

// Enable CC1 output
TIM1->CCER |= BIT0;

// Enable timer
TIM1->CR1 |= BIT0;

// Enable GPIOE clock
RCC->AHB1ENR |= BIT4;

// Configure PE_9 as alternate function
GPIOE->MODER |= BIT19;
GPIOE->AFR[1] |= BIT4;

I’ve reviewed the STM32 reference manual, datasheet, and application notes. Timer 1 and GPIOE clocks seem to be enabled, and PE_9 is in alternate function mode, though I’m unsure if AF1 (TIM1_CH1) is correctly set. The timer is configured for PWM output, but the prescaler is not set, and I’m uncertain if the timer clock is correct. I haven’t verified pin speed, output type, or pull-up/down resistors. Despite adjusting duty cycle and period, the LED remains unresponsive.

Am I missing any key register settings for Timer 1 or GPIOE? How can I confirm the correct alternate function for PE_9? Should I adjust the prescaler or check the timer clock frequency? Could GPIO configuration be affecting the LED? Any debugging tips, such as checking timer flags or using an oscilloscope, to verify the signal?

  1. Enthernet Code#0000

    To get your PWM signal working on the `STM32 NUCLEO-F207ZG` board, there are a few key things to check:

    – Set the Timer Prescaler

    – Correct Alternate Function for PE_9.

    – Re-check the GPIO settings for speed, output type (push-pull), and ensure there’s no pull-up/down resistor interfering with the signal.

    – Make sure the timer clock is correctly enabled and that you’re using the right PWM mode. Also, check if preload is enabled properly.

    @ifreakio

  2. Sterling#0000

    Thanks for the tips @enthernetcode .
    I’ll review the prescaler, PE_9 alternate function, and GPIO settings. Just to confirm, could a missing prescaler be causing the issue? Additionally, do my preload settings appear correct?

  3. Enthernet Code#0000

    You’re welcome @ifreakio
    Yes, the missing prescaler could indeed be contributing to the issue. Without setting the prescaler, the timer may be running too fast for the desired `PWM` frequency, resulting in no visible effect on the `LED`. Try setting an appropriate prescaler based on the system clock and the desired `PWM` frequency.

    As for the preload settings, you’ve enabled the preload for `TIM1` with the line `TIM1->CCMR1 |= BIT3;`. This looks correct, but ensure that you also enable the auto-reload preload if you want the `ARR` to be updated smoothly without glitches during operation. You can do this by setting the `ARPE` bit in `TIM1->CR1` (` TIM1->CR1 |= BIT7;`).

CONTRIBUTE TO THIS THREAD

Leaderboard

RANKED BY XP

All time
  • 1.
    Avatar
    @Nayel115
    1620 XP
  • 2.
    Avatar
    @UcGee
    650 XP
  • 3.
    Avatar
    @melta101
    600 XP
  • 4.
    Avatar
    @lifegochi
    250 XP
  • 5.
    Avatar
    @Youuce
    180 XP
  • 6.
    Avatar
    @hemalchevli
    170 XP