Show Posts
Pages: 1 2 3 [4] 5 6 ... 25
46  Using Arduino / Programming Questions / Re: Changing ISR's return address to a function's memory location? on: April 25, 2014, 10:42:28 am
... my read_voltage function relies on lower level interrupt priorities such as the Timer compare register match interrupt and ADC conversion complete interrupt to complete it's work.
Can you tell us more about how that works?
47  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 11:04:53 am
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
That is going to give you a float of the finished integer operation inside the parens.
Indeed.  It casts the expression inside the parentheses as float.  The parentheses, though, don't wrap the whole expression - they wrap only the numerator.  With the numerator cast as float, the division is carried out in floating point.
1/5 would give 0.0 not 0.2.
I get a different result.  Here's test code:
void setup() {
  int readings[] = { 0, 1, 0, 5 };
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
void loop() {}
Here's output:
as expected.
48  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 18, 2014, 07:25:04 am
... dealing with the issue of zero ... help with this?
  • Calcualte the denominator
  • Check to see if it's zero
  • If it is, do something appropriate
  • Otherwise, proceed as usual
"Something appropriate" might be printing a message, like, "Look out! It's gonna blow!"  or maybe shutting something down. or maybe just printing "undefined" instead of printing a number.
49  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 17, 2014, 05:21:37 pm
Here's what I think:
  float slope = (readings[1]-readings[0])/(readings[3]-readings[2]);
This line calculates the value of the slope.  All of the variables on the right hand side are integers, so the compiler does the whole calculation using integer math, yields an integer result, and dutifully assigns that integer to the float variable slope.

To fix this, you can cast either the numerator or the denominator of the fraction as float, like this:
  float slope = (float)(readings[1]-readings[0])/(readings[3]-readings[2]);
A purist might cast both as float.

Here's what else I think:
  • You should address the issue of a denominator of zero, as noted above.
  • You should use code tags to post your code.  Any number of confusing things can happen when you don't.
  • You should read "How to use this forum ..., " posted as the first entry in all the many forums.

Finally, please note that you've declared slope twice:  once as a global int, and once as a float local to loop().  I don't see that you ever use the global variable.  You probably don't want it at all.
50  Using Arduino / Audio / Re: arduino FHT on: April 06, 2014, 08:17:17 pm
Bit 0 = 1:  <wrong stuff snipped>
That is not correct. MUX3...0, the lower 4 bits of ADMUX, select ADC channel 0-8, ...
Indeed, that is not correct.  Edited the original post, using strikeout to leave a trail.

51  Using Arduino / Audio / Re: arduino FHT on: April 06, 2014, 06:40:58 pm
when i assign ADMUX = 0b010000001; this means that i use ADC1  ...
Checking it against the description of register ADMUX in the datasheet:
  • Bit 7 = 1, Bit 6 = 0:  This combination selects reference mode 2, which is described in the datasheet as, "reserved."  I don't know how the reference will behave, but it's likely that it won't do what you expect.
  • [Edit: Delete this, because it's incorrect] Bit 0 = 1:  This selects ADC channel 0, not ADC channel 1.
So, it's not surprising that it doesn't tell you about ADC channel 1.  Maybe that's what you used, or maybe you copied it wrong.  

If you want help, you should probably post some code.  You should tell us what you expected, and tell us what happened instead.  Your code should be a small sketch that illustrates the problem, rather than long stretches of code that are largely irrelevant to your question.
52  Using Arduino / Programming Questions / Re: SPI MISO-MOSI arduino on: April 02, 2014, 07:10:51 am
I think that this bit of code doesn't do what you expect:
byte data2 = shiftIn (SOMI, SCLK, LSBFIRST);
data2 = (data >>8)& (0XF);
data2 is a byte; it's only 8 bits long.  When you right-shift it by 8 bits, there's nothing left.  After this operation, data2 will always be 0.  Is that what you wanted?
53  Using Arduino / Audio / Re: Best anti-aliasing filter to use for sampling audio on arduino? on: April 01, 2014, 07:39:18 am
TI filter app ... seems to select filter parameters, but doesn't actually tell you anything about how to built the filter in hardware?
I think you're talking about WEBENCH.  When you see the list of filter types at the bottom of the page, push a green "Select" button on the right side of the table.  That'll take you to a schematic.  If you haven't logged in to TI, it'll make you do that first.
54  Using Arduino / Project Guidance / Re: Why inaccurate tempo? on: March 31, 2014, 10:53:30 pm
... ceramic resonator ...  Is this true?
Indeed.  The schematic, available here - - shows a device labeled "CSTCE16M0V53-R0 16MHZ" between the ATMega's XTAL pins.  The manufacturer shows that gizmo to be a "timing device," with initial tolerance of 0.5%, temperature stability of 0.3%, and frequency aging of 0.2%, here:

Quote from: Shakespeare, Hamlet, ~1600
The time is out of joint. O cursed spite, that ever I was born to set it right!

The OP reports that the Arduino's LED is "inverted" after 1 minute 40 seconds.  Presuming that means that the two devices are off by 1/2 cycle, at 60 beats per minute, here's how it works out:
  • 60 beats per minute = 1 Hz;
  • accumulated error at 1 minute 40 seconds = 1/2 cycle = 0.5 seconds;
  • relative error = 0.5 seconds / 100 seconds = 0.005 = 0.5%,
and that's the reported initial tolerance for the resonator.  All's well that ends well.

The Arduino isn't good at keeping time.  Folklore says that using the crystal that drives the ATMega16U2 for the 328, or using two crystals, would prevent the device from passing the US FCC's electromagnetic emissions test, so the designers opted for accuracy in communication timing, and something less in the processor clock.  If you want something precise, you can get a clone that uses a crystal, like a Diavolino -

Quote from: Shakespeare, All's Well That Ends Well, ~1604
Our remedies oft in ourselves do lie.
Or, you can build your own.
55  Using Arduino / Project Guidance / Re: Music tuner that monitors four sources at once on: March 26, 2014, 08:20:32 am
Always nice to come for help and get insulted.
A thin-skinned bagpiper?  You mean you didn't see that coming when you posted?

Initially, I thought you wanted to tune all the pipes by examining a single signal, separating the component tones, and reporting their frequencies - like polyphonic guitar tuners that have come out lately.  That's a demanding task, likely beyond even an ingenious Arduino implementation.  It's especially challenging for bagpipes, with three of the four sounders playing the same note.  After your fourth post, it looks like you're contemplating something with four separate sensors, and tuning the signals one at a time.  That's certainly feasible for the drones, if you can keep the sensors from hearing each other's pipes.  Tuning the chanter while playing, though, is likely to be challenging.

The "instructables" link referenced earlier is applicable to single-tone tuning.  So is this one, which uses autocorrelation to estimate the frequency:

You've gotten several useful references for this project, but I don't see any evidence that you've looked at them.  That makes me think that maybe you intend for someone else to implement this for you.  If that's so, you might try the "Gigs and Collaborations" section, here:  If you want to continue pursuing it in this section, you'd do well to provide a more detailed description of your vision.
56  Using Arduino / Project Guidance / Re: Music tuner that monitors four sources at once on: March 23, 2014, 12:24:11 am
This is the first I've heard that anyone ever tries to tune bagpipes.  None of the ones I've heard suggest that intonation is high on anyone's priority list.

Single-tone tuners are hard - just do a search on this forum, and see how many people aspire to making one, and how few report success.  They're much easier if they don't have to identify the input frequency automatically.  It may be that you don't need that feature.

You can see a solution for this project in Patent #8,309,834, an Apple patent for a polyphonic tuner.  A quick reading says that the technique is: use some kind of frequency discrimination function - almost certainly an FFT - to identify a frequency close to the lowest fundamental you're looking for, and then identify a couple of harmonics of that frequency to be sure that the fundamental is really present; repeat that for the other frequencies of interest using the same data; and finally, report the results as either sharp or flat.  It's written in patent-ese, with the intent of covering as many implementations of the concept as possible, without really giving much away.  A Google search for the patent will yield descriptions that are more understandable, but generally equally uninformative.

This scheme calls for some pretty precise frequency estimates.  For a six-string guitar, some of the interesting frequencies are close together, requiring narrow frequency bins to differentiate between them.  It might work if you're Apple, doing this on a smartphone or audio workstation, where memory sizes and processor speeds start with, "giga-," and high sample rates spanning several cycles aren't particularly challenging.  The Arduino Uno may not be up to it.

The "instructables" link isn't really applicable to this project.  It relies on identifying the input signal's zero-crossing with the maximum slope, and measuring the time between those events.  That's iffy for single-tone signals; it's no help for polyphonic signals.  You might be happier with a single-tone tuner.  How often do you have to tune up, and how fast?
57  Using Arduino / Programming Questions / Re: analogRead() Problem on: March 20, 2014, 09:37:02 pm
A0 is a value that the code uses to identify the pin.  To see this in action, try this:
void setup() {

void loop() {
I predict that it will print, "54." 

Your program assigns the value represented by A0 to the variable Potentiometer.  It never assigns anything else to it, so the value of Potentiometer never changes.

For the Due, the value of A0 is established in the file:
If you look into that file, you'll find this line:
static const uint8_t A0  = 54;
When you print A0, you get, "54."  Earlier replies in this thread describe how to store and print the analog value.
58  Community / Bar Sport / Re: Normal English phrase embarrassing in the US on: March 15, 2014, 10:43:20 pm
All y'all are having a lot of fun at Houston's expense.  Since I live in Houston, I feel compelled to defend it.  However, most of what you're saying is true-ish, if not true outright.

... try and avoid saying "I have to shoot off"!
With a reasonable audience, you can get away with it - indeed, you can get away with almost anything - if you say it with a British accent.  Teenagers and young men who don't date much will probably ridicule you for it, no matter what your accent.  Unless you're from Yorkshire, in which case no one will understand you at all.

Never use "pop" or "soda".
I live in Houston now, and I can't remember the last time I heard generic soft drinks called "cokes."  It's a ferocious melting pot here, and things change fast.  I say "soda," and always get away with it.  Out in the hinterland, though, everything seems to be a coke.

If he prefers iced tea sans sugar he must specifically request "unsweetened tea".
Yes, he must.  The default state of iced tea is sweetened.  In the broad swath of the south, an especially sweetened tea has come into use, made by saturating it with sugar while it's hot; that's called, "sweet tea," and you generally have to ask for it specifically.  It the server asks you, "Sweet tea?" and you decline, you'll probably get sweetened tea.  

"Fixin-to" = "planning" or "going to".
"Fixin' to" is used by the speaker to explain why he's idle at the moment.  "Whatchoo doin' up there on the porch with that mint julep, Buford?"  "I'm fixin' to go out back and dig me some post holes."  Post-hole digging is a lot of work, so it sounds like the speaker is very busy, while fixin' to dig post holes is kind of relaxing, and may involve whiskey or beer.

... don't ask for a rubber.
Indeed.  Even an upperclass London accent won't help you with that one.  Especially, don't send your young daughter into the drugstore to ask for them.

Y'all is singular ...
Yeah, sort of.  In my experience, the expected form of address - "you," "y'all," or "all y'all," - depends on the angle that the listeners occupy, from the speakers viewpoint.  Narrow angle, "you;" up to about 90 degrees, "y'all;" more than that "all y'all."

59  Using Arduino / Audio / Re: FFT on Arduino, the audio spectrum is cluttered? on: March 15, 2014, 10:57:50 am
However despite using analogRead(), by adding "ADCSRA = 0xc5;" to the code, I still get the same amount of noise reductions while still having around 20kHz freq range.
What's going on here?
What's going on is this:  by executing "ADCSRA = 0xc5,", you change the ADC settings, and change the way it works.  The ADC prescaler is set to 5, selecting a system clock divider of 32, an ADC clock of 500 kHz, and a sample time of 13.5 ADC clock cycles, 27 microseconds.  That corresponds to a maximum sample rate of about 37 kHz, and a Nyquist frequency of about 18.5 kHz.  Because the ADC conversions are triggered by the program, rather than hardware, you'll lose some time in loop overhead and function calls, so the actual sample rate and Nyquist frequency, will be something less.  You measured 15.5 kHz - something less than 18.5 kHz, as expected.  That suggests that you're losing about 5 microseconds per conversion in software, or about 80 system clock cycles.  That's probably not unreasonable.

Your posted code didn't manipulate ADCSRA, so it uses the default prescaler of 7, didviding the system clock by 128, for an ADC clock of 125 kHz, and a maximum sample rate of about 9.3 kHz.  It aliases at something like 4 kHz.  As expected.

If you want to know how the ADC control registers affect the way the ADC works,
You can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.
60  Using Arduino / Audio / Re: FFT on Arduino, the audio spectrum is cluttered? on: March 14, 2014, 07:38:34 pm
But how come that when I sweep the tone generator to 20khz it shows up on the arduino's far right side?  And anything beyond 20 khz starts to move to the left again?
You're talking about using the Open Music Labs code.  It works up to about 20 kHz because the sampling frequency is about 38.5 kHz.  That code doesn't use analogRead() to get samples; it directly manipulates the ADC.  ADCSRA is set to 0xE5: enable,  start conversion, auto-trigger enable, and prescaler 5.  On a 16 MHz Arduino, that sets the ADC clock to 500 kHz, and, with a conversion every 13 ADC clock cycles, the sample rate is about 38.5 kHz.  The Nyquist frequency is about 19.2 kHz - close to 20 kHz.  You can read about setting up the ADC in the ATMega328 datasheet, Chapter 24.

You've noticed, I'm sure, that you don't get that kind of performance out of your "noise cancelling" code.  That code uses analogRead() to get samples, and leaves the ADC clock at the default setting of 125 kHz, prescaler 7.  The ADC isn't free-running, so samples take 13.5 ADC clock cycles, for a maximum sample rate of about 9.3 kHz, and a Nyquist frequency of about 4.6 kHz.  There'll be some time lost between the end of one conversion and the start of another, so the rate will be a bit less than that.  With sampling controlled by the program, rather than a hardware clock, there'll probably be jitter, but, with interrupts disabled, it may not amount to much.

The results shown in the first post, with a bipolar sine signal directly coupled to the analog input, look about right.  I'd expect the ADC to read zero for the entire negative half-cycle, and to track the input signal for the positive half-cycle, if it wasn't destroyed outright.  Here's a link to a table of Fourier series, showing the coefficients for a half-wave rectified sine signal:  It has a DC component, a component at the fundamental, and decreasing components at even harmonics.  That corresponds qualitatively with the initial results.
Pages: 1 2 3 [4] 5 6 ... 25