Skip to main content
Ctrl+K

CanMV K230

  • CanMV-K230 Quick Start Guide
  • User Guide
    • 1. Obtaining the Development Board
      • CanMV-K230 Development Board
      • CanMV-K230D Development Board
    • 2. Flashing the Firmware
    • 3. Connecting the IDE
    • 4. Running Example Programs
    • 5. Advanced - Custom Firmware
  • Example Routine Explanation
    • 1. Peripheral Routine Explanation
      • 1. FPIOA Example
      • 2. GPIO Example
      • 3. UART Example
      • 4. I2C Example
      • 5. SPI Examples
      • 6. PWM Example
      • 7. ADC Example
      • 8. RTC Example
      • 9. WDT Routines
      • 10. TIMER Example
      • 11. FFT Example
      • 12. TOUCH Routine
      • 13. Explanation of AES Routines
      • 14. SHA256 Routine Explanation
      • 15. LED Routine Explanation
    • 2. Multimedia Tutorial Explanation
      • 1. Sensor Example Explanation
      • 2. Display Example Explanation
      • 3. Audio Routine Explanation
      • 4. Video Tutorial Explanation
      • 5. Explanation of Lvgl Example
    • 3. AI Routine Explanation
      • 1. nncase_runtime Module Usage Guide
      • 2. Face Detection Example
      • 3. AI Demo Documentation
    • 4. OpenMV Example Tutorials
      • 1. QR Code Recognition Routine Explanation
      • 2. Explanation of Barcode Recognition Routine
      • 4. Explanation of the DM Code Recognition Routine
      • 5. Common Image Drawing Routines Explanation
      • 6. Color Recognition (find_blobs) Routine Explanation
      • 7. Explanation of Eigenvalue Detection Routines
      • 8. Explanation of Image Processing Routines
    • 5. Network Examples Explanation
      • 1. Explanation of Using Wired Network Routine
      • 2. Wireless Network Example Explanation
      • 3. TCP-Client Example Explanation
      • 4. TCP Server Example Explanation
      • 5. Explanation of the UDP-Client Example
      • 6. UDP Server Example Explanation
      • 7. HTTP-Client Example Explanation
      • 8. HTTP Server Example Explanation
  • API Manual
    • 1. Python Standard Library and Micropython Standard Micro Library
      • 1.1 Ucryptolib Module API Manual
      • 1.2 Hashlib Module API Documentation
      • 1.3 utime Time-Related Functions API Manual
      • 1.4 gc – Memory Management API Manual
      • 1.5 uos – Basic Operating System Services
    • 2. Micropython Specific Libraries
      • 2.1 Uctypes Module API Documentation
      • 2.2 Network Module API Manual
      • 2.3 Socket Module API Manual
      • 2.4 ADC Module API Manual
      • 2.5 FFT Module API Manual
      • 2.6 Pin Module API Manual
      • 2.7 I2C Module API Manual
      • 2.8 FPIOA Module API Manual
      • 2.9 PWM Module API Manual
      • 2.10 SPI Module API Manual
      • 2.11 Timer Module API Manual
      • 2.13 UART Module API Manual
      • 2.14 Machine Module API Documentation
      • 2.15 RTC Module API Manual
      • 2.16 TOUCH Module API Manual
      • 2.17 LED Module API Manual
      • 2.18 SPI_LCD Module API Manual
    • 3. Image Multimedia
      • 3.1 Sensor Module API Manual
      • 3.2 Display Module API Manual
      • 3.3 Audio Module API Manual
      • 3.4 Media Module API Manual
      • 3.5 VDEC Module API Manual
      • 3.6 VENC Module API Manual
      • 3.7 MP4 Module API Manual
      • 3.8 Player Module API Manual
      • 3.9 RTSP Module API Manual
      • 3.10 PM Module API Manual
      • 3.11 Image Processing API Manual`
      • 3.12 LVGL User Manual
    • 4. nncase
      • 4.1 nncase_runtime Module API Manual
    • 5. AI Demo
      • 5.1 PipeLine Module API Manual
      • 5.2 Ai2d Module API Manual
      • 5.3 AIBase Module API Manual
  • Frequently Asked Questions
  • Version Description
dev
Branches
dev
main
External links
K210 CanMV
K210 CanMV Docs
K230 Docs
K230 CanMV Docs
  • .md

1.3 utime Time-Related Functions API Manual

Contents

  • Functions
    • ntp_sync
    • localtime
    • mktime
    • sleep
    • sleep_ms
    • sleep_us
    • ticks_ms
    • ticks_us
    • ticks_cpu
    • ticks_add
    • ticks_diff
    • time
    • ticks
    • clock
  • clock Class
    • Constructor
    • Methods
      • tick
      • fps
      • reset
      • avg

1.3 utime Time-Related Functions API Manual#

This module implements a subset of the functionality of the CPython module as described below. For more detailed information, please refer to the original CPython documentation: time.

The utime module provides functionalities for obtaining the current time and date, measuring time intervals, and delaying operations.

Epoch Time: The Unix port uses 1970-01-01 00:00:00 UTC as the standard epoch time for POSIX systems.

Maintaining Actual Calendar Date/Time: This requires using a real-time clock (RTC). On systems running an underlying operating system (including some real-time operating systems, RTOS), the RTC might be enabled by default. Setting and maintaining the actual calendar time is handled by the operating system or RTOS, and this is done outside of MicroPython. MicroPython queries the date and time via the operating system’s API.

Functions#

ntp_sync#

utime.ntp_sync()

When the system is connected to the network, calling this function can synchronize the current time from the internet. The function returns True or False, indicating whether the synchronization was successful. Some development boards do not support the RTC module, so this function always returns False on those boards.

localtime#

utime.localtime([secs])

Converts time in seconds since the epoch to an 8-tuple containing the following information: (year, month, day, hour, minute, second, weekday, yearday). If no seconds are provided, it returns the current time from the RTC.

  • Year includes the century (e.g., the year 2014)

  • Month ranges from 1-12

  • Day (mday) ranges from 1-31

  • Hour ranges from 0-23

  • Minute ranges from 0-59

  • Second ranges from 0-59

  • Weekday ranges from 0 (Monday) to 6 (Sunday)

  • Yearday ranges from 1-366

mktime#

utime.mktime(tuple)

This function is the inverse of localtime(). It accepts an 8-tuple representing local time and returns the number of seconds since 1970-01-01 00:00:00.

sleep#

utime.sleep(seconds)

Delays execution for the specified number of seconds. Some development boards support passing floating-point numbers to achieve sub-second delays. However, to ensure compatibility, it is recommended to use sleep_ms() and sleep_us() functions for millisecond and microsecond delays.

sleep_ms#

utime.sleep_ms(ms)

Delays execution for the specified number of milliseconds.

sleep_us#

utime.sleep_us(us)

Delays execution for the specified number of microseconds.

ticks_ms#

utime.ticks_ms()

Returns an increasing millisecond counter, referenced from an arbitrary point in the system’s internal time. The counter will wrap around after a certain value.

ticks_us#

utime.ticks_us()

Similar to ticks_ms(), but returns a microsecond-level counter.

ticks_cpu#

utime.ticks_cpu()

Provides the highest resolution counter, usually related to the CPU clock, used for high-precision benchmarking or tight real-time loops.

ticks_add#

utime.ticks_add(ticks, delta)

Calculates a new ticks value based on the specified time increment (delta, which can be positive or negative), useful for setting task deadlines.

ticks_diff#

utime.ticks_diff(ticks1, ticks2)

Calculates the difference between two ticks values, handling counter wrap-around.

time#

utime.time()

Returns the number of seconds since the epoch, provided the RTC is set. If the RTC is not set, it returns the number of seconds since the system was powered on or reset.

ticks#

utime.ticks()

Equivalent to utime.ticks_ms().

clock#

utime.clock()

Returns a clock object for time measurement and FPS calculation.

clock Class#

Constructor#

utime.clock()

Methods#

tick#

clock.tick()

Records the current time (in milliseconds), which can be used for FPS calculation.

fps#

clock.fps()

Calculates the frame rate (FPS) based on the time interval since the last clock.tick() call.

Example:

import utime
clock = utime.clock()
while True:
    clock.tick()
    utime.sleep(0.1)
    print("fps = ", clock.fps())

reset#

clock.reset()

Resets all timing markers.

avg#

clock.avg()

Calculates the average time consumed per frame.

previous

1.2 Hashlib Module API Documentation

next

1.4 gc – Memory Management API Manual

Contents
  • Functions
    • ntp_sync
    • localtime
    • mktime
    • sleep
    • sleep_ms
    • sleep_us
    • ticks_ms
    • ticks_us
    • ticks_cpu
    • ticks_add
    • ticks_diff
    • time
    • ticks
    • clock
  • clock Class
    • Constructor
    • Methods
      • tick
      • fps
      • reset
      • avg

© Copyright 2024 Canaan Inc.

Developer Resources
Downloads
Blog
Document Center
Answer
Contact Us
Mail: salesai@canaan-creative.com
Community
QQ Group: 578895334
WeChat public account: 嘉楠科技