Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal DAC outputs to available opamp inputs. #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidstalnaker
Copy link

This is done by adding internal structs for the DAC outputs and passing these into the constructor functions instead of an input pin, e.g. opamp1.follower(Dac3Out1, Some(gpioa.pa2.into_analog()));

I've tested that this works at least with opamps 1, 3, 4, and 5 in follower mode on an STM32G473. Can't verify everything of course but I don't see anything obvious that would break elsewhere, and it at least builds for other devices.

After writing this I now see related work in #113. If I'm reading right, I think this change is completely orthogonal and should merge with that one pretty cleanly.

This is done by adding internal structs for the DAC outputs and passing
these into the constructor functions instead of an input pin, e.g.
`opamp1.follower(Dac3Out1, Some(gpioa.pa2.into_analog()));`

/// Internal output of DAC 4 channel 2.
pub struct Dac4Out2;

Copy link
Contributor

Choose a reason for hiding this comment

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

We have the channel types from the dac module if we want to use those. I believe that would force the user to pass in the DAC they actually initialized, reducing the risk of error.

Copy link
Author

Choose a reason for hiding this comment

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

I like the idea but I don't think taking ownership of the DAC channel works in this case, for two reasons:

  1. The same DAC output can be used as input for multiple opamps (dac3ch1 can go to opamps 1 and 6 simultaneously, verified that this works).
  2. The user wouldn't be able to set the DAC's value (or other configuration) after setting up the opamp. There's some cases where that's ok (if using DMA) but the easiest setup would become impossible.

Copy link
Contributor

@usbalbin usbalbin Feb 21, 2024

Choose a reason for hiding this comment

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

Passing by reference would probably be enough. As long as the OPAMP does not keep the reference, the dac can still be modified and similar which I believe would solve both 1 and 2?

Copy link
Contributor

@usbalbin usbalbin Feb 21, 2024

Choose a reason for hiding this comment

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

Something similar is done for the comparator.

Usage looks like this

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.

2 participants