Problem with dac0 of arduino due

void produce_sound(float arr[],int len)
{
  //Serial.println(len);
  for(int i=0;i<len;i++)
  {
    //analogWrite(DAC1,0);
    analogWrite(DAC1,10*(arr[i]));
    //Serial.println(arr[i]);
    delayMicroseconds(23);
    }     
    
  }

here arr is a look up table and len is its length. I use a trrs breakout board connections are tip represents left earphone ring1 represents right ear phone , ring2 represents ground and sleeve represents microphone. I have connected tip to dac1, ring1 to dac0 as i have no use with sleeve i have left it connection less and ring2 to ground. The problem here is when i give signal to dac1 my left ear phone produces sound perfectly fine but when signal is given to dac0 there is no sound.
Is my dac0 not working properly?? and my arduino due is also making noise is there any problem with my arduino

do you have an oscilloscope to look at the output signals
e.g. this is using a DUE to output sine waves on DAC0 and DAC1
image

remember the DAC output is positive voltage

Are the waveforms generated by my code

bit difficult as you only give a small fragment of your code
the code used was

// Arduino Due - use DAC0 and DAC1 to generate two sine waves

// from https://forum.arduino.cc/t/how-can-i-get-2-sin-waves-on-the-due-at-same-time-one-out-of-phase-with-other/217778/4

const uint16_t sinTable[] = {
0x7ff, 0x823, 0x846, 0x86a, 0x88e, 0x8b1, 0x8d5, 0x8f9, 0x91c, 0x93f,
0x963, 0x986, 0x9a9, 0x9cc, 0x9ee, 0xa11, 0xa33, 0xa56, 0xa78, 0xa9a,
0xabb, 0xadd, 0xafe, 0xb1f, 0xb40, 0xb60, 0xb81, 0xba1, 0xbc0, 0xbe0,
0xbff, 0xc1e, 0xc3c, 0xc5a, 0xc78, 0xc95, 0xcb2, 0xccf, 0xcec, 0xd08,
0xd23, 0xd3e, 0xd59, 0xd73, 0xd8d, 0xda7, 0xdc0, 0xdd8, 0xdf1, 0xe08,
0xe1f, 0xe36, 0xe4c, 0xe62, 0xe77, 0xe8c, 0xea0, 0xeb4, 0xec7, 0xeda,
0xeec, 0xefe, 0xf0f, 0xf1f, 0xf2f, 0xf3f, 0xf4d, 0xf5c, 0xf69, 0xf77,
0xf83, 0xf8f, 0xf9a, 0xfa5, 0xfaf, 0xfb9, 0xfc2, 0xfca, 0xfd2, 0xfd9,
0xfdf, 0xfe5, 0xfeb, 0xfef, 0xff3, 0xff7, 0xffa, 0xffc, 0xffd, 0xffe,
0xfff, 0xffe, 0xffd, 0xffc, 0xffa, 0xff7, 0xff3, 0xfef, 0xfeb, 0xfe5,
0xfdf, 0xfd9, 0xfd2, 0xfca, 0xfc2, 0xfb9, 0xfaf, 0xfa5, 0xf9a, 0xf8f,
0xf83, 0xf77, 0xf69, 0xf5c, 0xf4d, 0xf3f, 0xf2f, 0xf1f, 0xf0f, 0xefe,
0xeec, 0xeda, 0xec7, 0xeb4, 0xea0, 0xe8c, 0xe77, 0xe62, 0xe4c, 0xe36,
0xe1f, 0xe08, 0xdf1, 0xdd8, 0xdc0, 0xda7, 0xd8d, 0xd73, 0xd59, 0xd3e,
0xd23, 0xd08, 0xcec, 0xccf, 0xcb2, 0xc95, 0xc78, 0xc5a, 0xc3c, 0xc1e,
0xbff, 0xbe0, 0xbc0, 0xba1, 0xb81, 0xb60, 0xb40, 0xb1f, 0xafe, 0xadd,
0xabb, 0xa9a, 0xa78, 0xa56, 0xa33, 0xa11, 0x9ee, 0x9cc, 0x9a9, 0x986,
0x963, 0x93f, 0x91c, 0x8f9, 0x8d5, 0x8b1, 0x88e, 0x86a, 0x846, 0x823,
0x7ff, 0x7db, 0x7b8, 0x794, 0x770, 0x74d, 0x729, 0x705, 0x6e2, 0x6bf,
0x69b, 0x678, 0x655, 0x632, 0x610, 0x5ed, 0x5cb, 0x5a8, 0x586, 0x564,
0x543, 0x521, 0x500, 0x4df, 0x4be, 0x49e, 0x47d, 0x45d, 0x43e, 0x41e,
0x3ff, 0x3e0, 0x3c2, 0x3a4, 0x386, 0x369, 0x34c, 0x32f, 0x312, 0x2f6,
0x2db, 0x2c0, 0x2a5, 0x28b, 0x271, 0x257, 0x23e, 0x226, 0x20d, 0x1f6,
0x1df, 0x1c8, 0x1b2, 0x19c, 0x187, 0x172, 0x15e, 0x14a, 0x137, 0x124,
0x112, 0x100, 0xef, 0xdf, 0xcf, 0xbf, 0xb1, 0xa2, 0x95, 0x87,
0x7b, 0x6f, 0x64, 0x59, 0x4f, 0x45, 0x3c, 0x34, 0x2c, 0x25,
0x1f, 0x19, 0x13, 0xf, 0xb, 0x7, 0x4, 0x2, 0x1, 0x0,
0x0, 0x0, 0x1, 0x2, 0x4, 0x7, 0xb, 0xf, 0x13, 0x19,
0x1f, 0x25, 0x2c, 0x34, 0x3c, 0x45, 0x4f, 0x59, 0x64, 0x6f,
0x7b, 0x87, 0x95, 0xa2, 0xb1, 0xbf, 0xcf, 0xdf, 0xef, 0x100,
0x112, 0x124, 0x137, 0x14a, 0x15e, 0x172, 0x187, 0x19c, 0x1b2, 0x1c8,
0x1df, 0x1f6, 0x20d, 0x226, 0x23e, 0x257, 0x271, 0x28b, 0x2a5, 0x2c0,
0x2db, 0x2f6, 0x312, 0x32f, 0x34c, 0x369, 0x386, 0x3a4, 0x3c2, 0x3e0,
0x3ff, 0x41e, 0x43e, 0x45d, 0x47d, 0x49e, 0x4be, 0x4df, 0x500, 0x521,
0x543, 0x564, 0x586, 0x5a8, 0x5cb, 0x5ed, 0x610, 0x632, 0x655, 0x678,
0x69b, 0x6bf, 0x6e2, 0x705, 0x729, 0x74d, 0x770, 0x794, 0x7b8, 0x7db,
};

void setup() {
  analogWriteResolution(12);
}

void loop() {
 for(int i=0; i<360; i++) {
 analogWrite(DAC0, sinTable[i]);
 int k=i+180;
 if(k>= 360) k=k-360;
 analogWrite(DAC1, sinTable[k]);
 //delay(1);
 }
}

however, the DAC write is similar to yours

is there any other way to check my dac

if you run my code and connect a headphone via a capacitor ( to remove the DC offset) you should hear a 374Hz tone - not tried this I always use an oscilloscope to looks at waveforms

iam getting tone only from left one

Did you try swapping DAC0 and DAC1 in the code to test the for loop logic?

I have two Arduino Due boards - ran same code on both
board 1: DAC0 and DAC1 OK
board 2: only DAC1 working DAC0 gives 0v output

I guess I must have run my original tests on board 1 to get the scope output

yes...no tone from dac0

does that mean my dac0 is faulty

Show me your wiring..

You should simplify your test code, to rule out any possible errors there...

I have connected tip of trrs breakout board to dac1, ring1 to dac0 as i have no use with sleeve i have left it connection less and ring2 to ground

You're telling me you connected low impedance hardware directly to a Due output pin?

You probably blew the pin. :frowning:

I have been using dac1 from a very long time and there was no issue with that

I defer to your superior engineering knowledge. Good luck with your project.

can you try the below code with the board2 and can you tell me whether dac0 is working or not

/*
  Melody on pin 8 of DUE
 
 http://arduino.cc/en/Tutorial/Tone
 
 */

// notes in the melody:
int melody[] = { 2000,3000,6000,5000,1000,2000,4000,3000
  /*NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4*/ };

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  2000,2000,2000,2000,2000,2000,2000,2000 };
int minFrequency;       // The minimum frequency of the range
int maxFrequency;       // The maximum frequency of the range

void setup() {
  pinMode(DAC0,OUTPUT);
}
float angle;
void loop() {
  // iterate over the notes of the melody:

  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = noteDurations[thisNote];
    tone(DAC0, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    delay(noteDuration);
    // stop the tone playing:
    noTone(DAC0);
  }
  delay(3000);
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = noteDurations[thisNote];
    tone(DAC1, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    delay(noteDuration);
    // stop the tone playing:
    noTone(DAC1);
  }
  delay(3000);
//ring2 gnd sleeve headset
}


/*
 Tone generator
 v1  use timer, and toggle any digital pin in ISR
   funky duration from arduino version
   TODO use FindMckDivisor?

   
   timer selected will preclude using associated pins for PWM etc.
    could also do timer/pwm hardware toggle where caller controls duration
*/


// timers TC0 TC1 TC2   channels 0-2 ids 0-2  3-5  6-8     AB 0 1
// use TC1 channel 0 

#define TONE_TIMER TC1
#define TONE_CHNL 0
#define TONE_IRQ TC3_IRQn

// TIMER_CLOCK4   84MHz/128 with 16 bit counter give 10 Hz to 656KHz
//  piano 27Hz to 4KHz

static uint8_t pinEnabled[PINS_COUNT];
static uint8_t TCChanEnabled = 0;
static boolean pin_state = false ;
static Tc *chTC = TONE_TIMER;
static uint32_t chNo = TONE_CHNL;

volatile static int32_t toggle_count;
static uint32_t tone_pin;

// frequency (in hertz) and duration (in milliseconds).

void tone(uint32_t ulPin, uint32_t frequency, int32_t duration)
{
    const uint32_t rc = VARIANT_MCK / 256 / frequency; 
    tone_pin = ulPin;
    toggle_count = 0;  // strange  wipe out previous duration
    if (duration > 0 ) toggle_count = 2 * frequency * duration / 1000;
     else toggle_count = -1;

    if (!TCChanEnabled) {
      pmc_set_writeprotect(false);
      pmc_enable_periph_clk((uint32_t)TONE_IRQ);
      TC_Configure(chTC, chNo,
        TC_CMR_TCCLKS_TIMER_CLOCK4 |
        TC_CMR_WAVE |         // Waveform mode
        TC_CMR_WAVSEL_UP_RC ); // Counter running up and reset when equals to RC
  
      chTC->TC_CHANNEL[chNo].TC_IER=TC_IER_CPCS;  // RC compare interrupt
      chTC->TC_CHANNEL[chNo].TC_IDR=~TC_IER_CPCS;
       NVIC_EnableIRQ(TONE_IRQ);
                         TCChanEnabled = 1;
    }
    if (!pinEnabled[ulPin]) {
      pinMode(ulPin, OUTPUT);
      pinEnabled[ulPin] = 1;
    }
    TC_Stop(chTC, chNo);
                TC_SetRC(chTC, chNo, rc);    // set frequency
    TC_Start(chTC, chNo);
}

void noTone(uint32_t ulPin)
{
  TC_Stop(chTC, chNo);  // stop timer
  digitalWrite(ulPin,LOW);  // no signal on pin
}

// timer ISR  TC1 ch 0
void TC3_Handler ( void ) {
  TC_GetStatus(TC1, 0);
  if (toggle_count != 0){
    // toggle pin  TODO  better
    digitalWrite(tone_pin,pin_state= !pin_state);
    if (toggle_count > 0) toggle_count--;
  } else {
    noTone(tone_pin);
  }
}

Please consult the GPIO pin maximum output current in Table 45-2 on page 1379 of the SAM data sheet.

I'll take that data over, "I have used it for a very long time and there was no issue".

I can see that you don't care, I am posting for other forum members who may read this.

It's a little bit weird that you are ignoring this, because it is exactly related to the problem that you are now having.

works OK on both boards generating tones

then what might be the problem..dac0 is working for that code but not for the another code