Show Posts
Pages: 1 2 3 [4] 5 6 ... 27
46  Using Arduino / Programming Questions / Re: Timer1.attachInterrupt( timerIsr ) problem on: May 18, 2014, 06:28:01 pm
i changed "== "by" = "and i cleared " interrupt" and i wrote volatile unsigned long var[n] but nothing happened.
You need to do these things, too:
  • Declare n as volatile.  It's shared between the ISR and other code.
  • Delete the Serial.print() from Timer1 ISR.  That statement is what's stops execution.

How do I guarantee that "n" is increment to the 50 without put the serial inside the ISR ?
Serial.print() n from loop().

i think that your sketch still won't give you accurate results after you make those changes, but it ought to run.  The best I can tell, there will still be plenty of things wrong with it.  Your code is garbled because you didn't use code tags when you posted it.  Anyone who wants to help you will have to guess at what your code really looks like.  It's easy for you to make your intent clear; it's hard to guess what you meant.  It's been said before in this thread, but I'll be repetitive and say it again:

Use code tags when you post code.
47  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 17, 2014, 07:29:14 am
... a 1200x3 byte and a 1200x1 int, as opposed to a 1200x4 int.  That still won't fit in flash memory but it will help anyway.
It'll probably fit into flash memory, if your program isn't too big.  "Flash" refers to program memory, and there's a little less than 32K available.  Flash, or program memory, is where your data resides when you declare it using "PROGMEM".

You need 6000 bytes for your data.  If your program doesn't exceed about 25K or so, you should have room.  The IDE tells you the compiled size of the sketch; you can see it in the lower window when compilation completes.  The arrays won't fit into RAM, since there's only 2K of that.  

Edit:  spelling
48  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 16, 2014, 09:15:53 am
No your memory is lying to you.
Not yet, I think.  In a test program, this line compiles, and the array elements show up where I expect them:
int16_t a[3][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,0,1}, };
Note that last unnecessary comma before the last curly bracket.  No complaints from the IDE, even when I asked it to be verbose.  
49  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 16, 2014, 01:43:32 am
Your statement that I bolded above is not helpful., IMO.
Apparently not.  I thought it hinted at a solution to the OP's stated problem.  Since it didn't seem to work, I'll be explicit this time.

Addressing the OP's directly stated concerns,
Now I just need to figure out how to convert a CSV into an array and store it in program memory...
... it's 1200 rows long so there's no way I'm converting from CSV to the second format manually ...
In view of the resources that he seems to have in hand,
... I'm trying to get the data from Excel onto the Arduino ...

Here's how I'd put that data into a PROGMEM array:
  • Open the CSV file in a text editor, and copy it to the clipboard.
  • Open a spreadsheet, and paste.  The reason I wouldn't open the CSV in a spreadsheet directly is to keep the spreadsheet from trying to parse the data.  If you have a way of keeping it from doing that, you can open the CSV straight from the spreadsheet program.
  • Write a spreadsheet formula to append a curly open bracket, a curly closed bracket, and a comma to single line, and paste it where I need it.  In Excel or in LibreOffice that formula might be, untested:
="{ "&A1&" },"
  • Copy the results of that formula from the spreadsheet, and paste it into the IDE.
I do this fairly often, for the same reason that it seems the OP wants to: to use handily captured or calculated data as known input to a program under development.  My memory tells me that the compiler doesn't even complain if you leave the last unnecessary comma in the code.  If you're a purist, you may want to take it out.

You might want to take the intermediate step of pasting the data from the spreadsheet into a text editor, copying it again, and pasting from that into the IDE.  I've seen the IDE balk at big clipboards from Excel, but not from Notepad or Gedit, and those programs handle pastes from spreadsheets with aplomb.

Of course, all that presumes that you can readily get data out of a 2D PROGMEM array.  I've never tried it.  This post says it has a solution; maybe it works -  Alternatively, you could use a one-dimensional array, and index it with something like 4*i + j, where i is the row index, and j the column, zero-based.  If you go that route, you don't need brackets around each line, you only need to add a comma at the end of each. 

I note that the sample data shows five entries per line, rather than four, and that the sample code applies that information inconsistently.  Maybe that data is for illustration, and not the real thing.  If the CSV has line numbers, you'll want to account for it somehow, either by allowing space for it in the array, or stripping it out of the data.  The array already takes up nearly a third of the available flash memory; I'd recommend removing line numbers.  Here's a way to strip the first entry off a line of comma-separated values in Excel or Libre, untested:
OpenOffice might do it that way, too; I don't remember.

As I see it, that solves the problem, as it was directly stated:  it make the data available to the program, it doesn't require the OP to manually change oodles of lines of code, and it uses the tools he says he already has.
50  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 15, 2014, 06:29:46 pm
Now I just need to figure out how to convert a CSV into an array and store it in program memory...
To initialize an array, either in RAM or with PROGMEM, you put the values inside curly brackets, and separate them by commas.  CSV stands for, "comma separated values."  Does that suggest anything to you?
51  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 15, 2014, 11:23:56 am
1200 x 4 is 4800; ints take two bytes, for a total memory requirement of 9600 bytes.  You can't store that in RAM on an Uno.  You can store it in program memory, if you have that much to spare.  Here's a description of how to store and fetch data in flash:
52  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 15, 2014, 07:40:54 am
I tried with ArduinoFFT ...
What did you try?  What did you expect it to do, and what did it do? 

If you answer those questions, and post code and a schematic, it can only help.

53  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 13, 2014, 09:56:36 am
... what is amplitude of a signal from an average cell-phone player? ...
I don't know of any standards.  Here's a guy testing the audio output of an iPhone 5:  According to him, full output is about 1.4V peak-to-ground, with an output impedance of 4.5 ohms.  With a 2.5V offset, that'll give ADC read ranging between roughly 225 and 800, at full output.
54  Using Arduino / General Electronics / Re: Measuring AC mains on: May 11, 2014, 06:30:59 pm
Quoth the OP:
I had not thought about measuring power.
That suggests that precise power measurements may not be the intent of this project.  Without knowing the data is for, or how accurate it has to be, we're chasing our tails here.

That said, I don't think that measuring the phase angle between the voltage and current is necessary.  Real power is the sum of the products of the instantaneous voltage and current readings; reactive estimates nicely from that and the RMS values of voltage and current with the Pythagorean Theorem.  That method assumes that there aren't any appreciable real or reactive power components at any frequency other than the fundamental, but so does calculating reactive power using the phase angle as calculated from the fundamental frequency.
55  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 11, 2014, 05:13:33 pm
I did some things ...
I don't see a description of what you did.  A schematic would help.

Can one suggest a ready to use solution if there is one?
Here's what I use: a cheap homemade circuit to connect the audio output of the PC to the Arduino.  A schematic is attached.  The Thevenin equivalent of the voltage divider is a 10K resistor and a 2.5V DC supply.  10K is suitable for an analog input, as described in the datasheet.  Note that there's nothing in series with the analog input.  I've verified that my PC won't output a 5V peak-to-peak signal, so I don't worry about overdriving the analog input.  You may prefer to use two 10K resistors, and a 5K in series, for an equivalent impedance of 10K, with the 5K providing a measure of protection for the analog input.  This scheme isn't really suitable unless the input is stiff enough to drive the equivalent impedance of the voltage divider; otherwise, the signal level will drop.

I added a 100K resistor to ground from the signal input.  That's because I suspect that the audio output is capacitively coupled, just like my input.   Without the resistor, the DC voltage between the two capacitors is essentially undefined.  Because I'm using an electrolytic capacitor, and I presume that the audio output does, too, I add the resistor to keep the DC level between them at ground, and make sure that the capacitor polarities are proper.  I can't say that it's necessary; I just like having it in the circuit.

Advantages are that it's cheap, easy to build, and I can define the analog input quite precisely by generating my own audio content.  The primary disadvantage is that it doesn't lend itself to real-world inputs:  The input impedance is so low it would pull down most guitar inputs, and it has no protection from analog overvoltage, as you might get from an amplifier output intended for a speaker. 

Criticism is welcome.
56  Using Arduino / Programming Questions / Re: interrrupt with timed LEDs on: May 09, 2014, 11:06:21 am
pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
and this:
never go in the same sketch.
i don't see the conflict.  As long as neither of ledPins[0] and [1] are 0 or 1, what goes wrong?
57  Using Arduino / General Electronics / Re: Measuring AC mains on: May 09, 2014, 10:33:51 am
Here's an application note from Atmel on this very subject:  They use a voltage divider on the power line, capacitively coupled to a DC voltage divider at the analog input, and the AVR's power supply is earthed.  I'd say that scheme is a bit delicate for connection to a power line.  A resistor in series with the analog input, with a couple of diodes to the supply voltages, would go a long way toward protecting that input from transients. 

The app note also describes controllable amplifier for the current input, since the dynamic range of the current levels that a meter will see is very wide.  You may not need that, if you don't need a lot of resolution at low current. 

What are you going to do with this data?  That'll affect which solutions might work for this project.
58  Using Arduino / Project Guidance / Re: PWM arduino uno problem? on: May 06, 2014, 11:45:30 pm
Can anybody tell me how to calculate duty cycle?

The Wikipedia article is reasonably clear, and not too complex.
59  Using Arduino / Programming Questions / Re: Changing ISR's return address to a function's memory location? on: May 05, 2014, 04:45:41 pm
I see this as a solution to the problem of synchronizing ADC readings.  I admit, though, that my understanding of the OP's goal is kind of fuzzy.
  • Set the ADC to auto-trigger on external interrupt 0
  • Set a timer to run at the appropriate frequency
  • Set that timer to deliver a PWM output
  • Connect that PWM pin to external interrupt 0 on both Arduinos
The datasheet says that the ADC prescaler is reset when the ADC is auto-triggered by an event, to assure a fixed delay from the trigger event to the start of conversion.  That will ensure that the samples taken by the two Arduinos are in sync to within what I'd expect to be a couple of system clock cycles, without intervention from the program.  Without some kind of active synchronization of ADC readings, they'll drift apart quite quickly, due to the difference in the frequencies of the two ceramic oscillators.

If the intent is to make power measurements on a single-phase circuit, I think that taking readings of current and voltage alternately on a single Arduino would be accurate enough.  Fiddling with a unity power factor calculation, close to full scale, in Excel, I get an error of about 0.1% by reacting alternate readings as if they were taken simultaneously.  Interpolating one set, I get about the same results.  That seems to be plenty accurate for a metering application, but there's no guarantee that's what the OP is up to.
60  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 04, 2014, 08:41:07 pm
OK.  If you don't have the FFT and display program working yet, you probably want to start on them.  Eventually, you'll process an array of analog data with your FFT code.  You can start now, using test data.

I'd like to know if anyone has built a working tuner on the Arduino based on the FFT.
Pages: 1 2 3 [4] 5 6 ... 27