DAC from Portenta H7

I tried again, here what I've found.

Verified (correct):

  • DAC out is PA6 - correct as A6 on header pins
  • I tried via toggling PA6 as GPIO, checking interactive PCB viewer - it is correct

But I've found some issues:

  • the mbed function analogout_write(&myDac, 0.5); seems to expect a floating point value
  • it seems to be the multiplier as: DACout = Value * VREF+
  • every value larger as 1.0 sets the maximum VREF+ voltage
  • VREF+ is not stable: it has 100K to 3V1 and it changes voltage if DAC changes output voltage
  • you have to provide a stable VREF+, on first pin of the header, e.g. connect it with 3V3 (pin 3 on other header - then it makes sense and seems to work

Here is my Scatch to use DAC: use values as 0.0 to 1.0 and provide a stable VREF+.

#include "AnalogOut.h"
#include "hal/analogout_api.h"

////AnalogOut *dac;
dac_t myDac;

void setup() {
  // put your setup code here, to run once:
  const PinMap *pinMap;
  pinMap = analogout_pinmap();

  pinMode(LEDR,OUTPUT);
  pinMode(LEDG,OUTPUT);
  pinMode(LEDB,OUTPUT); 

  digitalWrite(LEDR, HIGH); //red LED OFF - wait for terminal: default 9600baud
  digitalWrite(LEDG, HIGH); //HIGH is OFF!
  digitalWrite(LEDB, HIGH);

  // Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("*** DAC demo setup ***");
  Serial.printf("pin: 0x%x\n", pinMap->pin);

  ////dac = AnalogOut(pinMap->pin);
  analogout_init_direct(&myDac, pinMap);
  analogout_write(&myDac, 2048);
}

void loop() {
  Serial.println("Loop | DAC demo:");

  //ATTENTION: it looks like the value paramter has to be a float number
  //it is: Value * VREF+, so 1.0 is the max value, every value larger as 1
  //will generate always the same VREF+ voltage on PA6 (A6)

  digitalWrite(LEDG, HIGH);
  analogout_write(&myDac, 0);
  delay(4000);
  digitalWrite(LEDG, LOW);
  analogout_write(&myDac, 0.3);
  delay(4000);
  digitalWrite(LEDG, HIGH);
  analogout_write(&myDac, 0.5);
  delay(4000);
  digitalWrite(LEDG, LOW);
  analogout_write(&myDac, 1.0); //seems to set VREF+
  //ATTENTION: VREF+ is not stable (100K), it changes reference voltage:
  //connect VREF+ with 3V3 - then it makes sense!
  //it looks like, for DAC - you had to provide a VREF+ on first pin
  delay(4000);
}