I am not be able to plot the Sawtooth wave for 51.2 khz on serial plotter.

#include "DueTimer.h"

/*

  • Sawtooth waveform generation using timer
  • Wave frequency = wf (Hz)
  • Samples per pulse = wn (num)
  • So tatal samples passed per second to O/P = wf * wn
  • i.e. timer frequncy to write out, tf = wf * wn
    */

uint32_t wf =51200 ; // Frequency of 51.2kHz
uint32_t wn = 120; // Length of saw in this program
uint32_t tf = wf * wn;

uint32_t wi;

int saw[] = {
0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc, 0xee, 0x110, 0x132, 0x154,
0x176, 0x198, 0x1ba, 0x1dc, 0x1fe, 0x220, 0x242, 0x264, 0x286, 0x2a8,
0x2ca, 0x2ec, 0x30e, 0x330, 0x352, 0x374, 0x396, 0x3b8, 0x3da, 0x3fc,
0x41e, 0x440, 0x462, 0x484, 0x4a6, 0x4c8, 0x4ea, 0x50c, 0x52e, 0x550,
0x572, 0x594, 0x5b6, 0x5d8, 0x5fa, 0x61c, 0x63e, 0x660, 0x682, 0x6a4,
0x6c6, 0x6e8, 0x70a, 0x72c, 0x74e, 0x770, 0x792, 0x7b4, 0x7d6, 0x7f8,
0x81a, 0x83c, 0x85e, 0x880, 0x8a2, 0x8c4, 0x8e6, 0x908, 0x92a, 0x94c,
0x96e, 0x990, 0x9b2, 0x9d4, 0x9f6, 0xa18, 0xa3a, 0xa5c, 0xa7e, 0xaa0,
0xac2, 0xae4, 0xb06, 0xb28, 0xb4a, 0xb6c, 0xb8e, 0xbb0, 0xbd2, 0xbf4,
0xc16, 0xc38, 0xc5a, 0xc7c, 0xc9e, 0xcc0, 0xce2, 0xd04, 0xd26, 0xd48,
0xd6a, 0xd8c, 0xdae, 0xdd0, 0xdf2, 0xe14, 0xe36, 0xe58, 0xe7a, 0xe9c,
0xebe, 0xee0, 0xf02, 0xf24, 0xf46, 0xf68, 0xf8a, 0xfac, 0xfce, 0xff0
};

void tHandler() {
// Write the sawtooth wave sample to DAC1
analogWrite(DAC1, saw[wi]);

// Print saw wave in serial plotter
Serial.println(saw[wi]);
Serial.print(" ");

// Increment index to next sample or reset it if at the last sample
wi = wi + 1;
if (wi == wn) {
wi = 0;
}
}

void setup() {
// Can be changed to control phase of the O/P
wi = 0;

// Set BAUD rate for Serial stuffs
Serial.begin(9600);

// Set DAC1 for output
pinMode(DAC1, OUTPUT);

// Set resolution of DAC at 12 bits
analogWriteResolution(12);
// Reset analog pin to 0 before starting waveform
analogWrite(DAC1, 0);

// Bind TC3 with ISR, set frequency and start it
Timer2.attachInterrupt(tHandler).setFrequency((double)tf).start();

}

void loop() {
while(1) {
// delayMicroseconds(5000);// Main Loop is not required as ISR handles the waveform work.
}

}

_51.2_khz.zip (4.86 KB)

uint32_t wf =51200 ; // Frequency of 51.2kHz

doesn't square with a glacial baudrate:

  // Set BAUD rate for Serial stuffs
  Serial.begin(9600);

You also seem to be trying to do serial output from an interrupt handler - that can't work
as serial I/O is itself interrupt driven.