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

esp32/DAC: Add cosine generator capability #5514

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tschmid
Copy link

@tschmid tschmid commented Jan 10, 2020

The ESP32's DAC has the capability to generate constant waveforms. This
commit extends the machine.DAC interface of the ESP32 port to expose
this feature.

TODO:

  • Move detailed DAC function description to docs/library/esp32.rst and update
  • Move rtc_clk_div to esp library
  • tone tone type
  • KW args for constructor

The ESP32's DAC has the capability to generate constant waveforms. This
commit extends the machine.DAC interface of the ESP32 port to expose
this feature.
Decided to split the call into two such that the RTC clock divider
can be left alone, in case another peripheral is using and setting
it already.
Copy link
Contributor

@tve tve left a comment

Choose a reason for hiding this comment

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

Cool! I'm looking forward to using this, I also appreciate that you wrote docs! :-)

The main issue I see is that the driver doesn't follow the model of the others I've seen WRT initialization. In general, I see an init method that takes a slew of KW args to set all the features and a constructor that accepts the same set of KW args (usually all handled in one init_helper function). I would prefer new drivers to follow this model, but I don't really know what the general strategy is.

Unit tests?

# frequency steps for the CW generator, (7, 1) -> ~15 Hz


ESP32 specific DAC class method reference:
Copy link
Contributor

Choose a reason for hiding this comment

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

This doc is just the quick reference. You should place the detailed docs into docs/library/esp32.rst - IMHO

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, I mirrored what the ADC does? Should that be moved too?

``clk_8m_div`` is the divider and must be between 0 and 7.

.. Warning::
Be cautious in changing this value as it might affect other peripherals that use the 8 MHz RTC clock!
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this method be in a different class if it affects the system globally? E.g. ESP32.rtc_clk_div? I know it's more work, but it would be awful to have 2-3 peripherals that each have an rtc_clk_div method and that conflict with one another because they really adjust the same thing.

Copy link
Author

Choose a reason for hiding this comment

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

Agree. Will move that over and make a note about it in the reference for the frequency set function

SET_PERI_REG_MASK(SENS_SAR_DAC_CTRL1_REG, SENS_SW_TONE_EN);
switch(self->dac_id) {
case DAC_CHANNEL_1:
// Enable / connect tone tone generator on / to this channel
Copy link
Contributor

Choose a reason for hiding this comment

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

"tone tone"


ESP32 specific DAC class method reference:

.. method:: DAC.cosine_enable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you decide to break cosine_enable/disable out into their own methods as opposed to simply providing a cosine=True/False keyword parameter to the make_new constructor or actually to an init method? This really also applies to the frequency_step method. Unless these get called while the DAC is operating, they would be simpler just as KW args in the constructor/init IMHO.

Copy link
Author

Choose a reason for hiding this comment

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

Will have to do both as you can enable/disable this feature during run-time.

@projectgus
Copy link
Contributor

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

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

Successfully merging this pull request may close these issues.

None yet

4 participants