Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 784 Bytes

221025.uart_hack.md

File metadata and controls

26 lines (23 loc) · 784 Bytes

2022-10-25

https://discordapp.com/channels/918498540232253480/918498540232253483/1034488826334294126

floitsch

Such a cool and weird hack. One of our customers needs to measure pulses, but can't use the pulse_counter library (from v2) yet.
Here is the work-around that should make things work for them:

import gpio
import uart

main:
  port := uart.Port --rx=(gpio.Pin 19) --tx=null --baud_rate=4_000_000 --data_bits=5
  start := Time.monotonic_us
  count := 0
  last := 0
  while true:
    data := port.read
    count += data.size
    now := Time.monotonic_us
    frequency := 2 * (count * 1_000_000 / (now - start))
    if now / 1_000_000 != last:
      print "Frequency: $frequency"
      last = now / 1_000_000

With this I'm able to measure frequencies of ~1MHz.