analogWrite DAC only once for each pinMode( ,OUTPUT)

Nope, we hope 0.4.8 will contain the fix.

any ETA on a release? is there a blog from particle I can follow that discusses how development is going? I think in the future it would be important to introduce unit/regression testing into the development processes to reduce these types of issues.

You can have a look in the open sources (and you’ll also find unit tests there :wink: - OK regressions … hmm … :sunglasses: )

And here you can keep track of things
https://github.com/spark/firmware/issues

I’ve heard rumours about 0.4.8 being released this week, but no guarantees :confused:

What should the output voltage be on the DAC pin (or DAC2 for that matter) when you HAL_DAC_Write a 0 to it. I’m seeing just a touch over 57mv after writing 0 to the DAC. a true zero is important since I’m driving a power MOSFET through an op amp to isolate it and the small voltage causes the MOSFET to leak about 80ma of current when it should be zero (at cutoff).

The changelog for 0.4.8 didn’t mention the DAC. Any ideas if it’s been fixed, or if it’s been rescheduled for 0.4.9 (and when that might be released)?

Thanks

I am playing around with the DAC1 and it is only outputting 3.3 volts. Has this been fixed?

0.4.9 should have a fix and come next week (if no other issues pop up preventing this)

The fix is in the develop branch - would appreciate if someone can confirm the fix!

@mdma I will try to test it. Just checkout the latest from git (spark/firmware), build and download?

With the CAN driver also be in there now?

Thanks for testing and thanks again for the CAN driver contribution. The CAN driver PR hasn’t been merged yet. You can see the current status by looking at the PR - it’s still open. When merged, you’ll be notified (because you opened the PR), plus the status will be updated to “Merged”. Cheers! :smile:

I tested the DAC1 function using the develop branch, and I can confirm that the output produces a sawtooth waveform when using the following code,

    int pin = DAC1;
    uint16_t i = 0;
    
    void setup() {
        pinMode(pin, OUTPUT);
    }
    
    void loop() {
        analogWrite(pin, (i+=10) % 4096);
    }
1 Like

Thanks for testing! :smile:

i also confirm that it is working.

1 Like

That's cool. If I hook DAC1 (pinA6) up to an LED it flashes very nicely.

Never seen this style before

 analogWrite(pin, (i+=10) % 4096);

Kind of cool way to add 10 to "i" then modulus max amount 4096 (remainder). I assume when "i" gets to the uint16_t maximum it resets to zero, add-infinitum.

Nice to prove DAC1 works, thanks for the code.

1 Like

I wish I could take the credit for that stylish piece of code, but I borrowed that from a response @ScruffR made in this thread.

2 Likes

So here is my code, which tests both DAC1 (A6) and DAC2 (A3), very simple, my students should be able to understand it and it works.

void setup() {
    pinMode(DAC1, OUTPUT);    // pin A6
    pinMode(DAC2, OUTPUT);    // pin A3
    pinMode(D7, OUTPUT);
    digitalWrite(D7, HIGH);
    delay(2000);
    digitalWrite(D7, LOW);


}

void loop() {

    analogWrite(DAC1, 4095);
    analogWrite(DAC2, 4095);
    delay(1000);
    
    analogWrite(DAC1, 0);
    analogWrite(DAC2, 0);
    delay(1000);
    
    analogWrite(DAC1, 0);
    analogWrite(DAC2, 3000);
    delay(1000);
    
    analogWrite(DAC1, 3000);
    analogWrite(DAC2, 0);
    delay(1000);
     
    analogWrite(DAC1, 0);
    analogWrite(DAC2, 0);
    delay(1000);   

    
}

And here is the setup gnd-resistor-switch-LED-DAC. Make sure the LED is pointing away from the DAC1 Positive flow.

1 Like

What’s the minimum voltage of the DACs on Photons? When I analogWrite(DAC1, 0) the output gets set to 0.047V. Is there anyway to pull it all the way to ground?

Thanks

The DACs don’t go full range. You can check out the STM32 datasheet for details - http://www.st.com/web/en/resource/technical/document/datasheet/CD00237391.pdf section 6.3.21.

Hi! I used almost your exact code snippet but after 5-6 seconds the Photon flashes magenta and restarts. It doesn’t return to the working code once rebooted, it remains in a funky state until I reprogram it. After reprogramming it snaps back into functioning as expected for a few seconds and then flashes magenta and reboots. Ideas?

Firmware version of my photon is 0.5.1.
Code in *.ino file: (building through build.particle.io site)

int led = DAC1;

void setup() {
pinMode(led,OUTPUT);
}

void loop() {
pinMode(led, OUTPUT);
analogWrite(led, 4095); //3.3V
delay(1000);
pinMode(led, OUTPUT);
analogWrite(led, 2048); //1/2 of 3.3V
delay(1000);
}

LEDs are no good target for DACs :wink:
And 0.5.1 should not require pinMode() over and over again.

Can you do a

particle serial inspect

in Listening Mode and post the output