Problem with MCP4725 i2c delay

Example from Library Adafruit_MCP4725.h trying to generate tringle wave but unknown delay 600ms after every loop. Someone can help?

#include <Wire.h>
#include <Adafruit_MCP4725.h>
int timee=0;
Adafruit_MCP4725 dac;
void setup()
{  
Serial.begin(9600);
dac.begin(0x60);
}
void loop()
{
timee = millis();
Serial.println(timee);
   for (int counter = 0; counter < 4096; counter++)
   {
     dac.setVoltage(counter, false);
   }
   
   for (int counter = 1; counter > 4096; counter--)//4095
   {
     dac.setVoltage(counter, false);
   }
timee = millis();
Serial.println(timee);
}

Monitor resoults:

1752
1752
2336
2336
2920
2920
3505
3505
4088
4088

Are you sure the delay is after each loop() ? Try this instead:

#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
void setup()
{  
Serial.begin(9600);
dac.begin(0x60);
}
void loop()
{
   static uint32_t timee = millis();

   for (int counter = 0; counter < 4096; counter++)
   {
     dac.setVoltage(counter, false);
   }
   
   for (int counter = 1; counter > 4096; counter--)//4095
   {
     dac.setVoltage(counter, false);
   }

   Serial.print( "for loops took " );
   Serial.print( millis() - timee );
   Serial.println( " ms to complete." );
}

Also your second for loop won’t run at all

timee = millis();

The millis() does not return an int. You should NOT be storing the returned value in an int.

for (int counter = 1; counter > 4096; counter--)//4095
Starting with counter equal to 1, while counter is greater than 4096, do some stuff and then decrement counter by 1. The body of that statement will never be executed.

Anonymous printing sucks. It takes almost no effort to print
Time at start of loop: xxxxx
Time at end of loop: xxxxx

instead of
xxxxx
xxxxx

It makes no sense to do the slowest part of loop() at nearly the slowest speed possible.

Flush the data before looping, and you'll see that the start time of one iteration of loop() is nearly the ame as the end time of the previous iteration of loop().

OK thanks Paul and Guix ! I will corect code and let you know.

Hello Again code corrected and still problem:

#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
unsigned long timee=0;
unsigned long timee1=0;
unsigned long timee2=0;
void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
    timee=millis();
    uint32_t counter;
    // Run through the full 12-bit scale for a triangle wave
    for (counter = 0; counter < 4095; counter++)
    {
      dac.setVoltage(counter, false);
    }
    for (counter = 4095; counter > 0; counter--)
    {
      dac.setVoltage(counter, false);
    }
    timee1=millis();
    timee2=timee1 - timee;
    Serial.print("offset:");Serial.println(timee2);

}

Resoult:

offset:514
offset:514
offset:513
offset:513
offset:514
offset:513
offset:513
offset:514
offset:514
offset:513
offset:514
offset:514
offset:513
offset:513

:-(((

and still problem:

What IS the problem?

I2C is slow, if you need more speed you could try increase I2C clock speed (may not be possible, depending on which arduino you use), or use an SPI device instead

Brattain problem with delay 500ms after each loop.

zejd:
Brattain problem with delay 500ms after each loop.

You do NOT know where the delay occurs because you will not print anything useful.

Serial.print() the millis() value WITH IDENTIFICATION at the start of loop().
Serial.print() the millis() value WITH IDENTIFICATION at the end of loop().
Serial.flush() at the end of loop(), so that loop doesn't start again until all the serial data has been sent.

You will then see that your assumptions are all WRONG.