Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART controlled TIM in STM32F7

Status
Not open for further replies.

uranyumx

Advanced Member level 4
Joined
Mar 5, 2011
Messages
102
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,093
Hello,

I have a question about timer period control based on the received UART value. The code piece was attached to the thread. In the code, ModulationFreq value comes from UART receive. The problem is that I didn't get a signal update based on the ModulationFreq value. If you have any suggestions, I would appreciate it.

Thank you,

Code:
static void MX_TIM6_Init(void)
{
                /* USER CODE BEGIN TIM6_Init 0 */

                /* USER CODE END TIM6_Init 0 */
    if (ModulationFreq == 100)
    {

                TIM_MasterConfigTypeDef sMasterConfig = {0};

                /* USER CODE BEGIN TIM6_Init 1 */

                /* USER CODE END TIM6_Init 1 */
                htim6.Instance = TIM6;
                htim6.Init.Prescaler = 96-1;
                htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
                //htim6.Init.Period = (1000*(128*(ModulationFreq/2)))-1;
                htim6.Init.Period = 5000-1;
                
                // 96-1 Prescaler and 5000-1 Period equals = 100 Hz
                // 96-1 Prescaler and 10000-1 Period equals = 50 Hz
                // 96-1 Prescaler and 20000-1 Period equals = 25 Hz
                // 96-1 Prescaler and 50000-1 Period equals = 10 Hz
                
                htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
                if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
                {
                    Error_Handler();
                }
                sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
                sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
                if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
                {
                    Error_Handler();
                }
                /* USER CODE BEGIN TIM6_Init 2 */

                /* USER CODE END TIM6_Init 2 */
    }
        
}
 

The code you have shown appears to only initialise the timer and has nothing to do with the UART. (This makes me suspect that, as usual, the problem lies in code we are not shown!)
Also the 'if' statement at the start seems totally out of place - why only initialise the timer if 'ModulationFreq' exactly equals 100 and all of the period setup values are hard coded.
That code might be OK called once but then there should be other code elsewhere that uses the UART value to change the timer period.
Susan
 

Thank you @Aussie Susan for your comments.

Yes, you are right. The problem was not in the timer initializer code. I solved the problem with migrating "MX_TIM6_Init(); and HAL_TIM_Base_Start_IT(&htim6);" functions after receiving "ModulationFreq" value through UART Receive function.

I imagined that the timer function would start whenever I selected a certain value.

Thank you,
 

You should only need to call the initialisation code once. After that, updating the period value should be dynamic using the __HAL_TIM_RESET_AUTORELOAD macro (or similar - you can write directly to the ARR register as well).
There are a number of questions/articles on the topic of dynamically altering the timer period (I even found one for this on a regular basis.)
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top