際際滷

際際滷Share a Scribd company logo
GlobalLogic
Embedded Starter
Kit
Timers and PWM
Training 03
Bare Metal
Trainings
Contents
 Assignments and Goals
 Theory
 Practice
 Individual task
19.10.2020 15:13 Bare Metal  Training 03 2
Assignments and Goals
 Learn about clock control
 Create firmware that generate 1Hz signal
 Create firmware that works with Timers to
generate signals
 Create firmware that generate PWM signal
with predefined duty cycle
19.10.2020 15:13 Bare Metal  Training 03 3
Clock control diagram
19.10.2020 15:13 Bare Metal  Training 03 4
Clock control settings
19.10.2020 15:13 Bare Metal  Training 03 5
Clock control settings
19.10.2020 15:13 Bare Metal  Training 03 6
Create FW that generates 1Hz signal
19.10.2020 15:13 Bare Metal  Training 03 7
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
Create FW that generates 1Hz signal
19.10.2020 15:13 Bare Metal  Training 03 8
Timers
19.10.2020 15:13 Bare Metal  Training 03 9
Timer4 diagram
19.10.2020 15:13 Bare Metal  Training 03 10
Create FW that work with Timer4
19.10.2020 15:13 Bare Metal  Training 03 11
Create FW that work with Timer4
19.10.2020 15:13 Bare Metal  Training 03 12
Create FW that work with Timer4
19.10.2020 15:13 Bare Metal  Training 03 13
In main()
{
HAL_TIM_Base_Start_IT(&htim4);
while (1) {}
}
void TIM4_IRQHandler(void)
{ /* USER CODE BEGIN TIM4_IRQn 0 */
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);
/* USER CODE END TIM4_IRQn 0 */
HAL_TIM_IRQHandler(&htim4);
/* USER CODE BEGIN TIM4_IRQn 1 */
/* USER CODE END TIM4_IRQn 1 */
}
Create FW that work with Timer4
19.10.2020 15:13 Bare Metal  Training 03 14
Create FW that work with PWM
19.10.2020 15:13 Bare Metal  Training 03 15
Create FW that work with PWM
19.10.2020 15:13 Bare Metal  Training 03 16
In main()
{
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
TIM4->CCR3=100;
while (1)
{}
}
Create FW that work with PWM
19.10.2020 15:13 Bare Metal  Training 03 17
Individual task
 Enable 4 PWMs to control LEDs
(PD15, PD14, PD13, PD12)
 Blink LED without interrupts and main loop
(by timer HW)
 Fade In/Out LEDs with help of buttons
(or automatically by algorithm)
19.10.2020 15:13 Bare Metal  Training 03 18

More Related Content

Bare metal training_03_timers_pwm

  • 1. GlobalLogic Embedded Starter Kit Timers and PWM Training 03 Bare Metal Trainings
  • 2. Contents Assignments and Goals Theory Practice Individual task 19.10.2020 15:13 Bare Metal Training 03 2
  • 3. Assignments and Goals Learn about clock control Create firmware that generate 1Hz signal Create firmware that works with Timers to generate signals Create firmware that generate PWM signal with predefined duty cycle 19.10.2020 15:13 Bare Metal Training 03 3
  • 4. Clock control diagram 19.10.2020 15:13 Bare Metal Training 03 4
  • 5. Clock control settings 19.10.2020 15:13 Bare Metal Training 03 5
  • 6. Clock control settings 19.10.2020 15:13 Bare Metal Training 03 6
  • 7. Create FW that generates 1Hz signal 19.10.2020 15:13 Bare Metal Training 03 7 /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { HAL_Delay(500); HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */
  • 8. Create FW that generates 1Hz signal 19.10.2020 15:13 Bare Metal Training 03 8
  • 9. Timers 19.10.2020 15:13 Bare Metal Training 03 9
  • 10. Timer4 diagram 19.10.2020 15:13 Bare Metal Training 03 10
  • 11. Create FW that work with Timer4 19.10.2020 15:13 Bare Metal Training 03 11
  • 12. Create FW that work with Timer4 19.10.2020 15:13 Bare Metal Training 03 12
  • 13. Create FW that work with Timer4 19.10.2020 15:13 Bare Metal Training 03 13 In main() { HAL_TIM_Base_Start_IT(&htim4); while (1) {} } void TIM4_IRQHandler(void) { /* USER CODE BEGIN TIM4_IRQn 0 */ HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15); /* USER CODE END TIM4_IRQn 0 */ HAL_TIM_IRQHandler(&htim4); /* USER CODE BEGIN TIM4_IRQn 1 */ /* USER CODE END TIM4_IRQn 1 */ }
  • 14. Create FW that work with Timer4 19.10.2020 15:13 Bare Metal Training 03 14
  • 15. Create FW that work with PWM 19.10.2020 15:13 Bare Metal Training 03 15
  • 16. Create FW that work with PWM 19.10.2020 15:13 Bare Metal Training 03 16 In main() { HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); TIM4->CCR3=100; while (1) {} }
  • 17. Create FW that work with PWM 19.10.2020 15:13 Bare Metal Training 03 17
  • 18. Individual task Enable 4 PWMs to control LEDs (PD15, PD14, PD13, PD12) Blink LED without interrupts and main loop (by timer HW) Fade In/Out LEDs with help of buttons (or automatically by algorithm) 19.10.2020 15:13 Bare Metal Training 03 18