Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Testing if DAC pins are working

  1. #1
    Senior Member Projectitis's Avatar
    Join Date
    Feb 2018
    Location
    New Zealand
    Posts
    114

    Testing if DAC pins are working

    Hi all,

    I may have fried my DAC pins on T_3.6 (but I'm unsure how). I just stopped getting audio while debugging a project.
    I've tried a very simple sketch (below) to see if they are working, but I read no voltage between the pin and AGND (either pin).
    Is my sketch correct? Do I need to initialise the DAC pins first? Or is there another way to test for fried DAC pins?

    Code:
    void setup() {
      	// put your setup code here, to run once:
    	analogWrite( 21, (uint32_t)(4095 * 1) );
    	analogWrite( 22, (uint32_t)(4095 * 0.5) );
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    	
    }

  2. #2
    Senior Member Projectitis's Avatar
    Join Date
    Feb 2018
    Location
    New Zealand
    Posts
    114
    Sorry, basic mistake. The pins aren't 21 and 22, they are A21 and A22!

    Code:
    void setup() {
      	// put your setup code here, to run once:
    	analogWrite( A21, (uint32_t)(4095 * 1) );
    	analogWrite( A22, (uint32_t)(4095 * 0.5) );
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    	
    }

  3. #3
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,719
    Running on a 3.6 here the code points to digital pin21/22 not A21/22

    try

    Code:
    void setup() {
        // put your setup code here, to run once:
      analogWrite( A21, (uint32_t)(4095 * 1) );
      analogWrite( A22, (uint32_t)(4095 * 0.5) );
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
        analogWrite( A21, (uint32_t)(4095 * 1) );
      analogWrite( A22, (uint32_t)(4095 * 0.5) );
    delay(500);
        analogWrite( A21, (uint32_t)(0) );
      analogWrite( A22, (uint32_t)(0) );
      
    delay(500);
    }
    Edit - looks like you already found it -though I see the same upper value for A21 and A22 so looks like some integer math going on.

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,719
    Ah - missing step
    analogWriteResolution(12);
    takes analog write from the default 8 bit to where 4095/2 is half VCC

  5. #5
    Senior Member Projectitis's Avatar
    Join Date
    Feb 2018
    Location
    New Zealand
    Posts
    114
    Thanks GremlinWrangler. Almost all of the DAC examples and threads I can find are specifically for the Audio shield, so finding relevant info is quite tricky!

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,416
    FWIW, here is a sketch i use for testing DAC with ADC (and a digital pin to see voltage threshold)
    https://github.com/manitou48/teensy3...ter/dacadc.ino
    jumper the DAC pin to the ADC and digital pin

  7. #7
    Senior Member Projectitis's Avatar
    Join Date
    Feb 2018
    Location
    New Zealand
    Posts
    114
    Awesome, thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •