Skip to main content
abodi.1
Associate II
April 11, 2023
Solved

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

..

    This topic has been closed for replies.
    Pavel A.
    Pavel A.Best answer
    April 11, 2023

    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 */
    }

    10 replies

    waclawek.jan
    Super User
    April 11, 2023

    TIM1->CCR2 = value;

    JW

    abodi.1
    abodi.1Author
    Associate II
    April 11, 2023
    @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.
    Pavel A.Best answer
    April 11, 2023

    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 */
    }

    abodi.1
    abodi.1Author
    Associate II
    April 11, 2023

    @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)

    waclawek.jan
    Super User
    April 11, 2023

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

    JW

    abodi.1
    abodi.1Author
    Associate II
    April 11, 2023

    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 */

     }

    Tesla DeLorean
    Guru
    April 11, 2023

    That's probably unnecessarily frequent.

    Perhaps hold in a variable and check if it changes.

    Ideally if the board has access to a USART or serial data you could make something interactive rather than stopping in the debugger.

    Or if the board has a potentiometer you could read an angle from that using an ADC channel.​

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..