Use of stm32 basic timer TIM6 and TIM7

Publisher:温暖阳光Latest update time:2017-10-24 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The basic timer only has the most basic timing function, that is, when the accumulated number of clock pulses exceeds the preset value, it can trigger an interrupt or trigger a DMA request.


The following settings are required to use the timing function of the basic timer:

1) Enable the timer clock.

2) Set the pre-scaling number.

3) Set the counter value.

4) Set the sampling frequency division number.

5) Set the counting mode, up or down. TIM6 and TIM7 only have up counting function.

6) Enable interrupts, configure interrupt groups and interrupt service functions.

The configuration function is as follows:

/**************************************************************
** Function name: TIM6_Config
** Function description: Basic timer configuration
** Input parameters: None
** Output parameters: None
** Note: Timing time = (prescaler number + 1) * (count value + 1) / TIM6 clock (72MHz), unit (s)
   Here the overflow time t = (7200*10000) / 72000000s = 1s
*******************************************************************/
void TIM6_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); // Enable TIM6 clock


/* Basic settings */
TIM_TimeBaseStructure.TIM_Period = 10000-1; // Count value 10000   
TIM_TimeBaseStructure.TIM_Prescaler = 7200-1; //Pre-division, this value + 1 is the divisor of the division
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //Sampling division
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //Count up
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);


TIM_ITConfig(TIM6,TIM_IT_Update, ENABLE); //Enable TIM6 interrupt
TIM_Cmd(TIM6, ENABLE); //Enable timer 6
}
/******************************************************************
** Function name: NVIC_Config
** Function description: Interrupt priority configuration
** Input parameters: None
** Output parameters: None
*****************************************************************/
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Use group 2 
 
NVIC_InitStructure.NVIC_IRQChannel =TIM6_IRQn;//TIM6 interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//Preemptive priority is set to 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Sub-priority is set to 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//Interrupt enable
NVIC_Init(&NVIC_InitStructure);//Interrupt initialization
}

The interrupt service function is as follows:

/**********************************************************
** Function name: TIM6_IRQHandler
** Function description: Timer 6 update interrupt service routine
** Input parameters: None
** Output parameters: None
**************************************************************/
void TIM6_IRQHandler(void)
{
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM6,TIM_IT_Update);//Clear update interrupt flag
GPIOB->ODR^=GPIO_Pin_0;//Reverse PB0 level
}
}


The usage of TIM7 is similar. The timing interrupt function of the general timer is also used in this way. Just modify TIM6.


Keywords:stm32 Reference address:Use of stm32 basic timer TIM6 and TIM7

Previous article:Internal peripheral resources of different stm32f103 chips
Next article:Register configuration of stm32 IO port mode

Recommended ReadingLatest update time:2024-11-16 12:45

Getting Started with STM32 BIT_BAND Bit Band Alias ​​Area
1. What is a bit segment and bit band alias area? 2. What are its benefits? Answer 1: Yes, remember MCS51? MCS51 has bit operation, which takes one bit (BIT) as the data object.       MCS51 can simply operate the second bit of P1 port independently: P1.2=0;P1.2=1; just like this, the third pin (BIT2) of P1 port
[Microcontroller]
Getting Started with STM32 BIT_BAND Bit Band Alias ​​Area
STM32 learning notes (III) serial communication experiment
#include "sys.h" #include "usart.h"    //////////////////////////////////////////////////////////////////////////////////   //If you use ucos, just include the following header file. #if SYSTEM_SUPPORT_OS #include "includes.h" //ucos 使用    #endif //////////////////////////////////////////////////////////////////////
[Microcontroller]
STM32 learning notes (III) serial communication experiment
STM32 startup file (Reset_Handler function)
The main purpose of this file is: Setting the Initial SP Set initial PC=Reset_Handler Set the vector table entry address and initialize the vector table Call SystemInit to set the system clock to 72M. SystemInit is defined in the library file system_stm32f10.c and transferred to the label _main, and finally c
[Microcontroller]
SYS_TICK configuration for STM32
1. SYS_TICK is not a peripheral, but a part of the kernel. There is no description about it in RM0008. 2. This is a 24-bit counter that can generate internal interrupts. 3. Its interrupt can generate an interrupt without configuring the NVIC properties. 4. If you need to configure 8-frequency division, you need to con
[Microcontroller]
SYS_TICK configuration for STM32
STM32 BOOT bit understanding and setting
The STM32F10x on-chip storage area has three parts: built-in Flash, built-in SRAM, and built-in ROM (system memory). This defines three ways to start the system: starting from built-in Flash, starting from built-in SRAM, and starting from system memory. These three startup methods are determined by the two pins BOOT .
[Microcontroller]
STM32 BOOT bit understanding and setting
stm32 TIM2 remapping
There are four port usage combinations of TIM2 of stm32: 1. When not remapped, the default four IO ports of TIM2 are PA0, PA1, PA2, and PA3 2. To use the port combination of PA15, PB3, PA2, and PA3, call the following statement for partial remapping:   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Remapping
[Microcontroller]
stm32 TIM2 remapping
Interpretation of STM32 MCU: Code to implement PCROP clearing
Preface STM32  PCROP proprietary code readout protection sets a certain area to only allow execution, which can prevent the code from being illegally read out and modified. The ST website provides free PCROP reference code, but the routine only provides code to set PCROP. To facilitate the development and deployment
[Microcontroller]
Interpretation of STM32 MCU: Code to implement PCROP clearing
A topic about clearing the CCR of the STM32 timer
Today I would like to share with you a small case encountered in operating the CCR register during STM32 application development. It is about the problem of clearing the capture register in the STM32 timer.   Someone used STM32 to do input capture. In the callback function of the capture, the captured CCR value was fi
[Microcontroller]
A topic about clearing the CCR of the STM32 timer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号