I have this code. MCP4725 DAC Code.
I am taking rectangular pulse output with frequency of 3.2 kHz maximum. Whatever I increase or decrease the delay at the end, this frequency does not increase. I want it to be 20 kHz.
Here the output.
executes in 0 us! It turns out that if you look at the setVoltage() method prototype it sets the i2c frequency to 400000. 3 bytes are transmitted at 400Khz over i2c which takes approximately 60us. Therefore there is no way to to reach 20Khz with this code.
What type of Arduino are you using? You should be able to easily generate a 20Khz signal using a time library. I have used TimerOne library to generate square waves. You can also set the duty cycle as well.
A DAC is not the best way to generate a square wave.