你好
我 有一个传感器连接 到 MSP430FR2355启动板。 我有数字输入来计算频率(当分频器通电时)。 我想 测量 来自数字输入的频率分配器(5–6 MHz)的频率。 请 给我一些建议来执行此任务,并为我的编程提供示例代码?
我应该使用哪个针脚来读取频率?
此致,
埃勒姆
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
你好
我 有一个传感器连接 到 MSP430FR2355启动板。 我有数字输入来计算频率(当分频器通电时)。 我想 测量 来自数字输入的频率分配器(5–6 MHz)的频率。 请 给我一些建议来执行此任务,并为我的编程提供示例代码?
我应该使用哪个针脚来读取频率?
此致,
埃勒姆
此线程处理类似的问题。 也许有一些有用的东西?
您好,Elham,
您可以参考以下示例:
https://dev.ti.com/tirex/explore/node?node=ANcmdW6geYSVsxVVNMB9rA__IOGqZri__LATEST
此致
约翰逊
尊敬的约翰逊
感谢你的回复。
我将 P2.7更改为 P5.2和计时器,但我仍然没有任何东西。
请帮我解决问题。
最佳
埃勒姆
#include <msp430.h>
unsigned long timerBcaptureValues;
#define TB2IV_NONE (0x0000u) /* No Interrupt pending */
#define TB2IV_TB1CCR1 (0x0002u) /* TB2CCR1_CCIFG */
#define TB2IV_TB1CCR2 (0x0004u) /* TB2CCR2_CCIFG */
#define TB2IV_3 (0x0006u) /* Reserved */
#define TB2IV_4 (0x0008u) /* Reserved */
#define TB2IV_5 (0x000Au) /* Reserved */
#define TB2IV_6 (0x000Cu) /* Reserved */
#define TB2IV_TB2IFG (0x000Eu) /* TB2IFG */
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
P1DIR |= BIT0;
P1OUT = 0;
P2SEL0 |= BIT2; // P2.7 selected as TB0CLK
PM5CTL0 &= ~LOCKLPM5;
// Configure Timer_B
TB2CTL = TBSSEL_0 | MC_2 | TBCLR | TBIE; // ACLK, count mode, clear TBR, enable interrupt
TB2R = 0xFFFF - 20; // Offset until TBR overflow
__bis_SR_register(LPM4_bits | GIE); // Enter LPM4, enable interrupts
__no_operation(); // For debug
while (1)
{
P1OUT ^= BIT0; // P1.0 = toggle
__bis_SR_register(LPM0_bits); // CPU is not required
}
}
// Timer0_B3 Interrupt Vector (TBIV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER2_B1_VECTOR
__interrupt void TIMER2_B1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER2_B1_VECTOR))) TIMER2_B1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(TB2IV,TB2IV_TB2IFG))
{
case TB0IV_NONE:
break; // No interrupt
case TB0IV_TBCCR1:
break; // CCR1 not used
case TB0IV_TBCCR2:
TB2CCTL0 &= ~CCIFG;
timerBcaptureValues = TB2CCR0;
TB2CCR2 += 50000; // Add Offset to TBCCR1
__bic_SR_register_on_exit(LPM0_bits);// CPU active on reti
break; // CCR2 not used
case TB0IV_TBIFG: // overflow
TB2CTL = TBSSEL_2 | TBCLR; // SMCLK, clear TBR
TB2CCTL2 = CCIE; // TBCCR1 interrupt enabled
TB2CCR2 = 50000;
TB2CTL |= MC_2; // Start Timer_B in continuous
__bic_SR_register_on_exit(LPM4_bits);// Exit LPM4 on reti
break;
default:
break;
}
}