1

RTOS を実行している PIC32MX460F512L があり、コード内の 2 つのポイント間のミリ秒の差を取得する方法を探しています。

以下のコードはティック時間を取得しますが、ミリ秒単位の時間は取得しません。

static unsigned long gMSTP_timer_tick = 0 ;
void MSTP_timer_reset() {
    gMSTP_timer_tick = xTaskGetTickCount( ) ;
}
FLOAT32 MSTP_timer_differences() {
    unsigned long differences = xTaskGetTickCount( ) - gMSTP_timer_tick ;
    gMSTP_timer_tick += differences ;

    return (FLOAT32) differences ;
}

私の質問は

無料の RTOSで、現在の相対時間をミリ秒単位で取得する方法はありますか?

4

3 に答える 3

1

Ticks should have a set frequency. 1000Hz tick -> interrupt and task switch triggered every 1 ms. It won't be exactly that, especially if you have other interrupts. But it should keep that frequency.

I believe you should be able to compare two tick counts and divide by tick rate to end up with the delay.

Another classic trick would be to directly toggle a GPIO pin at the start of a timed interval and again at the end (repeatedly) and then use an oscilloscope to capture the interval. That should give a very precise real-time result.

You might also ask the FreeRTOS list.

于 2011-11-23T10:08:52.440 に答える