Repository navigation
am243x : add configuration of pulse per revolution and pulse loss detection - #162
Conversation
PR Summary by QodoConfigure PRU eQEP position wrap and add pulse-loss diagnostics
AI Description
Merge Risk
|
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit f8618ff |
f8618ff to
2ba57e6
Compare
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 2ba57e6 |
2ba57e6 to
90136a2
Compare
|
Code review by qodo was updated up to the latest commit 90136a2 |
90136a2 to
a3ee65e
Compare
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit a3ee65e |
a3ee65e to
496e405
Compare
|
Code review by qodo was updated up to the latest commit 496e405 |
496e405 to
9dc4824
Compare
|
Code review by qodo was updated up to the latest commit 9dc4824 |
9dc4824 to
f9b5117
Compare
|
Code review by qodo was updated up to the latest commit f9b5117 |
0490acd to
f83407c
Compare
pratheesh
left a comment
There was a problem hiding this comment.
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:176andpru_eqep_example.c:78say the R5F reads QPOSMAX, andmain.asm:64gives that as the reason for publishing it. The R5F read was removed.pru_eqep_example.c:101points to readme section 8e, which is now 8c.readme.md:231givescreate_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 wrotelast_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_LOSSon andPULSE_LOSS_DETECTIONoff, 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.syscfgnow 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. Theno_buffer_wraplabel, theCH*_QPOSMAX_OFFSETdefines andprev_QPOSare now unused.DMEM_CHANNEL_SIZEis 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_DETECTIONat 0 and 1. - QPOS wraps correctly in both directions (3999 to 0 and 0 to 3999), and
last_dirreports 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
volatilefinding doesn't apply here, becauseHW_RD_REG8andHW_RD_REG32already 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.
|
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. will fix in a seperate PR to add Z pulse support for this example |
f83407c to
4da4007
Compare
4da4007 to
f816cca
Compare
pratheesh
left a comment
There was a problem hiding this comment.
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:
- Flow chart: the phase-error box now says 1, 5, 9 and the decrement box 2, 6, 10.
EQEP_PRU_clearPulseLossFlag()now sticks. The flag latches only when the PRU pulse-loss counter differs frompulse_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.- 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. - 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_DETECTIONat 0 and at 1. - In the simulator, QPOS wraps 3999 to 0 and 0 to 3999, and
last_dirreads 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.cpasses a syntax check (tiarmclang -fsyntax-only -Wall, SDK 12.01) with and withoutTEST_PULSE_LOSS, using stubbed generated headers. That is not a full CCS build.
Still worth fixing:
- The
TEST_PULSE_LOSSlog doesn't printphase_error_flag. In that build, the 1-second print shows onlypulse_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:56DMEM_CH1_OFFSET 0x400says "base + 4KB", andmain.asm:48says "8 kB" whileMAX_BUFFERis 1 kB. - Nits: Qodo's three-space indent at
pru_eqep_example.c:189-193and "i.e." atmain.asm:135. To enableTEST_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]>
f816cca to
c5cf50d
Compare
pratheesh
left a comment
There was a problem hiding this comment.
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_LOSSlog 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_LOSSis 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.
nsaulnier-ti
left a comment
There was a problem hiding this comment.
Didn't review the code changes, but documentation updates look good.
-> 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]