Skip to content

am243x : add configuration of pulse per revolution and pulse loss detection - #162

Merged
nsaulnier-ti merged 5 commits into
mainfrom
ADD_PRU_EQEP_PPR_CONFIG
Nov 24, 2026
Merged

nsaulnier-ti merged 5 commits into
mainfrom
ADD_PRU_EQEP_PPR_CONFIG

Conversation

@a1248924

@a1248924 a1248924 commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

-> Make the QPOS wrap value a firmware compile-time setting derived from the
encoder pulses per revolution, and update the R5F application, syscfg and
readme accordingly.

-> Detect lost pulses from phase errors and from reverse edges while the
expected direction is forward. Add the firmware pulse-loss counter, the R5F
sticky flag, the TEST_PULSE_LOSS test option, the readme section and flow
chart.

signed-off by Ayushman [email protected]

@qodo-code-review

qodo-code-review Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Configure PRU eQEP position wrap and add pulse-loss diagnostics

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Make the PRU position counter wrap at a build-time limit derived from encoder pulses per
 revolution.
• Publish last-edge direction and optional reverse-edge counts for R5F diagnostics.
• Document configuration, detection limits, validation, and updated CCS project setup.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 3 capabilities

  • 3 affected capabilities within one bounded functional scope: pru_eqep_encoder_integration.
  • The PRU producer, per-channel DMEM state, and R5F polling/position consumers form one bounded encoder-measurement integration across six cores.
  • The changed direction and position values are consumed as one end-to-end measurement behavior rather than independent technical capabilities.
  • Pulse-loss and phase-error flags are diagnostic outputs of the same bounded encoder integration and are consumed by the same R5F polling/status path.
  • They are a distinct system outcome from raw measurement, but not an independent deployment or functional domain.
  • Status logs are a separate user-facing operation within the same bounded eQEP example integration.
  • They report the encoder and diagnostic state but do not create a separate encoder or deployment domain.
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Coordinated invariants

  • Before: QPOS was treated as a free-running uint32_t and R5F inferred direction from successive QPOS snapshots.
  • After: firmware maintains a bounded counter with increment overflow and decrement underflow transitions, publishes a direction code into shared DMEM, and the R5F consumer interprets that code as a sticky direction.
  • New correctness conditions: the counter must preserve the configured inclusive [0,QPOSMAX] invariant, each of six producer offsets must match its consumer offset, and the R5F must read a value corresponding to the PRU's most recent processed edge.
  • These are newly interacting producer/consumer state conditions, not merely reuse of an existing mapping helper.
Sources

examples/pru_eqep/firmware/include/macros.inc[56-60]

; Position counter maximum value (QPPR * 4 - 1)
QPOSMAX .set 3999

; set below to 1 to enable the firmware pulse loss detection 
PULSE_LOSS_DETECTION   .set    0
Potential damage 🟡 Medium 🩹 Incorrect results

  • A wrong QPOS boundary or wrong LAST_DIR address produces incorrect position or direction readings.
  • The result is recoverable by rebuilding/reflashing and restarting the example, but readings already emitted to a caller or log are not retroactively corrected.
  • No persistent database or external actuator write is present in the inspected path.
  • Code rollback and reflash can restore future readings.
  • Previously observed measurement output must be discarded or recomputed from a valid run; no automatic repair path was found.
Assessed commit c5cf50d
Diagram

graph TD
  CFG["Build-time settings"] --> FW["PRU edge processing"] --> MEM[("Shared PRU DMEM")] --> HOST["R5F polling"] --> OUT["Status and flags"]
  INPUT["Encoder A/B"] --> FW
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Configure QPOSMAX per channel at runtime
  • ➕ Allows different encoder PPR values without rebuilding six firmware images.
  • ➖ Requires a shared-memory configuration protocol and adds initialization or hot-path complexity.

Recommendation: Keep the build-time QPOSMAX for this example: it avoids shared-configuration coordination and keeps the PRU edge path predictable. Consider runtime per-channel configuration only if mixed-PPR encoders become a requirement; the optional pulse-loss mode also needs hardware validation before being treated as a general detector.

Files changed (16) +458 / -259

Enhancement (5) +309 / -211
macros.incDefine position limit and pulse-loss build switch +6/-0

Define position limit and pulse-loss build switch

• Adds the shared QPOSMAX constant, defaulting to 3999 for a 1000-PPR encoder at ×4 decoding. Adds a disabled-by-default firmware pulse-loss switch.

examples/pru_eqep/firmware/include/macros.inc

memory.incReserve register and per-channel diagnostic offsets +14/-1

Reserve register and per-channel diagnostic offsets

• Assigns a register for the cached position limit and DMEM offsets for last direction and pulse-loss counters across all six cores. Corrects the timestamp-buffer size description.

examples/pru_eqep/firmware/include/memory.inc

main.asmWrap position and publish edge diagnostics +19/-38

Wrap position and publish edge diagnostics

• Loads QPOSMAX at boot and wraps forward and reverse position updates at its boundaries. Publishes last-edge direction, optionally counts reverse edges, and removes duplicated buffer-wrap processing and unused Z-reset scaffolding.

examples/pru_eqep/firmware/main.asm

eqep_diagnostic.hExtend per-channel diagnostic state +45/-31

Extend per-channel diagnostic state

• Adds pointers and host-side fields for firmware-published last direction and pulse-loss counts and flags. Removes the position snapshot field no longer used to infer direction.

examples/pru_eqep/mcuplus/eqep_diagnostic.h

pru_eqep_example.cPoll firmware direction and optional pulse loss +225/-141

Poll firmware direction and optional pulse loss

• Maps new per-channel DMEM fields, reads direction directly from firmware, and optionally latches and logs pulse-loss counts. Adds channel-validated host-side flag-clearing functions and removes QPOS-difference direction inference.

examples/pru_eqep/mcuplus/pru_eqep_example.c

Documentation (3) +130 / -28
readme.mdDocument PPR setup, diagnostics, and example operation +126/-28

Document PPR setup, diagnostics, and example operation

• Explains QPOSMAX configuration, optional pulse-loss switches, detection limitations, and phase-error behavior. Adds run instructions and validation details while correcting stale interrupt, Z-reset, and direction guidance.

examples/pru_eqep/readme.md

pulse_loss_detection_flow_chart.pngAdd pulse-loss detection flowchart +0/-0

Add pulse-loss detection flowchart

• Adds the diagram referenced by the new pulse-loss documentation.

examples/pru_eqep/images/pulse_loss_detection_flow_chart.png

readme.mdList PRU eQEP in the examples index +4/-0

List PRU eQEP in the examples index

• Adds a short description of the example and its supported-processor table entry.

examples/readme.md

Other (8) +19 / -20
example.projectspecName the PRU0 CCS firmware project +2/-2

Name the PRU0 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_pru0_fw/ti-pru-cgt/example.projectspec

example.projectspecName the PRU1 CCS firmware project +2/-2

Name the PRU1 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_pru1_fw/ti-pru-cgt/example.projectspec

example.projectspecName the RTU_PRU0 CCS firmware project +2/-2

Name the RTU_PRU0 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_rtu_pru0_fw/ti-pru-cgt/example.projectspec

example.projectspecName the RTU_PRU1 CCS firmware project +2/-2

Name the RTU_PRU1 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_rtu_pru1_fw/ti-pru-cgt/example.projectspec

example.projectspecName the TX_PRU0 CCS firmware project +2/-2

Name the TX_PRU0 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_tx_pru0_fw/ti-pru-cgt/example.projectspec

example.projectspecName the TX_PRU1 CCS firmware project +2/-2

Name the TX_PRU1 CCS firmware project

• Replaces generic project title and description with PRU eQEP firmware identifiers.

examples/pru_eqep/firmware/am243x-lp/icss_g0_tx_pru1_fw/ti-pru-cgt/example.projectspec

example.syscfgConfigure UART logging at 921600 baud +6/-7

Configure UART logging at 921600 baud

• Sets the example's UART baud rate and explicitly disables CSS logging while removing the previous shared-memory logging settings.

examples/pru_eqep/mcuplus/am243x-lp/r5fss0-0_freertos/example.syscfg

example.projectspecRename the R5F CCS project +1/-1

Rename the R5F CCS project

• Changes the generic project title to PRU EQEP.

examples/pru_eqep/mcuplus/am243x-lp/r5fss0-0_freertos/ti-arm-clang/example.projectspec

@qodo-code-review

qodo-code-review Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


View medium (5)
Remediation recommended
1. Readme phase-error table uses tab characters 📘 ⭐
Description
The pulse-loss outcome table and the QPOS-error table added to section 8c contain literal tab
characters between cells, for example after |1, 5, 9, ... and |2, 6, 10, .... The markdown
whitespace rule allows only single spaces, so these tab characters fail the check and can render
inconsistently across editors and diff viewers.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

Issue description
The new pulse-loss detection table in readme.md contains tab characters between cells, which violates the single-space whitespace rule for markdown.

Fix Focus Areas
- examples/pru_eqep/readme.md[216-219]
- examples/pru_eqep/readme.md[225-230]

Recommended Fix
Replace every tab in these table rows with a single space (or rewrite the rows using the `| cell | cell |` form with spaces only).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

2. Clear helper has no cycle budget 📘
Description
The new host function EQEP_PRU_clearPulseLossFlag has a doc block with pseudocode but no
worst-case cycle budget or measurement method, which the rule requires for every new function. It is
a single bounds check and one store, so timing risk is low, but a later reader cannot compare it
against a bound if it is moved into a timing-sensitive path.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new host function `EQEP_PRU_clearPulseLossFlag` in `examples/pru_eqep/mcuplus/pru_eqep_example.c` has a doc block with pseudocode but no worst-case cycle budget or measurement method, as required for every new function.

## Fix Focus Areas
- examples/pru_eqep/mcuplus/pru_eqep_example.c[614-634]

## Recommended Fix
Add a line such as `WCET: <= N cycles (hand-counted: compare, branch, store)` to the doc block above `EQEP_PRU_clearPulseLossFlag`, stating the measurement method. Apply the same to `EQEP_PRU_clearPhaseErrorFlag` if it is touched in this PR.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

3. Channel checks repeat an unnamed limit 📘
Description
EQEP_PRU_clearPhaseErrorFlag and EQEP_PRU_clearPulseLossFlag both compare channel directly
against the literal 6 instead of a named channel-count constant. If the supported channel count
changes, these public APIs can retain stale bounds independently of the six-channel tables and loops
they protect.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new public flag-clearing APIs use the domain-specific literal `6` as their channel upper bound. The same limit is duplicated and can drift from the channel arrays and iteration bounds.

## Fix Focus Areas
- examples/pru_eqep/mcuplus/pru_eqep_example.c[617-620]
- examples/pru_eqep/mcuplus/pru_eqep_example.c[638-641]

## Recommended Fix
Introduce a descriptive shared constant such as `EQEP_CHANNEL_COUNT` for the six supported channels, document its meaning, and replace both `channel >= 6` checks with `channel >= EQEP_CHANNEL_COUNT`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

4. Firmware edits contain repeated spaces 📘
Description
The changed non-markdown source files add consecutive spaces, including trailing spaces in
pru_eqep_example.c and macros.inc. These whitespace sequences violate the single-space source
formatting rule and can cause whitespace-sensitive checks to fail.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

Issue description
The PR adds consecutive and trailing spaces in non-markdown source files.

Fix Focus Areas
- examples/pru_eqep/mcuplus/pru_eqep_example.c[303-316]
- examples/pru_eqep/firmware/include/macros.inc[59-60]

Recommended Fix
Remove trailing whitespace and reduce nonessential consecutive spaces to single spaces throughout the changed source lines, while preserving required assembly syntax.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

5. Unbalanced encoder branches can miss timing targets 📘
Description
The PRU encoder edge-processing path adds overflow, underflow, and optional pulse-loss counter
branches with unequal instruction paths and no nearby cycle-count, padding, or worst-case
execution-time documentation. When an edge crosses a position boundary or takes the pulse-loss path,
it executes a different number of instructions and memory operations from an ordinary edge in a
firmware path the documentation identifies as timing-sensitive.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PRU encoder edge-processing path adds overflow, underflow, and optional pulse-loss work without balanced instruction paths or local worst-case timing documentation.

## Fix Focus Areas
- examples/pru_eqep/firmware/main.asm[141-158]
- examples/pru_eqep/readme.md[214-216]

## Recommended Fix
Calculate the taken and not-taken cycle counts for the new branches using the PRU instruction timing table, including conditional pulse-loss counter work and shared-memory accesses. Add padding or restructure unequal paths to balance their timing. Place comments immediately above the timing-critical branches documenting per-path counts, any padding, the block’s worst-case execution time, and the assumed PRU clock or cycle-counting method.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Comment thread examples/pru_eqep/firmware/main.asm Resolved
@a1248924

Copy link
Copy Markdown
Collaborator Author

/agentic_review

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f8618ff

@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from f8618ff to 2ba57e6 Compare August 21, 2026 06:06
@a1248924

Copy link
Copy Markdown
Collaborator Author

/agentic_review

Comment thread examples/pru_eqep/firmware/main.asm Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 2ba57e6

@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from 2ba57e6 to 90136a2 Compare August 21, 2026 06:27
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 90136a2

@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from 90136a2 to a3ee65e Compare August 31, 2026 08:00
@a1248924

Copy link
Copy Markdown
Collaborator Author

/agentic_review

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a3ee65e

@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from a3ee65e to 496e405 Compare August 31, 2026 08:26
Comment thread examples/pru_eqep/firmware/main.asm Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 496e405

Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/firmware/main.asm Resolved
@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from 496e405 to 9dc4824 Compare September 11, 2026 09:42
Comment thread examples/pru_eqep/firmware/main.asm Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9dc4824

@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from 9dc4824 to f9b5117 Compare September 15, 2026 06:25
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f9b5117

Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/readme.md Resolved
Comment thread examples/pru_eqep/readme.md Resolved
Comment thread examples/pru_eqep/readme.md Resolved
Comment thread examples/pru_eqep/readme.md Resolved
@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch 2 times, most recently from 0490acd to f83407c Compare November 3, 2026 08:22
Comment thread examples/pru_eqep/firmware/main.asm Resolved
manojKoppolu
manojKoppolu previously approved these changes Nov 3, 2026

@pratheesh pratheesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes on f83407ca for four small fixes. The firmware itself looks sound. Three items marked fixed in earlier threads are still present: the flow chart, the pulse-loss clear, and the create_lut() line reference.

Please fix before merge

1. Flow chart: the phase-error box is wrong. images/pulse_loss_detection_flow_chart.png says "1, 2, 5, 6, ... pulses missed" for a phase error. It should say 1, 5, 9. Losing 2, 6 or 10 pulses gives a decrement and no phase error, as the readme table and the box below it already say.

2. EQEP_PRU_clearPulseLossFlag() still doesn't stick after a phase error. pru_eqep_example.c:417 still ORs in the sticky phase_error_flag, so the flag sets again on the next poll unless the phase-error flag is cleared too. Please compare against a last-seen phase-error count in the pulse-loss block instead of using the sticky flag.

3. Docs that no longer match the code.

  • readme.md:176 and pru_eqep_example.c:78 say the R5F reads QPOSMAX, and main.asm:64 gives that as the reason for publishing it. The R5F read was removed.
  • pru_eqep_example.c:101 points to readme section 8e, which is now 8c.
  • readme.md:231 gives create_lut() as line 545. It is at line 530. Naming the function without a line number would stop this recurring.

4. readme.md:216, "short by N", is only true for multiples of 4. That wording came from my October review, and it was wrong. Simulator results for N lost pulses in forward motion:

N mod 4 Examples Phase errors Reverse edges counted QPOS short by
1 1, 5, 9 1 0 N+1
2 2, 6, 10 0 1 N+2
3 3, 7, 11 0 0 N+1
0 4, 8, 12 0 0 N

This also affects readme.md:137, which says QPOS isn't corrupted by phase errors. Losing 1 pulse leaves it 2 counts short.

Should fix

  • Z can report a false pulse loss. This PR removes the Z logic but leaves Z in A_B_Z_GPI_mask. In the simulator, a Z high/low pulse while A/B is 01 or 10 added two phase errors. In every A/B state it added two ring-buffer entries, and in 00 or 11 it wrote last_dir = 0, which the docs don't list as a value. The default syscfg muxes slice 1 GPI2, the Z input for Ch3-5, and the readme says Z isn't wired. I haven't checked the pull setting. Dropping Z from the masks removes the problem.
  • Dither counts as pulse loss. One back-and-forth step with no lost pulse increments the counter. The forward-only note in section 8c should mention vibration at standstill.
  • Two separate switches. With TEST_PULSE_LOSS on and PULSE_LOSS_DETECTION off, the 2, 6, 10 cases go undetected with no warning. Please use one switch or make the dependency explicit.
  • Test coverage. The "not yet exercised" caveat and the PENDING row are still removed, and section 1 lists no bench test for wraparound or pulse loss. Could you add those results, or restore the caveat for what hasn't been run?
  • Console baud rate. example.syscfg now sets 921600, and the readme doesn't mention it.
  • Cleanup. The PR description is empty and the title doesn't mention pulse loss. Commit subjects such as "fix issue 'Clean up PR155'" need rewording, and sign-offs should be proper Signed-off-by: trailers. The no_buffer_wrap label, the CH*_QPOSMAX_OFFSET defines and prev_QPOS are now unused. DMEM_CHANNEL_SIZE is 0x400 but its comment says 4KB. The readme has no trailing newline.

What checks out

  • All six cores assemble clean on clpru 2.3.3 with PULSE_LOSS_DETECTION at 0 and 1.
  • QPOS wraps correctly in both directions (3999 to 0 and 0 to 3999), and last_dir reports the right direction.
  • The r25 change, mov QPOS, qposmax_reg, the dead-block removal and the project title are all done properly.
  • Simulator cycles per edge, compared with the base branch: increment stays at 35, and decrement goes from 36 to 38, or 44 with detection on. That matches the readme's +6, so I withdraw my earlier objection to that figure.
  • The qodo volatile finding doesn't apply here, because HW_RD_REG8 and HW_RD_REG32 already read through volatile pointers.

How this was tested

I ran only the PRU0 image, in pru-simulator, so none of this is hardware evidence. I did not compile the R5F code with TEST_PULSE_LOSS on, so item 2 comes from reading the code.

@a1248924

Copy link
Copy Markdown
Collaborator Author

regarding this comment : Z can report a false pulse loss. This PR removes the Z logic but leaves Z in A_B_Z_GPI_mask. In the simulator, a Z high/low pulse while A/B is 01 or 10 added two phase errors. In every A/B state it added two ring-buffer entries, and in 00 or 11 it wrote last_dir = 0, which the docs don't list as a value. The default syscfg muxes slice 1 GPI2, the Z input for Ch3-5, and the readme says Z isn't wired. I haven't checked the pull setting. Dropping Z from the masks removes the problem.
Dither counts as pulse loss. One back-and-forth step with no lost pulse increments the counter. The forward-only note in section 8c should mention vibration at standstill.

will fix in a seperate PR to add Z pulse support for this example

Comment thread examples/pru_eqep/firmware/main.asm Resolved
Comment thread examples/pru_eqep/readme.md Resolved

@pratheesh pratheesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked my 11-03 review against f816cca4. All four must-fix items are fixed, and nothing blocks merge from my side. What's left is small.

Fixed, with how I checked:

  1. Flow chart: the phase-error box now says 1, 5, 9 and the decrement box 2, 6, 10.
  2. EQEP_PRU_clearPulseLossFlag() now sticks. The flag latches only when the PRU pulse-loss counter differs from pulse_loss_count_last_seen, and the phase-error flag is no longer ORed in. I checked this by reading the code and didn't run it.
  3. Docs match the code: the QPOSMAX publish block and the R5F-read wording are gone, the C comment points to 8c, and the readme refers to create_lut() by name.
  4. The N-mod-4 table is right. I re-ran pru-simulator on the PRU0 image for N = 1..12 lost pulses in forward motion, and phase errors, reverse edges counted and QPOS shortfall all match the readme table. Line 139's "losing 1 pulse leaves QPOS 2 short" also matches.

Also fixed: dither and vibration are documented in 8c note 1 (simulator: one back-and-forth step adds 1 to the counter and leaves QPOS unchanged), the 921600 baud rate is documented, commit subjects are reworded with proper Signed-off-by: trailers, the unused label, defines and prev_QPOS are removed, DMEM_CHANNEL_SIZE says 1KB, and the readme ends with a newline.

Regression checks:

  • All six cores assemble clean on clpru 2.3.3 with PULSE_LOSS_DETECTION at 0 and at 1.
  • In the simulator, QPOS wraps 3999 to 0 and 0 to 3999, and last_dir reads 1 forward and 2 reverse.
  • Cycles per edge are unchanged from my last check: increment 35, decrement 38, or 44 with detection on.
  • pru_eqep_example.c passes a syntax check (tiarmclang -fsyntax-only -Wall, SDK 12.01) with and without TEST_PULSE_LOSS, using stubbed generated headers. That is not a full CCS build.

Still worth fixing:

  • The TEST_PULSE_LOSS log doesn't print phase_error_flag. In that build, the 1-second print shows only pulse_loss_flag, and the PhaseErr line exists only in the non-test branch. The readme says to watch either flag, so as it stands the 1, 5, 9 losses don't show up in the test output. Printing PhaseErr in the test branch too would fix it.
  • Section 8b should also say to rebuild the R5F project. Qodo is right here: the app embeds all six images through *_load_bin.h, so rebuilding only the PRU projects and reflashing the old app keeps the old QPOSMAX.
  • Z false pulse loss (you said a separate Z PR will handle it): until then, please add one line to the readme. The simulator still shows Z toggling while A/B is 01 or 10 adding two phase errors, and the default syscfg muxes the Ch3-5 Z pin.
  • PR title and description: the title mentions only pulses per revolution, and the description is just a sign-off line. Please mention pulse-loss detection and list what changed.
  • Readme line 23: please say whether "Tested with QPOSMAX=3999" was on the bench or in the simulator. Line 24 already says pulse loss was tested only in the simulator.
  • Stale comments: pru_eqep_example.c:56 DMEM_CH1_OFFSET 0x400 says "base + 4KB", and main.asm:48 says "8 kB" while MAX_BUFFER is 1 kB.
  • Nits: Qodo's three-space indent at pru_eqep_example.c:189-193 and "i.e." at main.asm:135. To enable TEST_PULSE_LOSS (:93-94), you have to move the */, not just uncomment a line.

The Z and dither behaviour comes from pru-simulator, not hardware.

Make the QPOS wrap value a firmware compile-time setting derived from the
encoder pulses per revolution, and update the R5F application, syscfg and
readme accordingly.

Signed-off-by: Ayushman <[email protected]>
Detect lost pulses from phase errors and from reverse edges while the
expected direction is forward. Add the firmware pulse-loss counter, the R5F
sticky flag, the TEST_PULSE_LOSS test option, the readme section and flow
chart.

Signed-off-by: Ayushman <[email protected]>
Address review feedback on PR155: update the per-core example.projectspec
files, the readme and the pulse loss flow chart.

Signed-off-by: Ayushman <[email protected]>
Remove unused firmware code and the R5F QPOSMAX references that are no longer
needed, and correct the related documentation.

Signed-off-by: Ayushman <[email protected]>
Code:
- Make pulse_loss_flag latch only when the PRU pulse-loss counter changes,
  so clearing it sticks after a phase error (was OR-ed with the sticky
  phase_error_flag).
- Stop publishing QPOSMAX to DMEM1 from main.asm and remove the unused
  CH*_QPOSMAX_OFFSET and QPOSMAX_OFFSET defines; the R5F no longer reads it.
- Remove unused no_buffer_wrap label and prev_QPOS field.
- Correct the DMEM_CHANNEL_SIZE comment (1KB) and the readme section
  reference (8c).

Docs:
- Fix the phase-error box in the pulse loss flow chart (1, 5, 9, ...).
- Replace the "short by N" claim with the per-N-mod-4 QPOS error table and
  qualify the phase-error note in the debug tips.
- Document that TEST_PULSE_LOSS and PULSE_LOSS_DETECTION must both be set,
  and that dither at standstill is counted as pulse loss.
- Add wraparound and pulse loss rows to the testing summary, document the
  921600 baud console setting, drop the unused QPOSMAX row from the DMEM1
  map, and add a trailing newline to the readme.

Signed-off-by: Ayushman <[email protected]>
@a1248924
a1248924 force-pushed the ADD_PRU_EQEP_PPR_CONFIG branch from f816cca to c5cf50d Compare November 23, 2026 06:48
@a1248924 a1248924 changed the title am243x : add configuration of pulse per revolution am243x : add configuration of pulse per revolution and pulse loss detection Nov 23, 2026
Comment thread examples/pru_eqep/readme.md Resolved
@a1248924
a1248924 requested a review from pratheesh November 23, 2026 08:41

@pratheesh pratheesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked my 11-20 notes against c5cf50db. This push is a rebase onto current main plus changes to the last commit: the first four commits are unchanged, and the main.asm changes are comments only, so my earlier assembly, simulator and cycle results still apply. All seven of my remaining items are addressed. Nothing blocks merge from my side.

  • The TEST_PULSE_LOSS log now prints PhaseErr next to the pulse-loss flag, inside the test branch, so 1, 5, 9 losses show up in the test output.
  • Section 8b now says to rebuild the R5F project after the firmware.
  • Note 3 in 8c documents the Z behaviour. It matches what I saw in the simulator.
  • The PR title and description now cover pulse-loss detection and list the changes.
  • Readme line 23 says the QPOSMAX=3999 wraparound was bench tested.
  • The 4KB/8KB channel-offset comments and the "8 kB" buffer comment are fixed.
  • TEST_PULSE_LOSS is now a standalone commented-out line, and the "i.e." is gone.

Optional tidy-ups, none of them blocking:

  • The three-space indent is fixed for the "PRU1 Cores" block, but the rest of EQEP_pruss_load_run_fw() still uses it (pru_eqep_example.c:195-220).
  • Qodo's tab finding is real: the two tables in 8c (readme.md:216-219, 225-230) use tab characters. GitHub renders them fine. The new note 3 line also has trailing spaces.
  • On the other Qodo findings: the "cycle budget" for EQEP_PRU_clearPulseLossFlag() doesn't apply, because that is R5F C code, not PRU firmware. The branch-timing point is already measured and documented: increment 35 cycles, decrement 38, or 44 with detection on. A named constant instead of the literal 6 in the two clear functions would be nice, but it's not needed.

@pratheesh-ti pratheesh-ti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@nsaulnier-ti nsaulnier-ti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't review the code changes, but documentation updates look good.

@nsaulnier-ti
nsaulnier-ti merged commit 6400bd6 into main Nov 24, 2026
14 checks passed
@nsaulnier-ti
nsaulnier-ti deleted the ADD_PRU_EQEP_PPR_CONFIG branch November 24, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants