Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

digital to analog triangle curve
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

digital to analog triangle curve

by cfloryiv on Sun Aug 19, 2012 4:13 pm

Is anybody getting strange results when they put the triangle generator through their oscilliscope?
Attachments
triangle.jpg
triangle.jpg (16.43 KiB) Viewed 1274 times

cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

Re: digital to analog triangle curve

by adafruit_support_mike on Mon Aug 20, 2012 11:21 am

What you're seeing is the classic resistor-capacitor charge/discharge curve.

The voltage across a capacitor rises as current flows in, falls as current flows out. The voltage across a reisistor is proportional to the current through it. When you charge a cap through a resistor, the voltage across the resistor falls as the voltage in the cap rises, meaning less current can flow through the resistor into the cap for further charging. The result is the kind of curve you see on your scope.

I don't recall an Adafruit triangle generator off the top of my head though.. what exact circuit are you using?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: digital to analog triangle curve

by cfloryiv on Mon Aug 20, 2012 11:59 am

That's what I tought. I'm just using the standard breakout board that Adafruit sells. The hookups are voltage, ground, address selecter, voltage out, clock and data. There are no capacitors in the circuit. I've tried getting the voltage off the arduino, from a battery and from a bench power supply. They all show the same curve.

cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

Re: digital to analog triangle curve

by adafruit_support_mike on Tue Aug 21, 2012 8:01 pm

So you're using the MCP4725 12-bit DAC breakout board, and running Adafruit's 'trianglewave.pde' sketch?

If so, let's try benchmarking things a little: try a stepped triangle wave like so:

Code: Select all | TOGGLE FULL SIZE
for (counter=0 ; counter < 4095 ; counter += 100) {
    dac.setVoltage( counter, false );
    delay( 10 );
}
for (counter=4095 ; counter >0 ; counter -= 100) {
    dac.setVoltage( counter, false );
    delay( 10 );
}

and see what you get on the 'scope. If you see wierd slewing from that, we can decide what to poke next.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: digital to analog triangle curve

by cfloryiv on Thu Aug 23, 2012 4:56 pm

here's the new waveform. I can't make sense of it. The curve rises too quickly.
Attachments
triangle.jpg
triangle.jpg (18.39 KiB) Viewed 1223 times

cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

Re: digital to analog triangle curve

by adafruit_support_mike on Thu Aug 23, 2012 6:16 pm

Hmm, looks like the first loop isn't executing. I'm inclined to think that's a code problem rather than a hardware problem though.

The down slope doesn't show any of the RC curvature from the first trace, so that much is good.

Let's try rolling everything into a single loop:

Code: Select all | TOGGLE FULL SIZE
for (counter=0 ; counter < 80 ; counter++) {
    dac.setVoltage( (100 * abs( 40 - counter )), false );
    delay( 5 );
}

That should make the wave an all-or-nothing kind of thing. If you don't get any output at all, check the surrounding code for missing semicolons and such. If you get a triangle wave, try stepping the delay down to 2, then 1, and see if any sign of the RC curve comes back.

If you get anything other than a triangle wave, post the whole sketch and we'll make sure there are no lurking typos or other gotchas.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: digital to analog triangle curve

by cfloryiv on Sat Aug 25, 2012 12:10 pm

Here's the latest waveform from my picoscope. The triangle wave reappeared when I changed the upper limit from 4095 to 4000.

Code: Select all | TOGGLE FULL SIZE
/**************************************************************************/
/*!
 @file     trianglewave.pde
 @author   Adafruit Industries
 @license  BSD (see license.txt)
 
 This example will generate a triangle wave with the MCP4725 DAC.   
 
 This is an example sketch for the Adafruit MCP4725 breakout board
 ----> https://www.adafruit.com/products/???
 
 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!
 */
/**************************************************************************/
#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

void setup(void) {
  Serial.begin(9600);
  Serial.println("Hello!");

  // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
  // For MCP4725A0 the address is 0x60 or 0x61
  // For MCP4725A2 the address is 0x64 or 0x65
  dac.begin(0x62);

  Serial.println("Generating a triangle wave");
}

void loop(void) {
  uint32_t counter;
  // Run through the full 12-bit scale for a triangle wave
  for (counter = 0; counter < 4000; counter+=100)
  {
    dac.setVoltage(counter, false);
    //dac.setVoltage(0, false);
  }
  for (counter = 4000; counter > 0; counter-=100)
  {
    dac.setVoltage(counter, false);
    //dac.setVoltage(4095, false);
  }
 // for (counter=0 ; counter < 80 ; counter++) {
 //   dac.setVoltage( (100 * abs( 40 - counter )), false );
  //  delay( 1 );
  //}

}

Attachments
20120825-0001.png
20120825-0001.png (26.41 KiB) Viewed 1195 times

cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

Re: digital to analog triangle curve

by adafruit_support_mike on Sat Aug 25, 2012 7:20 pm

Good.. that's one problem out of the way. There may have been a limit problem with the loop.

From the sketch, it looks like you're running the loop at full speed (no delay()), so we're not running into charging problems there.

Next come a couple of things:

First, keep the hardware and software exactly the same, but run the same test on your Tek. If you get two different curves from two different scopes, it means something is funky in one of the machines. Maybe one of your scope probes has a lot more capacitance than you expected.

Second, start reducing the step size in the loops.. from 100 to 50, to 20, 10, 5, 2, and finally 1. Keep the upper limit at 4000, just see if the RC curve starts to come back. If you get all the way down to a step size of 1 and still have a triangle wave, start raising the upper limit on the loop and see how close to 4095 you can get.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: digital to analog triangle curve

by cfloryiv on Tue Aug 28, 2012 4:37 am

It just seems to be an issue with the tek scope when running with a step of one. The pico scope doesnt show the charging artifact. I'm ready to move on to another project. Thanks for your help.

cfloryiv
 
Posts: 38
Joined: Tue Dec 27, 2011 10:06 am

Please be positive and constructive with your questions and comments.