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.

[参考译文] MSP430F5659:等待外部时钟脉冲计数

Guru**** 1825110 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1429831/msp430f5659-waiting-for-a-pulse-count-of-an-external-clock

器件型号:MSP430F5659

工具与软件:

您好!

我可能走错了路,但这是什么家伙。

我必须等待外部时钟的89个上升沿、然后才能继续运行程序。 时钟的频率约为250kHz。

该信号目前在端口6.4上、仍可用于我的控制器上的 COMP_B。

继续的最佳方式是什么? 可能可以切换到另一个引脚、但我希望避免这种情况。

提前感谢

Stefan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我告诉你,我走错了轨道。

    #include <msp430.h>
    
    void main(void) {
        WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    
        // Configure P6.4 as input
        P6DIR &= ~BIT4;             // Set P6.4 as input
        P6REN |= BIT4;              // Enable pull-up resistor
        P6OUT |= BIT4;              // Set pull-up resistor
    
        // Initialize variables
        unsigned int lastState = 0;
        unsigned int edgeCount = 0;
    
        // Main loop
        while (1) {
            // Read the current state of P6.4
            unsigned int currentState = (P6IN & BIT4) >> 4;
    
            // Check for rising edge
            if (currentState == 1 && lastState == 0) {
                edgeCount++;
            }
    
            // Update the last state
            lastState = currentState;
    
            // Check if 89 edges are detected
            if (edgeCount == 89) {
                // Take action when 89 edges are detected
                edgeCount = 0; // Reset the counter if needed
            }
        }
    }

    我想我自己已经解决了这个问题

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、 Stefan

    很好~我将关闭该线程。

    此致、

    Helic