Back to engineering archive

Record 026 / Firmware and control

Interrupt-based encoder counter draft

An archived encoder-input draft that updates a count from A/B transitions and prints the count and latest direction value over Serial.

Archived firmware draft
EncoderInterrupt inputSerial diagnostics

Archived source flow

Archived-source flow for an encoder counter: a channel-A change samples A and B, uses an old/new-state lookup, updates the count and direction, then retains the current state. A separate main loop prints diagnostics and waits one second. Not compiled or hardware-tested.
Selected paths reconstructed from the archived encoder draft. Channel A alone triggers the handler; count accuracy and hardware operation are unverified. View diagram at full size

Technical notes

Interrupt input

Channel A is configured for a CHANGE interrupt. The handler samples both A and B inputs.

Transition lookup

The previous and current two-bit states index a 16-entry lookup table. Its value is added to the count and stored as the latest direction value, then the current A/B state is retained for the next interrupt.

Diagnostics and limits

The loop prints the count and direction, then waits one second. Only channel A triggers the handler; count accuracy and hardware operation have not been verified. The source contains no BLE interface or motor-output commands.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project