Skip to content

core: arduino: analogWrite: Fix DAC output calculation#374

Open
soburi wants to merge 1 commit intoarduino:mainfrom
soburi:improve_analog_write_dac
Open

core: arduino: analogWrite: Fix DAC output calculation#374
soburi wants to merge 1 commit intoarduino:mainfrom
soburi:improve_analog_write_dac

Conversation

@soburi
Copy link

@soburi soburi commented Mar 1, 2026

  • Correct max value calculation
  • Add guard for DAC entry is not defined case
  • initialize only if DAC not initialized

@soburi soburi marked this pull request as ready for review March 1, 2026 16:11
Copilot AI review requested due to automatic review settings March 1, 2026 16:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Zephyr-based Arduino core’s DAC-backed analogWrite() to produce correct full-scale outputs, avoid setup work on every call, and compile cleanly when DAC channel configuration is missing from the devicetree.

Changes:

  • Fix DAC max/output scaling by mapping to (2^resolution - 1) and clamping the input range.
  • Add devicetree guard for missing dac-channels and make analogWrite(DAC…) a no-op when not defined.
  • Initialize DAC channels once (per channel) and only after verifying the DAC device is ready.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cores/arduino/zephyrCommon.cpp Adds guarded DAC channel config, one-time channel setup, input clamping, and corrected max/output scaling for DAC writes.
cores/arduino/Arduino.h Guards DAC enum expansion so builds succeed when dac-channels isn’t defined in the devicetree.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi force-pushed the improve_analog_write_dac branch from b373f7c to e0e5e23 Compare March 1, 2026 16:35
@soburi soburi requested a review from Copilot March 1, 2026 16:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@per1234 per1234 added the bug Something isn't working label Mar 2, 2026
- Correct max value calculation
- Add guard for DAC entry is not defined case
- initialize only if DAC not initialized

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the improve_analog_write_dac branch from e0e5e23 to a039a68 Compare March 16, 2026 21:53
@github-actions
Copy link

Built 0.53.2-0.dev+a039a686

CI run PASSED 🟢

ArtifactBoardCoreTestsRAMSketchesWarningsErrors
zephyr_contrib ek_ra8d1 📗

11.9%

2--
frdm_mcxn947 3 🏷️

58.0%

2--
frdm_rw612 1 🏷️

83.0%

2--
✔️* zephyr_main giga 4 🏷️ ✅*

54.5%

448-
nano33ble 1 🏷️ ✅*

78.7%

228-
nano_matter 📗 ✔️*

⚠️ 85.7%

208(2*)
niclasense 2 🏷️ ✅*

⚠️ 87.3%

208-
opta 4 🏷️ ✔️*

46.7%

548(2*)
portentac33 3 🏷️ ✔️*

⚠️ 95.1%

568(8*)
portentah7 3 🏷️ ✔️*

47.3%

588(2*)
✅* zephyr_unoq unoq 📗 ✅*

26.4%

608-
Legend

BoardTestStatus description
🔥 🔥 Test run failed to complete.
🔴 Test completed with unexpected errors.
✔️* 🚫 Test completed with errors, but all are known/expected.
✅* 🟡 Test completed with some warnings; no errors detected.
🟢 Test passed successfully, with no warnings or errors.
🌑 🌑 Test was skipped.

@soburi
Copy link
Author

soburi commented Mar 17, 2026

@pillo79

This is the same issue as #373, so please check it if you have the time.

@CLAassistant
Copy link

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants