cancel
Showing results for 
Search instead for 
Did you mean: 

Hello all the community can you help me on the code that will give me access to vary the value of the pulse using a variable on the debugger thanks. For info the application is a PWM command with duty cycle

abodi.1
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Do this in your SysTick_Handler

/* Change this with the debugger: */
volatile uint32_t g_value = ..... ;
 
void SysTick_Handler(void)
{
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */
  TIM1->CCR = g_value;
  /* USER CODE END SysTick_IRQn 1 */
}

View solution in original post

10 REPLIES 10

TIM1->CCR2 = value;

JW

abodi.1
Associate II
@waclawek.jan
 
Thanks for your answer but with TIM1->CCR2 = value; I can't vary the duty cycle  directly on the debbogger. I always have to stop the program and change the value in the pluse and recompile again. 

Pavel A.
Evangelist III

Do this in your SysTick_Handler

/* Change this with the debugger: */
volatile uint32_t g_value = ..... ;
 
void SysTick_Handler(void)
{
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */
  TIM1->CCR = g_value;
  /* USER CODE END SysTick_IRQn 1 */
}

@Pavel A.​ I copied and pasted it on my program but it generated errors 

../Core/Src/main.c:109:6 : warning : 'SysTick_Handler' défini mais non utilisé [-Wunused-function]

 109 | void SysTick_Handler(void)

Well, in debugger, you don't need any code. Just write directly to TIM1->CCR2 in the peripheral registers view.

JW

I have to write it on my main code the wile loop

 while (1)

 {

  /* USER CODE END WHILE */

TIM1->CCR2=250;

  /* USER CODE BEGIN 3 */

 }

@pavel A.​ look


_legacyfs_online_stmicro_images_0693W00000bhsyxQAA.png

It complains about nonexistent TIM1->CCR - missing 2 in TIM1->CCR2.

JW

thank you there are more errors but I don't see where I have to vary the duty cycle