Stm32f4计数脉冲(如何调整上升沿电压?)
Stm32f4 counting pulses (How can I adjust the rising edge voltage ?)
目前我在 stm32f4 - Discovery Board 上使用 TIM2 来计算脉冲(上升沿)。如何调整上升沿的阈值?我想计算 1 V 脉冲。目前只能计算 2V 脉冲。我无法在文档中找到关于此的内容。
这是我的定时器函数的代码。
void timer_2_pulse_counter_gpioa1_Init(){
RCC->AHB1ENR |= 0x01; // 1: IO port A clock enabled
//RCC->AHB1ENR |= 0x10; // 1: IO port E clock enabled
// APB1 peripheral reset register
RCC->APB1ENR |= 0x01; // 1: enable TIM2
// GPIO port mode register (GPIOx_MODER)
GPIOA->MODER |= 0x00000008; // 10: Alternate function mode PA1 => AF mode
GPIOA->AFR[0] |= 0x00000010; // 1000: Must refer to AF1 (alternate function for TIM1/ TIm2)
GPIOA->PUPDR |= 0x00000008; // Sets pull down resistor for PA1
// CCMR!: capture/compare mode register 1
TIM2->CCMR1 |= 0x0100; // CC2 channel is configured as input, IC2 is mapped on TI2
// SMCR: Slave Mode control register
TIM2->SMCR |= 0x0007; // Bits[2:0] 111: External Clock Mode 1 - Rising edges of the selected trigger clock the counter.
TIM2->SMCR |= 0x0060; // Bits[6:4] 110: selected Trigger: Filtered Timer Input 2 (TI2FP2)
TIM2->ARR = 0xFFFF; // Set the timer reset on the highest possible value
TIM2->CR1 |= 0x0001; //0001 Enable Timer
}
非常感谢您的支持!
数字输入不能 "trigger" 在程序员级别设置的特定电压下。但是您可以使用 ADC
"analogue watchdog" 模式在模拟模式下使用它。
如果您的微处理器有一个内置比较器(许多 STM32Fxxxx 都有一个),您可以用它来设置 "trigger" 电压。
目前我在 stm32f4 - Discovery Board 上使用 TIM2 来计算脉冲(上升沿)。如何调整上升沿的阈值?我想计算 1 V 脉冲。目前只能计算 2V 脉冲。我无法在文档中找到关于此的内容。
这是我的定时器函数的代码。
void timer_2_pulse_counter_gpioa1_Init(){
RCC->AHB1ENR |= 0x01; // 1: IO port A clock enabled
//RCC->AHB1ENR |= 0x10; // 1: IO port E clock enabled
// APB1 peripheral reset register
RCC->APB1ENR |= 0x01; // 1: enable TIM2
// GPIO port mode register (GPIOx_MODER)
GPIOA->MODER |= 0x00000008; // 10: Alternate function mode PA1 => AF mode
GPIOA->AFR[0] |= 0x00000010; // 1000: Must refer to AF1 (alternate function for TIM1/ TIm2)
GPIOA->PUPDR |= 0x00000008; // Sets pull down resistor for PA1
// CCMR!: capture/compare mode register 1
TIM2->CCMR1 |= 0x0100; // CC2 channel is configured as input, IC2 is mapped on TI2
// SMCR: Slave Mode control register
TIM2->SMCR |= 0x0007; // Bits[2:0] 111: External Clock Mode 1 - Rising edges of the selected trigger clock the counter.
TIM2->SMCR |= 0x0060; // Bits[6:4] 110: selected Trigger: Filtered Timer Input 2 (TI2FP2)
TIM2->ARR = 0xFFFF; // Set the timer reset on the highest possible value
TIM2->CR1 |= 0x0001; //0001 Enable Timer
}
非常感谢您的支持!
数字输入不能 "trigger" 在程序员级别设置的特定电压下。但是您可以使用 ADC
"analogue watchdog" 模式在模拟模式下使用它。
如果您的微处理器有一个内置比较器(许多 STM32Fxxxx 都有一个),您可以用它来设置 "trigger" 电压。