strange behavior of T3.2 DAC

Fenichel

Well-known member
As part of my modular datalogger project, I have been developing a depth monitor for my backyard pond. The sensor just lets the pond water (more of it when the water level is higher) be part of a voltage divider, where the voltage is supplied by a Teensy.

There is a tiny bit more to this than one might think. To keep electroplating effects and biofilms from degrading the sensor, it's prudent to run the test current in one direction for the measurement, then to run it in the reverse direction for equally long, and then to stop the current until another reading is needed.

I originally connected the sensor directly to a Teensy indoors, 10 meters away. This was a bad idea, because the sensor is a high-impedance source, the cable was effectively an antenna, and the small voltage changes with changing water depth were usually lost in noise.

Now I want to put a weather-proofed Teensy out near the pond, and to let it generate a lower-impedance voltage to send to the indoor Teensy. That should be simple.

The attached .zip file includes the Teensy program and the schematic for the pondside Teensy board. The program's loop just
  • sets up a voltage across the divider
  • waits for a settling time
  • reads the voltage from the divider
  • sets the DAC to produce that voltage
  • reverses the voltage across the divider
  • waits for the same settling time
  • waits for a while before looping

This almost works. The attached .jpg image shows two cycles of the loop. First the current flows for a reading (intervals marked 1, yellow above cyan), then it flows in reverse (intervals marked 2, cyan above yellow), then it rests (intervals marked 3, cyan and yellow both low). The voltage divider (here shown in magenta and seeing a constant "pond" resistance of 11K), seems to be doing what it should.

The DAC (here shown in blue) is not behaving as expected. Since it is set only during the 1 intervals, it should here have been constant across the screen, with a voltage similar to that produced by the divider during the 1 intervals. Instead, it drops to a low level during every 2 or 3 interval. The unrelated writes to the D02 and D03 pins seem to be resetting it.

Any suggestions will be welcome.
 

Attachments

  • depth sensor.zip
    20.3 KB · Views: 26
  • depth_sensor.jpg
    depth_sensor.jpg
    142.4 KB · Views: 27
You might add analogWriteResolution(12) to setup() (default is 8 bit), so the DAC resolution matches the 12-bit ReadResolution.
 
You might add analogWriteResolution(12) to setup() (default is 8 bit), so the DAC resolution matches the 12-bit ReadResolution.
I hadn't known about analogWriteResolution, and it's probably a good idea to put in that call to complement the analogReadResolution call.

On the other hand, it's unlikely to solve the problem I asked about. Something is changing the DAC output when no such change is programmed, and that doesn't seem like a resolution mismatch.
 
AND, DAC is pin A14 (NOT 14) , change to
const int pinAnalogOut = A14;

DAC can only drive about 1 ma
 
Last edited:
Terrific, that solved it. I can stare at syntax things like this for hours and never see them. Thanks.

Although that solved the problem, I still don't understand why the program was doing what it was doing. It was writing to D02, D03, D13 and (when it should have been writing to A14) to D14.
  • Why was the DAC producing any output at all, when I never wrote to A14?
  • Why was the DAC changing its output, when I wrote to D02 & D03 & D13?
 
Back
Top