Skip to content

Move sine mode to timer based non blocking - #455

Merged
AlkaMotors merged 6 commits into
mainfrom
improvement/timer_sine_mode
Nov 7, 2026
Merged

AlkaMotors merged 6 commits into
mainfrom
improvement/timer_sine_mode

Conversation

@AlkaMotors

Copy link
Copy Markdown
Collaborator

No description provided.

@tridge tridge added the AIReview label Nov 5, 2026
@AP-Review

AP-Review commented Nov 5, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-05)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 58a8ce3ee6.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/am32-firmware/am32/455/1.html#prAM32-455

This PR moves sine startup onto the COM timer, but a throttle excursion into the changeover band and back can leave sine mode stalled, which needs fixing before merge.

Blocking

  1. Src/main.c:2428: if input goes into 137..200 and then drops back below 137 before phase A reaches 0, this DISABLE_COM_TIMER_INT() turns the sine timer off but leaves sine_timer_active set. The restart at line 2437 is then skipped and the PWM compares stay at 0, so the motor stops under throttle until input goes <=48 or >200. Reproduced in SITL: 8 of 8 dips stall, against 0 of 8 on main. Calling stopSineTimer() in the do_once_sinemode block fixes it.

Low

  • Src/main.c:957: the comment says COM_TIMER runs at 2 MHz on all MCUs, but AT32F415 TMR11 uses div=75 (TMR9/TMR10 use 143 for 1 MHz), so it ticks at about 1.89 MHz and sine speed is about 5% slow there. Fix the comment or set the ARR per MCU.
Minor (1)
  • Src/main.c:946: timer sine adds about 600-720 B of flash on non-E230 targets (F031 +604 B, now 23232/27424 B). Everything links, but trimming could help on the 32K parts. E230 shrinks by about 3.8 KB.

Not fully reviewed: V203 builds (no RISC-V toolchain) and anything on real hardware, including timer and IRQ behaviour and the E230 register-level conversion.

@AP-Review

AP-Review commented Nov 6, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-06)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 711ba35cb8.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/am32-firmware/am32/455/2.html#prAM32-455

No blocking problems remain at 711ba35; one low-severity comment fix is still worth doing.
Since 58a8ce3 the cancelled-changeover stall is fixed: stopSineTimer() at the start of the do_once_sinemode block lets sine restart after a throttle dip out of the 137..200 band, which checks out in SITL (0/8 dips stall, was 8/8) and in an extracted-code test.

Low

  • Src/main.c:957: F415 COM_TIMER is not 2 MHz (still open). TMR11 runs at 144/76, about 1.9 MHz, so sine startup is about 5% slow there. Fix the comment or set ticks/us per MCU.
Minor (1)
  • Src/main.c:946: timer sine flash cost (still open). About +600-700 B on non-E230 targets (F031 +604 B), while E230 shrinks by about 3.8 KB; everything links. For information only.

Not fully reviewed: V203 builds (no RISC-V toolchain) and anything on real hardware, including the periodic COM timer's reload and IRQ behaviour and the E230 register-level conversion.

@AlkaMotors
AlkaMotors force-pushed the improvement/timer_sine_mode branch from 711ba35 to 9f301d1 Compare November 7, 2026 15:03
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 9f301d1862.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/am32-firmware/am32/455/3.html#prAM32-455

No blocking problems at 9f301d1; two low-severity fixes are worth making.
Since 711ba35 the branch was rebased onto main and gained 9f301d1, which clears demag state on sine entry and at changeover; the earlier cancelled-changeover fix still holds after the rebase (extracted-code harness 718/718, SITL dip test 8/8).

Low

  • Src/main.c:973: F415 COM_TIMER is not 2 MHz (still open). TMR11 runs at 144 MHz/76, so the 50 us sine tick is about 53.3 us and sine startup is about 5% slow there. Fix the comment or set ticks/us per MCU.
  • Src/main.c:1005: sine_ccr_offset/sine_ccr_scale are only computed in startSineTimer(), so changing SINE_MODE_POWER over DroneCAN during sine startup has no effect until sine restarts (the old advanceincrement() used the live value). Recompute them when the parameter changes, or document that it needs a restart.
Minor (1)
  • Src/main.c:962: timer sine flash cost (still open). About +600-880 B on non-E230 targets (F031 +648 B, V203 +880 B), while E230 shrinks by about 3.8 KB; every image links. For information only.

Not fully reviewed: anything on real hardware, including the periodic COM timer's reload and IRQ behaviour on each MCU and the E230 register-level conversion, plus live DroneCAN parameter changes.

AlkaMotors and others added 2 commits November 7, 2026 12:05
A demag watchdog or coasting state left over from six step commutation
carried through sine mode, and the changeover commutate() then skipped
comStep() because demag_state was still DEMAG_COASTING.
@AlkaMotors
AlkaMotors force-pushed the improvement/timer_sine_mode branch from 9f301d1 to a8f0eff Compare November 7, 2026 16:08
@AlkaMotors
AlkaMotors merged commit 9e19f28 into main Nov 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants