Show Posts
Pages: [1] 2 3 ... 22
1  Using Arduino / Programming Questions / Re: Calculating slope using array issues on: April 17, 2014, 05:21:37 pm
Here's what I think:
Code:
  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:
Code:
  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.
2  Using Arduino / Audio / Re: arduino FHT on: April 06, 2014, 08:17:17 pm
Quote
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.

Thanks.
3  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.
4  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:
Code:
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?
5  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.
6  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 - http://arduino.cc/en/Main/ArduinoBoardUno - 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: http://search.murata.co.jp/Ceramy/CatalogAction.do?sHinnm=?&nbsp&sNHinnm=CSTCE16M0V53-R0&sNhin_key=CSTCE16M0V53-R0&sLang=en&sParam=CSTCE.

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 - http://www.evilmadscientist.com/2010/diavolino/.

Quote from: Shakespeare, All's Well That Ends Well, ~1604
Our remedies oft in ourselves do lie.
Or, you can build your own.
7  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:  http://deambulatorymatrix.blogspot.com/2010/11/digital-chromatic-guitar-tuner-2008.html.

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:  http://forum.arduino.cc/index.php?board=26.0.  If you want to continue pursuing it in this section, you'd do well to provide a more detailed description of your vision.
8  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?
9  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:
Code:
void setup() {
  Serial.begin(9600);
  Serial.print(A0);
}

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:
 ../hardware/arduino/sam/variants/arduino_due_x/variants.h. 
If you look into that file, you'll find this line:
Code:
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.
10  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.

Quote
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.  

Quote
"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."

11  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.
12  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: http://people.clarkson.edu/~jsvoboda/Syllabi/EE221/Fourier/FourierSeriesTable.pdf.  It has a DC component, a component at the fundamental, and decreasing components at even harmonics.  That corresponds qualitatively with the initial results.
13  Using Arduino / Audio / Re: Frequency detection on: March 10, 2014, 10:33:41 pm
See a similar project here, with link to code: http://deambulatorymatrix.blogspot.com/2010/11/digital-chromatic-guitar-tuner-2008.html.
14  Using Arduino / General Electronics / Re: Multi-phase buck converter on: March 07, 2014, 04:22:00 pm
I'd be leery of this code.  It doesn't do anything intentional to establish any particular phase relationship between Timer1 and Timer2; it just gets lucky.  Here's why it seems to work:
  • The last thing that the internal startup code does is to set up and start Timer2.  Timer2 runs at 1/64 of the system clock, so it's still at zero when setup() executes.
  • Timer1 is set to full scale for its mode - 8-bit phase-correct PWM, mode 1 - rather than half-scale, as claimed in the text accompanying this code.  The code sets it explicitly to 0x7FFF, but Timer1 ignores the most significant byte in mode 1, and sets itself to 0xFF.  That more or less works, because the phase-correct mode counts up to the top, and then down to the bottom, rather than rolling over.  Timer1 is set to one tick away from zero, upcounting, at a time when Timer2 is at zero, upcounting.  On the next tick, Timer2 starts counting down, while Timer1 counts up.  They're almost 180 degrees out pf phase, but that's largely a matter of luck.  If the next version of the IDE adds code between setting Timer2 and calling setup(), or if you add code at the beginning of setup(), the phase relationship will be less accurate.  With just a couple of analogRead()'s, it gets off pretty far.

Here's an 8-phase PWM controller, made for applications like this: http://www.irf.com/product-info/datasheets/data/pb-chl8318.pdf.  It costs about $3 US in big quantities.  I didn't readily find any for sale in singles.  Maybe the manufacturer will sample a couple to you.

I believe that an Uno won't lend itself well to generating the PWM pulses you want.  A Due might.  The datasheet claims, "Up to 8-channel 16-bit PWM," - exactly the right number - but I don't know how that's implemented in the Due, or supported in the IDE.  If you want to investigate that, you might try the Due forum, here:  http://forum.arduino.cc/index.php?board=87.0.

I'll echo Grumpy Mike's sentiment, and vote that you prototype something with less current.  A buck converter runs just one step ahead of the grim reaper - if a driver doesn't switch off, the supply voltage shows up on the output in short order.  This statement:
Quote
I am new to microcontrollers ...
suggests that you'll have multiple rounds of debugging, and, with this project, that suggests that you might see a little smoke.
15  Using Arduino / Programming Questions / Re: Interruptions using TimerOne.h library on: March 04, 2014, 11:22:33 pm
If you're new to this, you may want to try something simpler.  Then, when that works, try adding some additional functions.  Based on what you've said here, it looks like you're trying to write the whole program at once.  When you do that, it can be very difficult to figure out what isn't working.

It sounds like you're making a traffic light controller.  I'll suggest that you try making it work like a simple automatic traffic light:  turns red for a while, and then turns green for a while - you don't mention a yellow light, so I presume that you're not implementing one.  If you can't make it work, you can post your code, describe what you expected, and describe what you it does instead.  If you can make it work, then you can try to add another function, and, when you run into trouble, post code, a clear description of what you expect, and a clear description of what it does.  When you post code, please make sure that you post something that compiles, so that others can load it straight into an Arduino and see how it works.

So far, you haven't told us much.  Your description is hard to understand, and you don't show any code.  It's difficult for anyone to offer any help.

As you get further into this project, you may find that it works well as a state machine.  Here are a couple of references that discuss state machines:
Pages: [1] 2 3 ... 22