Sawtooth waveform with the Arduino Due’s Built-In DAC

Users of the ATmega328 based Arduino boards will recognize that the analogWrite() function doesn’t actually do anything analog.  It just sets the duty cycle of a pulse width modulated (PWM) signal.  The (new) Arduino Due board, which I have had limited time to play with, actually sports two Analog DAC channels.
Sawtooth Waveform
Using a very simple for() loop, it is possible to generate a sawtooth waveform using these channels.

Long comments, URLs, and code tend to get flagged for spam moderation. No need to resubmit.

ALL comments submitted with fake or throw-away services are deleted, regardless of content.

Don't be a dweeb.

Leave a comment

5 thoughts on “Sawtooth waveform with the Arduino Due’s Built-In DAC

  1. Hi James,

    Excellent blog with helpful information.

    I was wondering how you used for loop to generate the sawtooth. Is there a sample code I can refer to?

    Thanks!

    • It was just a simple for() loop. Something along the lines of:

      int x=0;
      for(x=0; x<256; x++) {
      analogWrite(pin,x);
      delay(50);
      }

      Changing the delay helps modify the waveform (I don't recall if I used a delay or not.)

  2. James,
    Nice blog!
    I saw your post on Arduino website and I say, wait a minute, I know this guy.

    BTW, DAC together with peripheral DMA can make you saw waveform go even higher frequency.

  3. Muy buenas, mira lo que pasa es que estoy trabajando con el DAC del arduino due, necesito obtener una señal rampa o diente sierra que trabaje a una frecuencia minima de 1KHz con una resolucion de 12 Bits, hasta el momento solo he logrado obtener la señal a 12 Bits, con una frecuencia de 70.8 Hz lo cual es muy lento para el trabajo que estoy realizando, si le bajo la resolucion la frecuencia aumenta un poco, pero en la verdad no me sirve perder resolucion, por favor le agradeceria me guiara en como hizo para obtener dicha señal a esa frecuencia, si me puede pasar el codigo se lo agradeceria.

    Muchas gracias