当前位置:网站首页>Time synchronization of livox lidar hardware -- PPS method
Time synchronization of livox lidar hardware -- PPS method
2022-07-07 02:00:00 【The moon shines on the silver sea like a dragon】
Livox Lidar hardware time synchronization ---PPS Method
stay This blog This paper introduces the in Livox Time hardware synchronization 3 Methods , One way is through PPS The way of the signal , Signal time synchronization . This article passes STM32 TIM3 Timer update interrupt , Produce satisfactory PPS The signal .
Livox Yes PPS Signal requirements
Livox Yes PPS The signal requirements are shown in the figure below :
among GPRMC Don't worry about your requirements , Get two useful information :
- The interval between the rising edges of two adjacent second pulses Effective range 900-1100ms Recommended values ,1000ms
- High level time of second pulse Effective range 5ms-900ms Recommended values 10ms-200ms
Now let's use STM32F4 A product that meets the requirements PPS The signal
STM32F4 The timer is very powerful , Yes TIME1 and TIME8 Advanced timer, etc , Also have TIME2-TIME5,TIM9-TIM14 And so on , also TIME6 and TIME7 Wait for the basic timer , Total amount 14 There are as many timers .
STM32F4 Timer classification ( common 14 individual ):
- Advanced timer :TIME1 、TIME8
- Universal timer : TIME2-TIME5,TIM9-TIM14
- Basic timer : TIME6 、 TIME7
STM32F4 General timer Introduction
STM32F4 The universal timer contains a 16 Bit or 32 Bit auto overload counter (CNT), The counter consists of a programmable prescaler (PSC) drive .
STM32F4 A universal timer can be used for : Measure the pulse length of the input signal ( Input capture ) Or produce an output waveform ( Output comparison and PWM) etc. .
Use a timer prescaler and RCC Clock controller prescaler , Pulse length and waveform period can be adjusted from a few microseconds to a few milliseconds .
STM32F4 Each universal timer is completely independent , There are no resources shared with each other .
STM3 Common to TIMx (TIM2-TIM5 and TIM9-TIM14) Timer functions include :
16 position /32 position ( only TIM2 and TIM5) Up 、 Down 、 Up / Auto load counter down (TIMx_CNT), Be careful :TIM9~TIM14 Only support upward ( Increasing ) Count by .
16 Bit programmable ( It can be modified in real time ) Preassigned frequency counter (TIMx_PSC), The frequency division coefficient of the counter clock frequency is 1~65535 Any number between .
4 A separate channel (TIMx_CH14,TIM9TIM14 most 2 Channels ), These channels can be used as :
A. Input capture
B. Output comparison
C.PWM Generate ( Edge or center alignment mode ) , Be careful :TIM9~TIM14 Middle alignment mode is not supported
D. Monopulse mode outputExternal signals can be used (TIMx_ETR) Control timer and timer Interconnection ( It can be used 1 One timer controls another timer ) The synchronous circuit of .
Interrupt occurs when the following events occur /DMA(TIM9~TIM14 I won't support it DMA):
A. to update : The counter overflows up / Spilling down , Counter initialization ( Through software or internal / External trigger )
B. Triggering event ( The counter starts 、 stop it 、 Initialized or internally / External trigger count )
C. Input capture
D. Output comparison
E. Support for incremental positioning ( orthogonal ) Encoder and Hall sensor circuits (TIM9~TIM14 I won't support it )
F. Trigger input as an external clock or current management by cycle (TIM9~TIM14 I won't support it )
STM32F4 Register of general timer
Control register 1
Control register 1(TIMx_CR1)
The description of each bit of this register is shown in Fig
TIMx_CR1 The lowest point of , That is, the counter enable bit , This bit must be set to 1, To get the timer to start counting .
DMA/ Interrupt enable register
DMA/ Interrupt enable register (TIMx_DIER)
The register is a 16 Bit register , Their descriptions are shown in the figure :
The first 0 position , This bit is the update interrupt allowed bit , Update interrupt using timer , This bit needs to be set to 1, To allow interrupts due to update Events .
Prescaler register
Prescaler register (TIMx_PSC).
This register divides the clock by setting , Then provide it to the counter , As a counter clock . The description of each bit of this register is shown in Fig
here , The clock sources of timers are 4 individual :
1) Internal clock (CK_INT)
2) External clock mode 1: External input pins (TIx)
3) External clock mode 2: External trigger input (ETR), Only applicable to TIM2、TIM3、TIM4
4) Internal trigger input (ITRx): Use A Timer as B Timer prescaler (A by B Provide clock ).
These clocks , The specific choice can be made by TIMx_SMCR Register to set . there CK_INT The clock is from APB1 Double frequency , Unless APB1 Set the number of clock dividers to 1( It's not usually 1), Otherwise, the universal timer TIMx The clock is APB1 Of the clock 2 times , When APB1 When the clock doesn't divide , Universal timer TIMx The clock is equal to APB1 The clock of . The advanced timer and TIM9~TIM11 The clock doesn't come from APB1, But from APB2 Of .
Counter register
TIMx_CNT register , This register is the counter of the timer , This register stores the count value of the current timer .
Auto reload register
Auto reload register (TIMx_ARR)
This register physically corresponds to 2 A register . One is that programmers can operate directly , The other is something that programmers can't see , This invisible register is called shadow register . In fact, what really works is the shadow register . According to the TIMx_CR1 In the register APRE Bit setting :APRE=0 when , The contents of the preloaded register can be transferred to the shadow at any time
Sub register , here 2 The is connected ; and APRE=1 when , At each update event (UEV) when , Just put the preload register (ARR) The contents of are transferred to the shadow register .
The description of each bit of the automatic reload register is shown in the figure
Status register
Status register (TIMx_SR)
This register is used to mark various events related to the timer / Whether the interruption occurs . The description of each bit of this register is shown in Fig
Configure timer through library function
Timer related library functions mainly focus on firmware library files stm32f4xx_tim.h and stm32f4xx_tim.c In file . The timer configuration steps are as follows :
TIM3 Clock enable .
TIM3 It's mounted on APB1 under , So pass APB1 The clock enable function under the bus enables TIM3. The function called is :
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); /// Can make TIM3 The clock
Initialize timer parameters , Set auto reload value , Division coefficient , Counting method, etc
In library functions , The initialization parameter of timer is through initialization function TIM_TimeBaseInit Realized :
voidTIM_TimeBaseInit(TIM_TypeDef*TIMx,
TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
The first parameter is to determine which timer
The second initialization parameter is the body parameter of the pointer , The structural type is TIM_TimeBaseInitTypeDef, The definition of this structure :
typedef struct
{
uint16_t TIM_Prescaler;
uint16_t TIM_CounterMode;
uint16_t TIM_Period;
uint16_t TIM_ClockDivision;
uint8_t TIM_RepetitionCounter;
} TIM_TimeBaseInitTypeDef;
This structure has 5 Member variables , For general timers, only the first four parameters are useful , Last parameter TIM_RepetitionCounter It's the advanced timer that works
The first parameter TIM_Prescaler It is used to set the frequency division coefficient
The second parameter TIM_CounterMode Is used to set the counting mode , It can be set to count up , Down counting and center aligned counting , More commonly used is the up count mode TIM_CounterMode_Up And count down mode TIM_CounterMode_Down.
The third parameter is to set the auto overload count cycle value
The fourth parameter is used to set the clock division factor
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 5000;
TIM_TimeBaseStructure.TIM_Prescaler =7199;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
Set up TIM3_DIER Allow update interrupt
To use TIM3 The update of , The corresponding bit of the register enables the update interrupt . In the library function, timer interrupt is enabled by TIM_ITConfig Function to implement :
void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
The first parameter is the timer
The second parameter is critical , Is used to indicate the type of timer interrupt that we enable , There are many types of timer interrupts , Including update interrupt TIM_IT_Update, Trigger interrupt TIM_IT_Trigger, And input capture interrupt and so on .
The third parameter is disable or enable .
Can make TIM3 The update of , The format is :
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE );
TIM3 Interrupt priority setting .
After timer interrupt enable , Because it's going to interrupt , It's essential to set up NVIC Related registers , Set interrupt priority
Can make TIM3
Start the timer after configuration , adopt TIM3_CR1 Of CEN Bit to set . In the firmware library, the function to enable timer is through TIM_Cmd Function to implement :
void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
Enable timer 3, Method is :
TIM_Cmd(TIM3, ENABLE); // Can make TIMx peripherals
Write interrupt service function
In the end , Or write timer interrupt service function , This function is used to process the related interrupt generated by timer .
After the interrupt is generated , The value of the status register is used to determine the type of interrupt generated . Then perform the relevant operations
Use update ( overflow ) interrupt , In the status register SR The lowest point of . After processing the interrupt, it should be directed to TIM3_SR Write at the lowest position of 0, To clear the interrupt flag .
In the firmware library function , The function used to read the value of interrupt status register and judge the type of interrupt is :
ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT)
The function is to , Judge timer TIMx The interrupt type of TIM_IT Whether there is an interruption . such as , We must judge
Chronometer 3 Whether there is an update ( overflow ) interrupt , Method is :
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){
}
The function of clearing interrupt flag bit in firmware library is :
void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT)
The function is to , Clear timer TIMx The interrupt TIM_IT Sign a . stay TIM3 After the overflow interrupt of , We want to clear the interrupt flag bit , The method is :
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
The firmware library also provides two functions to judge the timer status and clear the timer status flag bit TIM_GetFlagStatus and TIM_ClearFlag, Their role is similar to that of the previous two functions . It's just TIM_GetITStatus The function will first determine whether the interrupt is enabled , Enable to judge the interrupt flag bit , and TIM_GetFlagStatus Directly used to determine the status flag bit .
Code
// Universal timer 3 Interrupt initialization
//arr: Auto reload value . psc: Clock presplitting frequency
// Timer overflow time calculation method :Tout=((arr)*(psc))/Ft us.
//Ft= Timer operating frequency , Company :Mhz
// Here's a timer 3!
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); // Can make TIM3 The clock
TIM_TimeBaseInitStructure.TIM_Period = arr-1; // Automatic reload load value
TIM_TimeBaseInitStructure.TIM_Prescaler=psc-1; // Timer frequency division
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; // Upcount mode
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);// Initialize the timer TIM3
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); // Allow timer 3 Update interrupt
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; // Timer 3 interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x01; // preemption 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03; // Response priority 3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);// initialization NVIC
TIM_Cmd(TIM3,ENABLE); // Enable timer 3
// Timer 3 Interrupt service function
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET) // Overflow interrupt
{
PPS_OUT=1;
delay_ms(100);
PPS_OUT=0;
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); // Clears the interrupt flag bit
}
Contains an interrupt service function and a timer 3 Interrupt initialization function
Of this function 2 Two parameters are used to set TIM3 Overflow time . Because the system is initialized SystemInit The function has been initialized APB1 The clock is 4 frequency division , the
With APB1 The clock is 42M,
When APB1 The number of clock frequency division is 1 When ,TIM2-7 as well as TIM12-14 The clock is APB1 The clock of , And if the APB1 The number of clock divisions is not 1, that TIM2-7 as well as TIM12-14 The clock frequency of will be APB1 Twice the clock . therefore ,TIM3 The clock is 84M, Then according to the design arr and psc Value , You can calculate the interruption time .
The calculation formula is as follows :
Tout= ((arr+1)*(psc+1))/Tclk;
among :
Tclk:TIM3 Input clock frequency ( Unit is Mhz).
Tout:TIM3 Overflow time ( Unit is s).
Then in the interrupt function , Judge after interruption , pull up AF10, Time delay 100ms Pull down again .
Result
A continuous signal , Now scale the horizontal axis time , Look at the specific level time
One horizontal grid is 100ms, The duration of high level is about 100ms, The low level is 900ms, The adjacent time of the rising edge is 1000±100ms.
Amplify the high-level part , Probably 10 A grid , One space is 10ms, So the high level is 100ms±10ms Inside .
The signal meets the requirements stated at the beginning .
边栏推荐
- When grep looks for a process, it ignores the grep process itself
- Gin introduction practice
- MySQL execution process and sequence
- Ds-5/rvds4.0 variable initialization error
- Correct use of BigDecimal
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- ROS learning (XIX) robot slam function package cartographer
- Cisp-pte practice explanation (II)
- STM32F4---PWM输出
- ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
猜你喜欢
随机推荐
开发中对集合里面的数据根据属性进行合并数量时犯的错误
centos8 用yum 安装MySQL 8.0.x
ROS learning (22) TF transformation
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
String to date object
dvajs的基础介绍及使用
Halcon knowledge: segment_ contours_ XLD operator
猫猫回收站
Centos8 install MySQL 8.0 using yum x
ROS學習(23)action通信機制
Related programming problems of string
STM32F4---PWM输出
2022/0524/bookstrap
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
Recognition of C language array
Shell script quickly counts the number of lines of project code
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
盒子拉伸拉扯(左右模式)