Show Posts
Pages: [1] 2 3 ... 25
1  Using Arduino / Audio / Re: MCP4922 problem on: Today at 04:47:51 pm
OK, so it looks like this:

MCP4922   PIN        CONNECTED
PIN       FUNCTION   TO
-------   --------   ---
 1        VDD        5V             
 2        NC         ---             
 3        CS         DUE PIN 10 (CS)         
 4        SCK        DUE ICSP-3 (SCK)
 5        SDI        DUE ICSP-4 (MOSI)
 6        NC         ---             
 7        NC         ---             
 8        LDAC       GND
 9        SHDN       5V
10        VOUTB      -> DAC B OUT
11        VREFB      2.5V - RESISTIVE DIVIDER
12        VSS        GND
13        VREFA      2.5V - RESISTIVE DIVIDER
14        VOUTA      -> DAC A OUT

Changes I've made to your list:
  • Added the Due pin number for CS that corresponds to your code, pin 10.
  • Added the Due ICSP designations for those pins.
  • Added a connection between MCP4922 9, SHDN, the shutdown pin, and 5V.  If that pin is left open and read by the MCP4922 as a low input, the DAC shuts down.  If you don't use that pin, it should be tied high.
It's worth noting that you can use the same resistive divider to supply VREFA and VREFB.  You may well have done it that way; I mention it for completeness.

Here's something else to note:  The MCP4922's datasheet shows VIH, the minimum voltage that the circuit promises to read as high, as 0.7VDD.  That's 3.5V.  The Due's logic outputs can only be as high as 3.3V, and that's less than VIH.  There's a possibility that the MCP4922 will not be able to see a high input from the Due, and will thus give unexpected results.  It's not particularly likely, as 3.3V is pretty close to VIH, but it's not impossible for the MCP4922 to read lows where it should see highs under some conditions, and for some unlucky MCP5922's to never read a high in this circuit.  If you start getting unexpected results, that's a possible reason.  A remedy would be to apply some level-shifting between the Due and the MCP4922

With LDAC grounded, the input registers transfer immediately to the DAC output when they're received.  It's easy, but the DAC is less functional in that mode.  The purpose of LDAC is to allow synchronization of the A and B outputs, and other DAC's as well, if the device has others.  You can load register A, load register B, then pulse LDAC, and both outputs will update simultaneously.  You can also use LDAC for hardware-controlled timing, by loading the A and B registers, and letting a hardware timer output control the LDAC input.  The outputs update precisely on the clock, and you can load the next values into the registers in response to the timer, by polling or interrupt. 

Note that the function of the LDAC pin is controlled by bit 14 of the input message:  if that's a 1, LDAC is active; if it's a 0, LDAC has no effect, and the DAC register transfers to the output immediately.  Your code sets bit 14, so LDAC is active.
2  Using Arduino / Audio / Re: Help with audio quality! on: August 31, 2014, 06:06:59 pm
Is the DCLK pin the DAC output ? I didn't notice that.
I don't think so.  It looks like the datasheet describes two different modules - WTV020-SD-16P and WTV020-SD-20S - that use the same IC, WTV020SD-20S.  The '-16P module has an output labeled, "AUDIO-L," which appears to be a DAC-ish output.  The '-20S module doesn't have that output.  Comparing the schematic linked to the Sparkfun product page with the schematics shown in the datasheet for both modules, the Sparkfun unit doesn't look like either one, but the functionality provided by the outputs at the card edge seems to resemble the '-16P.  The AUDIO-L output comes from pin 10 in the IC, and, based on the Sparkfun schematic, that's connected to a pin called, "PWM," on JP-2 Pin 1.  The datasheet shows this pin and GND as the output to an external amplifier, in the MP3/DAC output mode. 

I don't know what mode the OP is using.  I don't find clarity in the datasheet about how to select the various modes, if one actually selects them.

The blurb lists this as a feature:
Quote
Dedicated 16-bit DAC/PWM audio output to use with an external amplifier.
The datasheet, on page 20, shows this heading
Quote
8.4.MP3 MODE APPLICATION CIRCUIT(DAC OUTPUT)
, with this note shown in the text
Quote
WTV020-SD-16P DAC output,” Audio L” and module GND to amplifier. WTV020-SD-20S DAC output, “SPK+” and module GND to amplifier.

How is the external amp connected to the module when it's delivering lousy sound?  The datasheet suggests driving an external amplifier from SPK+ and GND, and calls it a "DAC output mode" for the WTV020-SD-20S, whcih doesn't bring pin 10 of the IC to a connector.  I don't know how the OP's amp is connected.  If SPK+ and SPK- are used as input to the amp, I'd expect trouble.  There'll be less trouble with SPK+ and GND, but, until it can be verified, I'd recommend keeping the volume on the amp turned down low, as I'd expect the PWM frequency to be well-represented in the output signal.

A search of the forum finds others having trouble getting the -16P device to work as expected.  Solutions posed include making sure to format the microSD to FAT16.  There's talk of fiddling with the SD card - apparently, not all of them are compatible - and of using a different supply voltage, but those suggestions appear to refer to module '-16P, which can use a standard non-mocro SD card.  The OP seems to be getting his micriSD to work already.
3  Using Arduino / Audio / Re: Help with audio quality! on: August 31, 2014, 09:46:46 am
For this Sparkfun Audio-Sound Breakout - https://www.sparkfun.com/products/11125 - the blurb and datasheet both reference a DAC-based output for connection to an external amplifier.  If you're using this device with the PWM output connected to the amplifier, try connecting the DAC output instead.  If you're already using the DAC output for the amplifier, then the audio quality issues you mention may be related to the device's 4-bit format.  If you're not using this device at all, but some other one, just forget I said anything.

Maybe you could mention exactly what device you're using, and either post a schematic or give us a list of your connections?
4  Using Arduino / Audio / Re: MCP4922 problem on: August 28, 2014, 09:41:06 am
... works like a charm!
Delighted. 

You may want to continue this discussion for another post or two, though, as the document you reference is more than a little ambiguous, and there may yet be issues with the design that you haven't bumped into yet.  The ones I see have to do with the voltage that powers the MCP4922, and the reference voltages.

Here's the briefest description of what I'm thinking:
  • The posted code shows bit 13 of the message seent to teh MCP4922 as a '1', which selects a gain of 2X.  If VREF is the same as VDD, it looks like the DAC will hit its power supply rail at half-scale, and won't be able to register higher voltages in response to bigger input codes.  In essence, it'll operate as an 11-bit DAC.  If you send code 3333, as shown in your sketch, and then send 4095, do you get the expected results?
  • If the MCP4922 is powered at 5V, as shown in the schematic, then the Due's output high voltage of 3.3V won't reach the level of VIH = 0.7*VDD = 3.5V.  VIH is the lowest voltage that the manufacturer promises will be read as a logic high.  The Due doesn't miss the mark by much, though, and the circuit may work properly nearly every time.  But, if it does in fact glitch, it will be devilishly hard to troubleshoot.

You may have spotted these issues and designed around them; I can't tell from the posts.  As a favor to the next guys who try to interpret that document, could you post a schematic of what you built, or at least a list of your connections? 
5  Using Arduino / Audio / Re: MCP4922 problem on: August 27, 2014, 08:50:40 am
The MCP4922 datasheet says the output channel is selected by the most significant bit of the input message.  Here's the datasheet, with the message structure described on page 24:  http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf.

To switch to channel B, try changing this:
Code:
msg1=msg1 | 0b01010000;
to this:
Code:
msg1=msg1 | 0b11010000;
6  Using Arduino / Audio / Re: Frequency Detection on: August 25, 2014, 08:53:47 am
I am interested in creating various visual effects based on analog audio signals. I started by trying to detect pitches in the chromatic scale for the frequency range of a 22-fret guitar in standard tuning:
A lot of people have posted on this forum intending to build a guitar tuner with an Arduino Uno, and using the FFT for automatic pitch detection. I haven't seen anyone report success.  If you're going to do pitch detection this way, you'll have to be ingenious.

Quote
82.4 (E2) - 1174.7 Hz (D6) ...
... sampling rate ... ~2350 ...
Accurately identifying 1174 Hz with a sample rate of 2350 Hz will be challenging.  The Nyquist criterion says that the sample rate has to exceed twice the frequency of the highest frequency signal component with significant content, not the highest frequency that you're interested in.  2350 is pretty close to twice 1174, so doing this detection will take a nearly perfect brick-wall filter.  You'll need a higher sample rate, and an aggressive filter.  Forum member pito has identified an eighth-order single-chip elliptical filter family that uses switched capacitors, whose cutoff frequency depends on either an external capacitor or an external clock signal.  The datasheets can be reached from here: http://www.maximintegrated.com/en/datasheet/index.mvp/id/1899.

Quote
I keep running into resolution limitations for low frequencies due to frequency bin size.
The resolution of the FFT can be improved with parabolic interpolation.  Here's a description from a guy at Stanford:  https://ccrma.stanford.edu/~jos/parshl/Peak_Detection_Steps_3.html.  The idea is that an input signal whose frequency doesn't exactly match a specific FFT output frequency will show up spread over several adjacent FFT output values.  It's estimated by identifying a local peak in the bins, and fitting a parabola to the the peak and its two adjacent values, calculating the axis, and calling that the estimated frequency.  I've never tried it with the FFT, but it has worked for me with YIN.  Note, though, that the input values to the interpolation are completely different kinds of objects than the output of the FFT.  You may get different results.

Quote
The first referenced project doesn't use YIN.  It estimates pitch by examining the time between zero-crossings with the highest slope.  That's going to have a high error rate, because guitar harmonics aren't precisely integer multiples of the fundamental - their phase rotates with regard to the phase of the fundamental, so they contribute their slope to the sum at varying points in the cycle.  As for what the error rate might be, I can't say.  It might be entirely acceptable.

Quote
I would also like to detect the fundamental frequency of strummed chords, and this method seems vulnerable to complex signals.
YIN isn't applicable to polyphonic signals.  It looks for a near match between one segment of the input and another segment some time later, and uses the time interval between those two segments as the inverse of the frequency.  If a signal has two components of roughly equal amplitude at, say, 1 Hz and 1.5 HZ, YIN will estimate the frequency at the least common multiple, 3 Hz.

If you mean that you want to identify the lowest component of the signal, you're in for a bit of a challenge: chord components can easily be within a minor third of one another, overlapping in the FFT output enough to confound parabolic interpolation.  If you want to do that reliably, I think you'll have to look at multiple cycles at fine resolution.  

You don't say that you hope to identify individual strings in a polyphonic signal.  If you do, that's a lot of work.  Here's an Apple patent on that process:  https://www.google.com/patents/US8592670?dq=8592670&hl=en&sa=X&ei=Y3_5U_buBZW2yATqj4Jo&ved=0CB0Q6AEwAA.  It's feasible with an iPhone, running at more than a gigahertz, with gigabytes of storage; less feasible on an Arduino.  
  
Quote
I'm beginning to wonder whether the Arduino is up to the task ...
Think a bit about how much latency you can tolerate.  The Arduino can be persuaded to do interesting things if they don't take too much memory, but they sometimes take a long time.  I've gotten reliable frequency identification for guitar-like signals in the 80-880 Hz range using YIN, but it takes about 150 milliseeconds to identify a string on the low end of the range.  That's way too much latency if I'm trying to control a MIDI device, as the output would be always a sixteenth note behind the rest of the band at 100 beats per minute, but it's OK for other things, like identifying the frequency for a tuning application.

Quote
I'm looking at my $20 chromatic tuner and wondering how it can do this for so cheap
One thing to consider is that it doesn't do it all that fast.  150 milliseconds is practically imperceptible in that application.  Another is that the tuner may use application-specific ICs to do its work.  Here's a link to the only one I can find, quoted at about 6.5 USD in 10K lots:  http://www.tuneric.com/literature.html.

Edit: grammar and spelling
7  Using Arduino / General Electronics / Re: Is it possible 7490 is skipping number on 7 digit display? on: August 17, 2014, 11:43:58 pm
Post your code, maybe?  And maybe a schematic? 
8  Using Arduino / Audio / Re: FFT with DUE and TFT on: August 13, 2014, 11:29:37 pm
The example runs, but only at a buffer size of 2048. If I try to change it in the libraries, the DUE does nothing.
If you could tell us, specifically, what you did to change the array size, it might lead to a solution.
9  Using Arduino / Programming Questions / Re: MATHS help reqired for HSI project. on: August 13, 2014, 10:44:24 pm
After a few tries, I still can't grasp what you're trying to do.  It looks like this:
  • read an accelerometer,
  • make some calculations, and
  • turn on some neopixels based on the results.
Beyond that, I'm befuddled.

Here's something, though it's almost certainly not the primary problem.  In the sketch, I find this in loop():
Code:
  x, y, z = attitude();
and this in attribute():
Code:
  return (x,y,z);
It looks like that code is intended to return three values from attribute().  That won't work - C++ allows a straightforwared return of only a single value from a function.  I'm fairly certain that code doesn't do what's intended.  The function appears to work, because the values x, y and z are global values, and they're directly modified in attribute().  But, they're not returned to loop(); in fact, only z is returned.  To see it break, use local variables rather than global inside attribute(), return them, and watch what happens to the values of the first two variables.

I can't be certain, but I don't see any evidence that you've tested the various tasks that you're trying to program separately.  Things like:
  • reading the accelerometer, printing the results to the terminal, and confirming that they match the expected results based on the accelerometer's orientation
  • running calculations on known test data rather than the accelerometer's output, printing those, and observing that the results are what's expected, and
  • running the display routines on known test data, and observing that the expected lights come on while the others stay off.
As things stand, there could be problems - maybe more than one - with any of those tasks.  If you test in smaller pieces, there will be fewer hurdles to get past in order to help.  Right now, we have to decipher the post - something I haven't been able to do - analyze the program, find the libraries, analyze them, and get up to speed on this particular accelerometer.  The list of people who will do that is a short list; I'm not on it. 

Can you post a minimal sketch that compiles, and illustrates a specific problem, and then describe specifically what you expected, and what you got?
10  Using Arduino / Audio / Re: FFT with DUE and TFT on: August 07, 2014, 10:00:42 pm
How is the analog signal connected now?  Your question about an op amp or diode suggests that there may be a problem with that connection.  Please be specific.

The Due doesn't want a 5V input - it wants something between 0V and 3.3V.  See the warning on the product page, here:http://arduino.cc/en/Main/ArduinoBoardDue.

Running the FFT with calculated data will eliminate uncertainty about the analog input.  I'd suggest getting it working with known data before trying to integrate it with analog acquisition.  I'd also recommend acquiring and printing raw analog data, to make sure that you're getting the analog inputs you expect, and get that working before trying to integrate it with the FFT.

You can get by without an op amp, but, as far as I know, a diode won't help you.  The canonical method for connecting a bipolar analog signal to an analog input is to use a voltage divider connected between 3.3V and 0V, and capacitively couple the input signal to the midpoint of the divider, and take the analog input from that point.  That method provides no protection for the input, though - it'll be up to you to make sure that the input signal doesn't go out of range.  

You seem to have access to a signal generator.  Those usually have a DC offset that you can set to 1.65V, and it will still be up to you to set the amplitude to avoid a signal excursion outside the safe range.  

Finally, I don't see anything about the frequency of the input signal, and I don't see anything controlling the analogRead() frequency other than the time it takes to get a reading.  If your input frequency is low, and the analogRead() speed is fast, you might be seeing only part of the input cycle, with weird results.
11  Using Arduino / General Electronics / Re: 220VAC to 12DC on: August 03, 2014, 09:03:44 am
... I need something smaller ....
Maybe you'd like to elaborate on what "smaller" means, and tell us what other requirements you have?  This process goes faster if we don't have to guess.
12  Using Arduino / General Electronics / Re: Reduced phone ringing voltage on: July 13, 2014, 12:47:59 pm
I think that you want a circuit that signals the Arduino when the phone rings.

A schematic of a gizmo called a "ring detector" from Velleman is attached.  Here's a link to the product page, where you'll find a link to the user manual, the source of this schematic:  https://www.vellemanusa.com/support/downloads/?code=K8086.  The manual is long on assembly instruction, and short on theory.  Note that Velleman's blurb for this device doesn't mention any regulatory approvals, so I presume it has none.  Proceed at your own risk.

The device blinks an onboard LED, and optionally operates an onboard relay.  Power for the relay coil comes from an offboard power supply, presumably because it takes more current that can be surreptitiously drawn from the phone line.  That supply doesn't appear to come standard with the device.  I don't think you want a relay output, anyway, so you can do without it, and without the circuitry that drives it.  You can replace everything to the right of the red line with a pullup resistor, an input pin's internal pullup resistor, or, as has been suggested in this thread, a retriggerable one-shot multivibrator.  You can do without the LED, if you don't need a visual indication.

The purpose of 1M resistor R1 escapes me, but it limits current to microamps, so it almost might as well not be there.  A purist might omit it.  As a phone technician, you'll know a lot more about the possible effects of that resistor on the system than I will.  Maybe you can illuminate?

I have previously believed that ringing voltage was supplied by reversing the polarity of TIP and RING. Today, I'm not so sure.  You'll know, though, and you can use that information, along with knowledge of transients that Might appear on phone circuits, to select the right voltage rating for capacitor C1.

Otherwise, the circuit looks OK to me.  Capacitor C1 blocks DC, so there's no current when the line is on-hook.  The back-to-back zener diodes block current when the AC peak voltage is below 20V, so there's also no current when the phone is off-hook.  he full-wave rectifier ensures that it's balanced, and will operate when TIP and RING are reversed.  The only time the circuit conducts is when the phone rings.  The phone system used to ring electromechanical bells, with coils and switches, so I'd expect that it can deal with considerable chaos during ringing, and I wouldn't expect it to be annoyed by anything this circuit could do. 

Alternatively, you could just buy one of these devices.  Amazon has them for about 23 USD, and I've seen a price of about 11 pounds, exclusive of VAT, on a UK site.
13  Using Arduino / Programming Questions / Re: Modify the PWM Output frequency. on: July 11, 2014, 01:26:58 pm
You stopped reading too soon.  It also says,
Quote
Varying the timer top limit: fast PWM
Both fast PWM and phase correct PWM have an additional mode that gives control over the output frequency.
This part of the tutorial specifically addresses changing the PWM frequency.
14  Using Arduino / Audio / Re: Elektret Micophone on: July 06, 2014, 01:45:17 pm
You don't describe your level of experience with the Arduino, or with electronic circuits in general.  I'm going to make a guess about both of those, based on your earlier posts.  Please pardon me if I describe things that seem elementary to you.

For the convenience of others reading this thread, I'm attaching the schematic from the referenced "instructables" posting.

I'd recommend checking the amplifier's DC conditions.  First, I'll repeat two earlier recommendations:
  • Power the circuit from the Arduino's 5V.  The purpose of that is to make sure that the amplifier's output voltage doesn't exceed 5V.  If the amplifier output voltage gets above the level of the Arduino's power supply, it could damage your Arduino.
  • Make sure that the ground of the amplifier circuit is connected to the Arduino's ground.  If the circuit's current doesn't have a way to return to the Arduino's power supply, it won't operate.
Here's how to check the DC output level:
  • Remove the electret from the circuit.  The purpose of that is to make sure that voltage readings won't be affected by sounds in the room, so that we can read the DC voltages in peace.
  • Measure the voltage at the collector of Q1.  That will be the junction between the transistor and the 10K resistor R3.  By my calculations, that should be between about 0.8 volts and 1.3 volts, depending on the actual DC current gain of your particular transistor.
  • If you don't have a voltmeter, then connect the collector of Q1 to analog input A5, and run your program.  Again, by my calculations, you should see analog readings between about 125 and 170, depending on the actual transistor characteristics.
I haven't built the circuit; my calculations could be wrong.  

If you don't get those values, something's likely to be askew.  In that case, I'd recommend disconnecting the amplifier circuit completely, and testing the analog input with the Arduino's onboard 3.3V source.  Connect the 3.3V pin to analog input A5, and run your program.  That should give readings of about 675.  If that test fails, something's certainly askew.

As DVDdoug aptly says, the value 4685 is bigger than any value that the ADC can register.  I don't see any way that your program could show that reading, so I'll presume that it's a typing error.

[Edit: spelling]
15  Using Arduino / Audio / Re: Elektret Micophone on: July 05, 2014, 10:00:08 am
Are you using the output coupling capacitor, called "C2" in the instructables schematic?  That capacitor is intended to block the DC component of the output signal.  The ADC needs to see that DC component, because it can't read voltages below zero.

Here's my suggestion for what to try next:
  • Power the circuit from the Arduino's 5V supply.  Be sure to connect the circuit ground to the Arduino ground.
  • remove C2 and connect the output of the transistor, "Q1," to the analog input.
  • Try it again.
Pages: [1] 2 3 ... 25