cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_OCActive example, setting TIM1 CH1 output pin PA8 to HI is visible for all four channels

Kmax18
Senior II

Hi, I implemented and tested the example TIM_OCActive, which is included in the  STM32Cube_FW_G0_V1.6.2 package, using a NUCLEO-G071RB and the STM32CubeIDE version 1.17.0.

As the trigger signal for the oscilloscope I generated a 10 ms wide pulse by adding lines 3 and 4 in the below code snippet.

Question: although the trigger pulse is written only to the TIM1 CH1 output (PA8), it appears for all four channels, as can be seen in the below oscilloscope screenshot. Please explain that. Thank you!

 

 

  /* Generate pulse (set/reset) TIM1 CH1 output pin as trigger
   * reference for the oscilloscope */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
  HAL_Delay(10);

  /*## Start signals generation ##*/

  /* Start channel 1 in Output compare mode */
  if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }

 

 

 

Kmax18_0-1735145572749.png

 

4 REPLIES 4

Do you see those pulses also if you remove the HAL_GPIO_WritePin() line, leaving just the delay?

JW

TDK
Guru

edit: misunderstood what was being asked.

 

If you feel a post has answered your question, please click "Accept as Solution".

Hello Jan, thank you for your response and question. I appreciate you taking the time for this.
The answer to your question is No., the pulses at channels 1-4 are not present without writing to PA8 (Ch1). Please see the three figures below for details.

  • Figure 1. The relevant code snippet and oscilloscope screenshot show the timer 1 signals WITH the 10 ms pulse written to PA8 only (Channel 1). However, the pulse is visible at all four channel outputs.
  • Figure 2 shows the code snippet from the original example WITHOUT writing to PA8, and without the 10 ms delay. However, the oscilloscope screenshot shows a 3.3V spike visible at all four channels. The reason for that is unknown. (One might speculate if that spike is caused by the channel 1 output and somehow affects channels 2, 3, 4.)
  • Figure 3 shows what you asked for: the code snippet from the original example WITHOUT writing to PA8, but WITH the 10 ms delay. The delay seems to prolong the 3.3V spike.

Is there an answer to my original question why writing to PA8 (CH1) affects all four channels?

 

Figure 1. Timer 1 signals WITH the 10 ms pulse added only to CH1.

Kmax18_1-1735393106788.png

Kmax18_0-1735392448627.png

Figure 2. Timer 1 signals WITHOUT the 10 ms pulse (original example code).

Kmax18_2-1735395925445.png

Kmax18_3-1735396035950.png

Figure 3.

Kmax18_5-1735396841941.png

Kmax18_4-1735396519237.png

 

 

 

> The answer to your question is No., the pulses at channels 1-4 are not present without writing to PA8 (Ch1).

Third figure looks to me much like Yes.

All 4 pins are at that point already set as AF in their respective GPIO_MODER register, so setting GPIO output level for any of them does nothing.

What you see is consequence of pins being set up with pullup. The timer outputs are not enabled yet at that point (by TIMx_CCER.CCxE and, as TIM1 is an Adcanced timer, also by TIMx_BDTR.MOE) - that comes only when you call HAL_TIM_OC_Start().

JW