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.


Fan of making things beep, blink and fly. Created AddOhms. Writer for News. Freelance electronics content creator for hire! KN6FGY and, of course, bald.


  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?


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

      int x=0;
      for(x=0; x<256; x++) {

      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.

    • Hey Buli cool that you found my blog! I’ll be in Greenville the week of April 14th.

  3. Marcos Monsalve Reply

    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

Write A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.