当前位置:网站首页>STM32 - input capture experiment
STM32 - input capture experiment
2022-07-23 10:11:00 【Three sloths】
One 、 General timer input capture overview
STM32 PWM working process

STM32 Input capture workflow ( passageway 1 For example )

By testing TIMx_CHx Edge signal on , At the edge, the signal jumps ( For example, the rising edge / Falling edge ) When , Set the current timer value (TIMx_CNT) Store in the corresponding capture / Compare register (TIMx_CCRx) Inside , Complete a capture .
1、 Set the input capture filter ( passageway 1 For example )

hypothesis IC1F[3:0]=0011, And set up IC1 Map to channel 1 On , And it is triggered by the rising edge , Then when the rising edge is captured, use fDTS The frequency is continuously sampled to 8 Secondary channel 1 The level of , If it's all high , It means it is an effective trigger , An input capture interrupt is triggered , This can filter out those high-level pulse width lower than 8 Pulse signal with sampling period , So as to achieve the effect of filtering . If you don't do filtering , Is set IC1F[3:0]=0000, As long as the rising edge is collected, the capture is triggered .
2、 Set input capture polarity ( passageway 1 For example )

Suppose it is set to rising edge , When the edge detector detects a rising edge, it will capture .
CC1 The channel is configured to output :
0:OC1 High active 1:OC1 Low level active
CC1 The channel is configured as input :( choice IC1 still IC1 As a trigger or capture signal )
0: Non antiphase : Capture occurs at IC1 The rising edge of : When used as an external trigger ,IC1 Reverse phase .
1: Reverse phase : Capture occurs at IC1 The falling edge of : When used as an external trigger ,IC1 Reverse phase .
3、 Set the input capture mapping channel ( passageway 1 For example )

IC1 Can be mapped to TI1 Can also be mapped to TI2 On ;IC2 Can be mapped to TI2 Can also be mapped to TI1 On .
4、 Set the input acquisition divider ( passageway 1 For example )

1 frequency division : A rising edge triggers a capture
2 frequency division : Every time 2 An event triggers a capture ( It will not be captured until two rising edges are detected )
4 frequency division : Every time 4 An event triggers a capture
8 frequency division : Every time 8 An event triggers a capture
Trigger capture is to load the value of the counter into the capture register
5、 Capturing a valid signal can turn on the interrupt

For example, the rising edge is captured and the frequency is not divided , Then each rising edge captured will trigger a capture , At the same time, if capture interrupt is enabled , The interrupt will be triggered .
namely : First filtering , Then judge whether the rising edge or the falling edge , Then map the last frequency division to select when the interrupt event occurs
Two 、 Library function configuration input capture
Input capture channel initialization function :
void TIM_ICInit (TIM_TypeDef* TIMx , TIM_ICInitTypeDef* TIM_ICInitStruct);
typedef struct
{
uint16_t TIM_Channel;// Capture channels 1-4
uint16_t TIM_ICPolarity;// Capture polarity
uint16_t TIM_ICSelection;// The mapping relationship
uint16_t TIM_ICPrescaler;// Division coefficient
uint16_t TIM_ICFilter;// filter
} TIM_ICInitTypeDef;
TIM5_ICInitABC.TIM_Channel=TIM_Channel_1;
TIM5_ICInitABC.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM5_ICInitABC.TIM_INSelection=TIM_ICSelection_DirectTI;
TIM5_ICInitABC.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM5_ICInitABC.TIM_ICFilter=0x00;
TIM_ICInit(TIM5,&TIM5_ICInitABC);Channel polarity setting independent function :
void TIM_OCxPolarityConfig(TIM_TypeDef* TIMx , uint16_t TIM_OCPolarity);
Get channel capture value :
uint32_t TIM_GetCapture1(TIM_TypeDef* TIMx);
3、 ... and 、 Enter the general configuration steps for capture :
1、 The initialization timer corresponds to the channel IO The clock .
2、 initialization IO mouth , The mode is reuse : GPIO_Init();
3、 Set the pin reuse mapping :GPIO_PinAFConfig();
4、 Initialize the timer ARR、PSC:TIM_TimeBaseInit();
5、 Initialize the input capture channel :TIM_ICInit();
6、 Enable capture interrupt :TIM_ITConfig(); NVIC_init();
7、 Enable timer :TIM_Cmd();
8、 Write interrupt service function :TIMx_IRQHandler();
The experiment purpose : Measure the pulse width of the signal

Measurement principle :TIM5_Cap_Init It is set when the function is executed , Then wait for the rising edge interrupt to arrive , When the rising edge is captured, the interrupt , If at this time TIM5CH1_CAPTURE_STA Of the 6 Position as 0, Indicates that a new rising edge has not been captured , As the first TIM5CH1_CAPTURE_STA、TIM5CH1_CAPTURE_VAL and TIM5->CNT Equal clearing , And then set TIM5CH1_CAPTURE_STA Of the 6 Position as 1, Flag capture to high level , Finally set to falling edge capture , Wait for the falling edge to come . If waiting for the falling edge to arrive , The timer overflowed , It's just TIM5CH1_CAPTURE_STA It counts the overflow time , When the maximum overflow time comes , Force tag capture to complete ( At this time, the falling edge has not been captured ). When the falling edge comes , First set up TIM5CH1_CAPTURE_STA Of the 7 Position as 1, The flag successfully captures a high level , Then read the value of the timer at this time to TIM5C1_CAPTURE_VAL Inside , Finally set to rising edge capture , Go back to the original state . as long as TIM5CH1_CAPTURE_STA Of the 7 I've always been for 1, Then there will be no second capture .
Input capture experiments
边栏推荐
- 海通证券场内基金开户怎么样安全吗
- This is how the permission system is designed, yyds
- Open source Invoicing system, 10 minutes to complete, it is recommended to collect!
- 南京银行提前批金融科技岗
- IDM最新版软件的安装下载和使用方法
- js div 滚动到底部
- 《nlp入门+实战:第一章:深度学习和神经网络》
- 网络安全之ARP欺骗防护
- Scala object
- GNN third party Library: pyg (pytorch geometric) [the library based on pytorch can help users quickly build and train their own graph neural network model] [deepwalk, line, GCN, gat, etc.]
猜你喜欢

数据库范式与模式分解

世界正在被开源软件吞食

Leetcode-99. restore binary search tree

Multi-UA V Cooperative Exploringfor the Unknown Indoor EnvironmentBased on Dynamic Target Tracking翻译

Leetcode 1074. number of submatrices that sum to target

九张图纵观加密市场周期规律

中小企业的福音来咯!JNPF渐火,助力业务数字化升级

网络安全之ARP欺骗防护

L-半胱氨酸修饰的金纳米粒子(Cys-GNPs)和牛血清白蛋白/生物素化白蛋白纳米粒

567. Arrangement of strings
随机推荐
Is it safe for CITIC futures to open an account online and will it be cheated?
[node middle layer practice (IV)] ---- logical processing of express middle layer
js div 滚动到底部
Scala对象object
实现方法pathListToMap,能够将输入的pathList转化为具有层级结构的map类型
spark中saveAsTextFile如何最终生成一个文件
leetcode-99.恢复二叉搜索树
实现城市治理一网统管,必须这 4 个关键技术
亿级融资事件占比超30%,超自动化的下一站是何处?丨曼孚科技
BGP reflector, federal, routing rules
three文档使用
Hide the PHP version information in the response header of the website server
[learning notes] node -- from 0 foundation to actual enterprise official website
十年架构五年生活-05第一次出差
枚举类的使用和实现
567. Arrangement of strings
error MSB4181: “QtRunWork”任务返回了 false,但未记录错误
PHP converts pictures to Base64 format and restores them to generate pictures
STM32——输入捕获实验
赚钱能力”是需要积累的