Ttreintaysiete / ardcore

Building docs, Hardware resources and Sketches updated to the new ardcore hardware
13 stars 6 forks source link

Jumping weird behaviour from DAC output… #8

Open hedefalk opened 6 years ago

hedefalk commented 6 years ago

Finally I have it working! I burnt my homebrewed AVR programmer but yesterday I got a usbasp in the mail ($1 one from China :) ) so now I'm up and running again. Had some more soldering issues, but now I get stuff out, even from the DAC, but I have really weird behaviours.

To simplify, I have this basic 2s square wave sketch:

#include <SPI.h>         // Remember this line!
#include <DAC_MCP49x1.h>

#define SS_PIN 10

DAC_MCP49x1 dac(DAC_MCP49x1::MCP4901, SS_PIN);

void setup() {
  dac.setSPIDivider(SPI_CLOCK_DIV16);
    dac.setPortWrite(true);
}

void loop() {
  dac.output(0);
  delay(2000);
  dac.output(4095);
  delay(2000);
}

The output puts out a value when said so but then slowly moves towards ground:

image

Anything you've seen before?

hedefalk commented 6 years ago

More debugging. What comes out of the DAC is fine. Also what comes out of the first opamp, but the after the second one it's this kind of wave instead of the square.

Not sure I understand everything about the circuit here, but looks like something with caps. I'll double check the cap values if I have messed that up.

hedefalk commented 6 years ago

But hey wait, I can't have a CAP there and use the DAC for control voltage can I? :) The DAC output i AC coupled?

Have you used this for any kind of CV generation?

hedefalk commented 6 years ago

Shorting that cap makes it behave as I would have expected.

Ok, got it! It seems to me that changes has been made in this version that makes it unsuitable as a 1V/Oct CV tool, like quantizer, glissando, adsr etc. It has been optimized to be a audio generating tool on the DAC output:

Maybe you should add that to README.md. I actually intended this mostly to be using for those kinds of things. I guess I can mod it with a trimpot and short that cap, but a heads up could be useful for the next one in line :)

hedefalk commented 6 years ago

Hm, I realized I need to offset it too if I want something like 0-5V with full resolution from the DAC… Need TWO trimmers I guess… For the version I have I could set the gain by desoldering R56 and then putting a smaller one in series with a trimmer… But need offset too… Wonder how to fit stuff.

Do you happen to have the original schematics? I can't seem to find them anywhere on the web…

hedefalk commented 6 years ago

Oh, it's actually inverting the dac output too…

So I can't simply short the cap, then I have a square between -12V and 0V. Ugh.

We'll I could probably pre-invert in software for my intended use cases. Then I could skip the offset…

Hopefully I've just misunderstood something because the mods I need seem to add up to be quite complicated :)

hadesbox commented 6 years ago

I'm at the office now but when I get home I can tell you how to connect what to achieve the DC coupled

hedefalk commented 6 years ago

Thx for the schematic! 👍

so what cap are you refering to

C4

Shorting it however makes the signal inverted since we just have on non-inverting buffer followed by an inverting one.

NP, I'll figure something out and report back.

Then I could skip the offset… I was naive there I think.

hadesbox commented 6 years ago

Here are both schematics ordered with opamp input output in the same way.

captura de pantalla de 2018-01-24 18-29-25

hedefalk commented 6 years ago

Yeah, the original uses two inverting ones. Two minuses equals plus :)

hadesbox commented 6 years ago

I found a fix but its suboptimal... it outputs DC with 650mv peak, but its suboptimal...

  1. remove C4, C29, C21 and R55.
  2. Connect a jumper wire between postive pin of C4 and and output (i.e. pads R55)

whatsapp image 2018-01-24 at 21 20 54

This version we did was thinked for audio.... the problem is that original ardcore onlyoutputs DC, and out only outputs AC... and you need both :). But you are totally right we didn't explain this anywhere and for aplications like quantizers wont work on AC.

So what I'm thinking is doing another version with simultaneous AC and DC outputs.. its pretty easy to implement...

hadesbox commented 6 years ago

Im really sorry for this confusion/problem... we got it completely wrong with the AC/DC

hedefalk commented 6 years ago

NP :) I'm in it for the learning! And super thankful for all the help! I'll try to digest that fix…

I was thinking in similar lines, bypassing the second opamp, should be enough buffering with one.

Should should be some way to wire it for a 0-5 V output too. I'm thinking just making a simple unity gain buffer of the first one straight from DAC output (which is 0-5V, right?)

hedefalk commented 6 years ago

Wait, that sounds like the same fix you have. I mean, if we just jump from the output of the first opamp to the jack, it looks to me it should output 0-5V if DAC does, looks just like a unity gain buffer?

So just removing R55, R56, C4 and pulling a wire from 7 to the jack?

hedefalk commented 6 years ago

I can't see how that could give you 650mv peak… Something I'm missing here. Do you output the full range to the DAC?

// Output something slow enough that a multimeter can pick it up.
// Shifts the output between 0 V and <VREF> (5 volts for many, but not
// necessarily!).
// For MCP4911, use 1023 instead of 255.
// For MCP4921, use 4095 instead of 255.
void loop() {
  dac.output(0);
  delay(2000);
  dac.output(4095);
  delay(2000);
}
hadesbox commented 6 years ago

first opamp is buffer, after CAP it becomes AC and its inverted by the second op amp..

I'll test your code because I'm testing with oficial Ardcore "Simple VCO" sketch.

hadesbox commented 6 years ago

I'm testing with this code

#include <SPI.h>
#include <DAC_MCP49xx.h>
DAC_MCP49xx dac(DAC_MCP49xx::MCP4921, 10);

void setup()
{

}

void loop() {
  dac.output(0);
  delay(20);
  dac.output(4095);
  delay(20);
}

and another fixe that Manu (from befaco) recommend me and now I have 11v peak... it involves cutting 2 traces and 3 wires :S

hadesbox commented 6 years ago

for you is working now by just bypassing the second opamp and the coupling cap? what you got now?

hedefalk commented 6 years ago

Sorry, I haven't tested anything - my stuff is at the office :) I'm just looking at the schematic.

The official sketches are based on 8 bit dac aren't they so possibly need to up the numbers?

Interesting, can you show that fix?

I'm pretty sure I had 0-5V square on the output from the DAC as well as the first opamp which should be buffer enough. So I'm thinking just adding a 1K output resistor after the first opamp and then straight to output?

Would have been great with a trimpot/jumper solution for the next iteration though so I don't have to label half of them CV and half Audio :)

hadesbox commented 6 years ago

Yes I'll add the trimmer and fix this AC output thing...

hadesbox commented 6 years ago

Basically you leave the first opamp untouched, and remove the electrolytic cap... and then change the second op amp from inverter to this gain amp circuit

captura de pantalla de 2018-01-24 23-00-54

with R1 = 10k and R2 = 100k which uses this formula

captura de pantalla de 2018-01-24 23-01-19

hadesbox commented 6 years ago

to achieve this you need to cut one trace on the top (black arrow)

front_arrows

and another in the bottom (again black arrow)

back_arrows

hadesbox commented 6 years ago

its a very messy fix...

hadesbox commented 6 years ago

So today I tried what you said, and just bypass the second opamp, and connect the output of the buffer to the out-minijack. And I get 5v range DC.

This is way more simple than the previous fix I told you. So removing C21, R50, R55, R56 and adding a jumper is enough.

img_20180125_085643

img_20180125_085649

hedefalk commented 6 years ago

Great stuff! Maybe better to use a 1K resistor than a jumper though for safety?

Thanks for being so resourceful!

hedefalk commented 6 years ago

I take that 1K back, just reading about input/output impedance - for CV I guess that's a pretty bad idea…

hedefalk commented 6 years ago

@hadesbox Just wanted to check - did you have a suggested schematic fix to allow both audio and cv from the dac?

I'm about to send of an order of a pcb panel and have room to stuck this in. Kicad nightlies also just now became pretty solid on Eagle import so I can actually do work on this myself which I couldn't before because I really don't know Eagle at all. But now it's just a few clicks to import to KiCad and then I can mod it myself :)

I take that 1K back, just reading about input/output impedance - for CV I guess that's a pretty bad idea…

I saw some are using something like 50-180 Ohm though as short protection even on CV, that'd be ok… 100k / 100 should be low enough?

So, ideally, I guess we want full DAC resolution on: 1) something like -10 to +10V for audio. Here, tuning doesn't matter. 2) 0-5 V for CV with tuning. I guess we one need two trimmers for offset + linear factor right?

And we could probably do with 3 pins and ha jumper for choosing between 1 and 2?

If you haven't had any time to look into this, I probably could do it later, but then it'd only be in KiCad :)

hadesbox commented 6 years ago

hi @hedefalk

regarding the DAC resolution I was thinkin as you propose in a jumper to have 0-5v and a bipolar 10v... I havent the time to breadboard this and test it but yes I do intend to do it!

If you want to breadboard it and take a picture of the schematic you draw I can put the eagle files really fast like in 1 or 2 hours.

This weekend I dont have much time to do breadboarding as I have a gig to prepare, but we can probably have the files finished for next week... I dont mine if you propose anything in the schematic we can try it :)

hedefalk commented 6 years ago

@hadesbox Cool, thanks! I think I might be a bit short on time coming week too. But I'll try to squeeze it in!

hadesbox commented 6 years ago

so we will need to have 2 opamps at output I guess

  1. one like in the current design but with a gain x2 to have bipolar 10v
  2. another to buffer the output to 5v with a precission trimmer to adjust 0v.

and a pin to switch from behind. Ill also try to do something on this weekend but I'm a bit tight on time too

hedefalk commented 6 years ago

another to buffer the output to 5v with a precission trimmer to adjust 0v.

I'm really super noob on this, but don't we need a trimmer to adjust the amplification to be exact? I was thinking two timmers at first - one for offset and another for amplification factor, but just realize offset is free in this case, I mean 0V is GND?

And the both dac and amplification should be linear så only need to adjust amp so that our max 5th octave is 5V.

Here's an example from gmsn's quantizer:

image

So they only have one trimmer for the amplification. The left pot is for charging that cap for glide.

hedefalk commented 6 years ago

Just realized I don't get that schematic entirely.

They have 5V as reference voltage on the DAC. Does that mean 0-5V range there? Or could be 0-10V if 2x gain on the DAC, that's a software setting, isn't it?

But let's say 0-5V. Then we have a unity gain buffer and then a non-inverting one with gain:

1+(x/10k) where x = 10-20k. That gives me 2-3 gain right? So 10-15V? That's a lot… 8 octaves would definitely be enough?

hedefalk commented 6 years ago

Just realized I don't get that schematic entirely.

Well, the GMSN quantizer do have 0-10V range apparently. But I'm still confused about 10-15V theoretical then. 9-11V or something would just make more sense? Asked about it: https://forum.gmsn.co.uk/t/trying-to-understand-the-dac-output-stage/413

One more thing though - just realized that 2x gain thing is really my friend. I'm slowly understanding :)

Don't know if it might mess up backwards comp with ardcore sketches, but personally I'm not concerned about that.

But anyways - I would actually be really happy with being able to switch between say 0-5V and 0-10V range CV strictly in software. So I'm probably gonna branch off a bit here and stick a 2.5V reference chip in there. If I understand correctly, I could use 5V power to the DAC and a 2.5V reference. That would give me 12 bit resolution on either 0-2.5V or 0-5V. Sticking a 2x gain amp after that I'd have 0-5V or 0-10V. Thing is that it would even be selectable at runtime. I would simultaneously set the gain factor to 1 or 2 and switch the note lookup table. I could just have one of the analog pots select range basically.

Should probably be just a little shy of 2.5V so it doesn't hit the roof in some way, would just adjust this with amp factor. Hm, the MCP4822 that I was going to use for another project has an internal Vref of 2.048V. Do you know why the 4921/4922 is chosen before that one? Seems practical to me with an internal Vref…

Another approach might be to have two trimmers in series for the gain factor. One course and one fine. Then I could set whatever range I want in my software and just adjust the gain to tune? Is that really such a bad idea?

Is it scary to have trimmers having too much affect I mean? Like vibrations and stuff having an influence?

I was going to go for 0-8V for a midi2cv I'm building, but for something like an Ardcore the use case isn't really known. Sometimes it might be for CV range 0-5V and sometimes for -10+10. As we learnt here :)

hedefalk commented 6 years ago

Whoops, probably not too good to over-rely on trimmers:

I haven't use trimpots in 15 years -- because they are unreliable. As mechanical devices, they are subject to instability due to wear and vibration. The wiper contact is susceptible to the effects of humidity and atmospheric contamination. They generally have awful temperature coefficients. The "precision" multi-turn versions are the worst: the mechanical linkage between the adjustment screw and the wiper is susceptible to backlash errors -- both during adjustment and afterwards due to vibration.

These days I do everything digitally. Transducer -> A/D -> signal processing. Any calibration or scaling is done with math -- which is completely immune to the above stated effects.

If I require precision analog, I'll use the best voltage reference and low Vos opamps I can afford and 0.1% precision fixed resistors (which are relatively cheap these days).

https://forum.allaboutcircuits.com/threads/trimpot-reliability.113915/

hadesbox commented 6 years ago

I like pretty much evertying you posted, I'll GSMN schematic... the 5V reference is for setting a "stable" voltage so it can be used by the internal resistor ladder to produce voltages consisntely equal when the DAC receives same values.

That thing about trimmers is just plain silly for our use case, most of analog modules have trimmers and they work fine... so I'll that that schematic and read about how to make thos 0-10v!

I would go with 0-5v for fine quantization and 10v bipolar for audio rates and similar.

So we do need to keep the coupling cap I, but that is selectable by this jumper.

Ill read more on the links and then will draw a schematic when we both are happy I lay the PCB we should both send this to factory, or we can share the expenses if you want 5 boards for me for testing and 5 for you :).

hedefalk commented 6 years ago

I would go with 0-5v for fine quantization.

I know I've been talking a lot about 5V, but I think actually I would need to be able to set up to 0-8V for 1V/oct in some cases so would be good to have that. I think the typical use cases are:

the 5V reference is for setting a "stable" voltage so it can be used by the internal resistor ladder to produce voltages consisntely equal when the DAC receives same values.

Sure! But if I understand the feature, the 2x gain feature in this DAC family isn't usable if one uses 5V as ref though since the max rail is 5.7V or something I think. If one instead have just short of half the supply voltage (2V-somthing) one can control gain in software which is pretty useful for us, isn't it? This is how I understand it at least.

I actually have a panel going out soon with room for this. I'm a little cheap trying to use those 10*10 offers without panelization features and gonna use this monster paper cutter to cut them before soldering. It cuts through 1.6mm glass fiber like butter: image

Still need to see if my panelization idea works but if it turns out nice I'd be happy to send you 5 for free :) Probably wont be as nice as factory cut, but I think good enough for me…

hadesbox commented 6 years ago

Hey @hedefalk

I've been comparing the circuit of the MI Peaks with the ardcore, and the output its pretty much the same, except that @pichenettes uses a reference voltage of 10V and without the coupling cap.

I would say that is a nice way to do it, what you think??

MI Peaks

captura de pantalla 2018-03-25 a las 14 52 09

Ardcore

captura de pantalla 2018-03-25 a las 14 52 17
hadesbox commented 6 years ago

remember that the Peaks output both CV and Audio :)... I have not measure my peaks, but I guess is 0-10v range the audio.

hedefalk commented 6 years ago

"Output level: 0 to +8V for envelopes, 10Vpp for LFOs and drum signals."

The schematic says it has +-8V on the output…

I see no trimpots so I actually don't understand how that output stage can support different ranges… Maybe it's something in the DAC, it uses another 16 bit DAC, right? Maybe in that case, one don't care much if one loses one bit of resolution, but in our 12 bit case it's a bit more on the edge I think :)

I'm still though playing with the idea of being able to use that 2x software feature of the 4921 DAC just to keep resolution for different use cases. But then one needs to add another Vref around 2+V or so…

pichenettes commented 6 years ago

The circuit is designed for -8V to +8V, with voltages 0 to +8V used for unipolar output and -5V to +5V used for bipolar output (so each time, about 50% of the available resolution is not used).

hedefalk commented 6 years ago

@pichenettes Thanks for the clarification!

In our case we have a 12 bit DAC compared to the 16 bit of the Peaks. If we want 0-8V for 1V/oct and something like +-8V for audio with the same output stage we'd have to lose half the resolution too. In our case that's going from 4096 to 2048 steps. I think that might be pushing it, but I don't really have the experience to tell…

Simple math though, over 8 octaves that's 2^11/8/12 = 21 steps per semitone which would mean 3-4 cents out of tune I guess? Maybe that's alright? But still 2 cents would be better than 4, that's my 2 cents :)

@hadesbox ^

hadesbox commented 6 years ago

Then.. I'm all in to upgrade the DAC too, and the good news there is a library for the DAC8552 so ppl will be able to upgrade their sketches and use this DAC which is far better the current one. This is a community based, diy project and its to experiment not intended as a product so we can do whatever we want.

https://github.com/RobTillaart/Arduino/tree/master/libraries/DAC8552

@hedefalk the way the bipolar/unipolar is done is all via code, so we will have to publish functions to overwrite the dacOutput which will add some offset and scale the output value, and this should be done when someone is porting the sketch depending if he wants to upload a CV sketch or a audio sketch!

A second output would be nice too, we could output phased sines and stuff... we can call it half-quadrature :D.... or we can do "stereo" (panning) outputs.. that would be nice.

I think overall is a good idea... 8552 seems to work on 5v! :) So we could use the 5v as reference too or make a smaller voltage reference.