DAC usage



  • How can I make use of the DAC on the Spresense? I'm using the Arduino IDE abd would prefer to stay there as opposed to working with nuttx (it seems far less clear how to use all of the low level stuff)

    I couldn't figure out which pins are used and it seems it is a PDM based DAC and not a traditional DAC that one would user for audio purposes. I'm synthesizing sound, so I'd like to be able to build the waveforms in real time and set the DAC at 44khz if possible.

    Or should I just go for an external DAC?
    Also, for the ADC, can I increase sampling rate by simply setting registers using the Arduino IDE?


  • DeveloperWorld

    Hi @the_mutt

    I use the Arduino IDE with Linux so my path are how it looks like for in Ubuntu. If you use an other OS you will have to find your installation path for that OS.

    For the DAC question:
    In the file:
    ~/.arduino15/packages/SPRESENSE/hardware/spresense/1.1.2/variants/spresense/pins_arduino.h

    You will find how the PWM pins map to the regular GPIO pin names:
    #define PIN_PWM_0 PIN_D06
    #define PIN_PWM_1 PIN_D05
    #define PIN_PWM_2 PIN_D09
    #define PIN_PWM_3 PIN_D03

    This is for the standard Arduino compatible analog out case.

    If you want to output proper audio via the built in Class D amplifier you can use the audio library instead.

    You could in the Arduino IDE open the File menu and select an appropriate example sketch: E.g File->Examples->Audio->application->player
    should give you a hint on how to write data to the audio amplifier.

    @the_mutt said in DAC usage:

    I couldn't figure out which pins are used and it seems it is a PDM based DAC and not a traditional DAC that one would user for audio purposes. I'm synthesizing sound, so I'd like to be able to build the waveforms in real time and set the DAC at 44khz if pos



  • Thank you Karl! I haven't had a chance to look at the player example in detail and test out my idea yet, but does it sound feasible for me to write out the audio data sample by sample (at around 44kHz I mean) ?

    I couldn't find any data on how long a write to the amplifier takes, so hence my question.



  • I've just tested out the beep example and it worked! I think with this I'll be able to adapt it to what I intend to do. Thanks again Karl!

    EDIT: Does the setBeep function affect the possibility of using the ADC or the timing of it? @TE-KarlKomierowski


  • DeveloperWorld

    @the_mutt said in DAC usage:

    I've just tested out the beep example and it worked! I think with this I'll be able to adapt it to what I intend to do. Thanks again Karl!

    Hi @the_mutt
    Sorry for long time for the reply.
    Great to hear that you managed to solve this.
    Will this work be published somewhere? Like hackster? Just curious to see what you have built there.



  • @TE-KarlKomierowski Yes, I'll be posting it to Hackster under the Make It Better contest.

    So far it seems to be working as I hoped, although I've still got to figure out some details over the weekend.