[Solved] Using a DAC (MCP4911) instead of a low-pass filter

Hi, my chips arrived today!

I tested it on its own, and it works fine (it seems to be using 12-bit values and it doesn't quite go up to 5V, but I think that's because I'm running of USB right now).

I tried to fuse the example with my webserver code, and it sort of works... I put this in loop():

  unsigned long currentMillis = millis();
  
  if(currentMillis - previousMillis == 500) {
    previousMillis = currentMillis;
    analogOut.setValue_A(cnt);
    cnt += 20;
    if (cnt > 4095) {
      cnt = 0;
    }
  }

The voltage increases as expected... until I try to load my page! The voltage stays constant after that.

I'm really hoping that my final implementation works properly. The voltage will not be increasing at a constant rate, but will be decided by a controller several times a second. Hopefully loading a page will not affect this!

But if it does... is there a way to specify a different MOSI pin for my DAC? I'm guessing that's where the conflict is coming from...

Edit: I added a println() to see what was going on. When I load a page it stops changing cnt. I won't be using cnt in my final sketch so I don't think it will be a problem! :disappointed_relieved:

Edit2: It seems the webserver stops whatever I have in the if statement, I'll have to fix this...

Edit3: Everything works fine if I use >= instead of ==, which I suppose is okay, the page doesn't refresh anyway. Crisis averted! But my controllers do use a constant sampling interval...