ECE471/571 (RTOS) STM32 C Example - Hardware PWM

In STM32CubeMX

  1. Initialize all peripherals with in default mode? - yes
  2. find PB0, PB7, PB14, PC13
  3. find TIM3 - Timer3
  4. disable Ethernet (optional)
  5. disable USB_OTG_FS (optional)

Adapt and compile a project (example 1)

  1. Open source/main.c
  2. Locate int main() function
  3. Inspect the GPIO initialization called from main()
  4. Locate the timer initialization in main()
  5. Insert your code ** HERE **
      MX_TIM3_Init();
      ...
      /* USER CODE BEGIN 2 */
          ** HERE **
      /* USER CODE END 2 */
    
  6. Code to start the hardware-based PWM generation on channel 3. Each channel had to be started individually.
      HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
      TIM3->CCR3 = 500; // 0 - 2000, as the period in CubeMX was set to 2000 count)
    
  7. Open source/main.c
  8. Locate int main() function
  9. Inspect the GPIO initialization called from main()
  10. Locate the forever loop in main()
  11. Insert your code ** HERE **
        /* USER CODE BEGIN WHILE */
        while (1)
        {
        /* USER CODE END WHILE */
    
        /* USER CODE BEGIN 3 */
            ** HERE **
      }
      /* USER CODE END 3 */
    
  12. Code for the main loop to demonstrate how to change the PWM rate
        for (uint32_t coef=0; coef<2000; coef=coef+100 )
        {
          TIM3->CCR3 = coef;
          HAL_Delay(100);
        }
    

web site front local main page local list page general bookmarks software bookmarks go back copyright info