Timer, js Timer

Source: Internet
Author: User

Timer, js Timer

 

The STM32 timer has powerful functions. There are a total of 8 16-bit timers. Among them, TIM6 and TIM7 are basic timers, which mainly generate DAC trigger signals. TIM2, TIM3, TIM4, and TIM5 are general timers, in addition to basic timing, there are several available scenarios

      • Capture/compare registers for pulse frequency measurement;
      • Analysis of PWM output process;
      • Analysis of PWM input process;
      • Timer clock. An external pulse can be used as the timer clock source;

TIM1 and TIM8 are advanced timers, which have all basic and general functions. Besides, they also have interfaces of the Three-cell 6-step motor, brake functions, and dead-time control for PWM drive circuit. Compared with the general timer, it mainly has two more structures: BRK and DTG, so it has the dead-time control function.

Take timer 3 as an example. The initialization program is as follows:

void timer_init_(u16 err,u16 psc){  TIM_TimeBaseInitTypeDef TIM_instructer;    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);    TIM_instructer.TIM_Period=err;    TIM_instructer.TIM_Prescaler=psc;    TIM_instructer.TIM_CounterMode=TIM_CounterMode_Up;    TIM_instructer.TIM_ClockDivision=TIM_CKD_DIV1;    TIM_TimeBaseInit(TIM3,&TIM_instructer);    TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);    TIM_Cmd(TIM3,ENABLE);    }void NIVC_init(){    NVIC_InitTypeDef NVIC_instructer;    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);    NVIC_instructer.NVIC_IRQChannel=TIM3_IRQn;    NVIC_instructer.NVIC_IRQChannelCmd=ENABLE;    NVIC_instructer.NVIC_IRQChannelPreemptionPriority=1;    NVIC_instructer.NVIC_IRQChannelSubPriority=1;    NVIC_Init(&NVIC_instructer);}void TIM3_IRQHandler(){  if(TIM_GetFlagStatus(TIM3,TIM_IT_Update)!=RESET)    {      LED0=~LED0;            }  TIM_ClearITPendingBit(TIM3,TIM_IT_Update);}

Among them, the initialization section of Objective C already exists. For details about TIM3 initialization.

typedef struct { u16 TIM_Period; u16 TIM_Prescaler; u8 TIM_ClockDivision; u16 TIM_CounterMode; } TIM_TimeBaseInitTypeDef; 

TIM_Period sets the value of the Automatic Reload register cycle for the next update event loading activity. The value must be between 0x0000 and 0xffff;

TIM_Prescaler is set as the pre-division value of the TIMx clock frequency division. The value must be between 0x0000 and 0 xFFFF;

TIM_ClockDivision sets the clock division. The value is as follows:

TIM_CKD_DIV1 TDTS = Tck_tim
TIM_CKD_DIV2 TDTS = 2Tck_tim
TIM_CKD_DIV4 TDTS = 4Tck_tim

TIM_CounterMode: select the counter mode. The value is as follows:

TIM_CounterMode_Up TIM upward counting Mode
TIM_CounterMode_Down TIM downward counting Mode
TIM_CounterMode_CenterAligned1 TIM central alignment Mode 1 count mode
TIM_CounterMode_CenterAligned2 TIM central alignment Mode 2 count mode
TIM_CounterMode_CenterAligned3 TIM central alignment Mode 3 count mode

The TIM_ITConfig (TIM_TypeDef * TIMx, uint16_t TIM_IT, FunctionalState NewState) function is used to enable specific interruptions. The input parameter TIM_IT is enable or disable the TIM interrupt, one or more values can be combined. The values are as follows:

TIM_IT_Update TIM interrupt source
Tim_it_pc3 TIM capture/compare 1 interrupt source
TIM_IT_CC2 TIM capture/compare 2 interrupt source
TIM_IT_CC3 TIM capture/compare 3 interrupt source
TIM_IT_CC4 TIM capture/compare 4 interrupt source
TIM_IT_Trigger TIM triggers the interrupt source

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.