8000 RFC: PulseTime · Issue #2210 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
RFC: PulseTime #2210
Open
Open
@dmopalmer

Description

@dmopalmer

This is a Request For Comment for a suggested extension to pulseio for doing high precision timing on multiple inputs on the SAM port of circuitpython.

I would like to do time capture on pin inputs so that I can do things like:

  1. Get the exact time of an event (on one pin), compared to GPS time (referenced to the Pulse Per Second on another pin).
  2. Get the time between a start pulse and a stop pulse on two different pins
  3. Get the frequency, duty cycle, etc. of a signal by measuring the times of all the rising edges, falling edges, or both.
  4. Do the timing at the maximum feasible resolution (e.g. 12.5 ns for an 80 MHz CPU clock) and without jitter (i.e. using the hardware timers).

The current pulseio.PulseIn:

  1. Only gives the duration of a positive pulse, or of a negative pulse, and doesn't give the time between pulses.
  2. Is limited to microsecond resolution, with latency jitter, and to 0.065536 seconds maximum duration.
  3. Can't do multi-pin comparison

Is there already a library that can do what I want? (or a sufficient subset of it)? No sense re-inventing the wheel. (rfc: 'Why don't you just use the fooTime module on Arduino instead?' would be a useful comment.)

If not, I am thinking of adding pulseio.PulseTime (rfc: make it a separate module?) to the samdx1 library. The SAM has TCC (Timer Counter for Control) modules that can run a 24-bit counter from the CPU clock (or other source) and capture the times of up to 4 event sources. My library would set up a TCC with the user's choice of event inputs, and queue up event times as they occur.

Some details:

  1. 24 bits rolls over 5 times per second at 80 MHz, so the library would keep track of the rollover count. Easy code to get wrong, so I will be careful.
  2. The 31 bit integers of circuit Python roll over in 13 seconds (faster for faster clocks), so times would have to be in a format like (seconds,subseconds), with a convenience library to make them useful.
  3. A .now() method is needed to read the current timer state so you know how long ago an event happened.
  4. The minimum time delta between two events on the same pin is limited to how fast the ISR can reset the capture register. The time delta between events on two pins is unrestricted, so simultaneous or either-order single-cycle timing is possible.

rfc: Any other capabilities that should be included?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0