Show Posts
Pages: 1 2 [3] 4 5
31  Using Arduino / General Electronics / Re: ADC noise problems on: June 08, 2011, 07:36:40 pm
Hello again, I finally managed to try out the suggestions above and I thought I 'd post the results.

Finding inductors was not easy but with a quick trip to a local computer shop I managed to get my hands on a broken motherboard. From this, I was able to get my hands on some inductors and some pretty enormous electrolytic capacitors which came in handy.

So, the circuit was very simple this time. I connected one motor directly to the battery and sampled the voltage (~10V) through the Arduino's ADC after cutting it down to about a third of its size.

Motor, Arduino and battery share a common ground.


I initially sampled it with the motor "raw". This was terrible, the Arduino disconnected immediately when the motor started working. Even worse, because I 'm on Linux, I could keep an eye on current developments via "dmesg". I could see that the FTDI chip was trying to connect but couldn't as long as the motor was running.

I then connected the smallest electrolytic cap I had salvaged from the motherboard straight across the motor terminals. That was a 100uF, a thousand times bigger than Grumpy Mike's suggestion but my biggest ceramics were small. The motor ran like a dream.

My next move was adding a very large electrolytic cap (3300 uF) parallel to the original, bringing the total to 3400 uF. For some reason, the Arduino didn't like that, it reset itself a couple of times when I turned on the motor, although "dmesg" informed me that the FTDI immediately went and registered at the next available serial port (a Processing sketch trying to talk to the chip kept the original port occupied).

I removed the big electrolytic and went on, adding 47nF ceramic caps from each terminal to the case, added inductors and finally added the big electrolytic across the far side of the inductors, taking measurements at every step. This is what the final thing looks like.



And here's a picture.



I then had a look at the data. Here's a graph of sampled voltages with the motor on.



The standard deviations of the signals in every case is on the legend. There is a definite trend for the voltage to settle more as more components are added. However, it seems that, compared to the vast difference I got between the samples of the "raw motor" (where I couldn't even get a sample as the Arduino immediately gave up) and adding the first cap between the terminals, the remaining components did not do much more.

Still, I had fun playing around with the circuit. Thanks again.
32  Using Arduino / General Electronics / Re: ADC noise problems on: June 05, 2011, 05:41:51 am
Hello again, I 'm trying to make a sketch of all the advice I got in this thread so that I can visualise it and perhaps help some poor sod in the future. So, this is what I have come up with.



Killing the motor noise requires putting the capacitor(S) DIRECTLY at the motor terminals. Even three capacitors, one from each terminal to the motor case, and one across the terminals. And likely significantly larger value capacitors.


I have added cap C1 across the terminals and C2 from each terminal to the case. Some ballpark figures (and ballpark value ranges) for these caps would be welcome.


Also, bypassing the H-bridge chip itself would be advisable

This I don't understand. I need the H-Bridge to supply the thirsty motors. What do you mean by bypassing it?


You can also put series inductors in both motor leads with a capacitor across both the motor and across the other side of the inductors. These should be larger than 3n5, make them 100nF and should be fitted physically as close to the motor as possible. One inch away is too far.

I have added the series inductors (L). I guess "across both the motor" means C1. However, I don't understand what is meant by "across the other side of the inductors". Other side of what? Should I add caps in parallel with the inductors (Ca?)? Connect them across the power line gap (Cb?)? My guess is the latter, since it would serve the same purpose as the 47 uF cap in the final sketch in Grumpy Mike's De-coupling tutorial. Have I got that right?
33  Using Arduino / General Electronics / Re: ADC noise problems on: June 05, 2011, 02:08:27 am
D'oh, I 'm a moron  smiley-razz

Vibrations!

I simply removed the accelerometer board from the platform and held it in my hand a few millimetres above its position and my "noise" disappeared.

Thank you so much guys, Grumpy Mike's tutorial is excellent reading, straight to the point. I 'm glad you pointed me to it.
34  Using Arduino / General Electronics / ADC noise problems on: June 04, 2011, 09:48:34 am
Hello forum, I have a problem with noise on my analog lines and I was wondering if anyone had any quick and dirty ideas I could play with. Here is a quick description of what I 'm trying to do.

I have a DC-SS009 3-axis accelerometer which spits out an analog signal which can be read through the Arduino's ADC. I thought I 'd mount it on a platform that is allowed to rotate along one axis and stick two motors with propellers on either end to balance it at a given angle. The whole setup can be seen below.



Now, some more detail. The motors suck around 400 mA when going strong so I power them through an L293 H-Bridge. Now, here is the problem. Motors on the power line do absolutely disgusting things to the voltage level. When powering both my Arduino and the motors from the same source, I have had the Arduino resetting repeatedly.

To counter this, I have kept the Arduino and motor power supplies separate, the motors are powered by a battery (some 10.5 Volts give or take) and the Arduino by the PC through the USB cable. To keep things even cleaner, the logic level voltage needed by L293 is given by a 5V voltage regulator and not by the Arduino 5V pin. This way, the only interaction between the Arduino and the L293 is through two of the Arduino's digital out PWM pins which connect to the corresponding input pins of the L293. To dampen any nastiness in the motor power lines I have added a capacitor on each, connecting it to ground. Battery, voltage regulator, motors and Arduino share a common ground. All this is shown in the diagram below.




If I 'm using my multimeter properly, the capacitors I 'm using seem to be around 3.5 nF. Here they are.





This circuit is the best I could come up with the get rid of noise but unfortunately, it doesn't cut it. Here's why.



The picture below shows the final angle readings I get after processing the ADC voltages. This is the range of motion I have physically allowed the platform and the resolution is not that bad within it. These readings have been taken with the motors off and me moving the platform with my hand. It is sketched in a silly little Processing sketch I have written to act as a crude scope.





The next one shows the same thing (me moving the platform around within its limits of motion) but with the motors on. The noise is beyond terrible.




This one shows the transition to quiet as I turn the motors off. The difference is obvious.





Now, the big question is, where does the noise come from? If it's kicked back down the motors' power supply line and somehow manages to travel through the L293 and up the Arduino's digital output pins there's not much more I can think of doing other than stuffing ever bigger capacitors on the motor power supply line. However, I thought I could be picking up electromagnetic noise through the unshielded lines going to the ADC acting as aerials. I 'm sure the motors must be spitting out some pretty disgusting EM fields around them as they go about their business and the ADC line is just begging to pick it up.

To test this, I disconnected the digital output pins from the L293, completely isolating the Arduino from the motor power supply lines (they still share a ground). I then connected the motors directly to the battery and turned them on and off. The results are shown below. I was quite astonished at what a tremendous amount of noise my unshielded line is picking up (I am also astonished that the platform actually manages to kind of balance, although in a very drunk manner).




So, my big question. Is there anything I can try to get better measurements? The obvious answers I can think of are:

a) get an accelerometer with digital output (I 've got my eye on this one http://www.sparkfun.com/products/9723). Expensive but the best solution I guess.

b) get shorter ADC lines. My cables are certainly longer than they need to be but what happens if for whatever reason I need them to be long?

c) shield them. If I wrap the cables in tin foil and then connect it to ground, will I get any worthwhile effect or would I be wasting my time?

Am I missing something obvious?

Cheers.
35  Using Arduino / Storage / Re: Destroying SD cards through low voltage on: February 06, 2011, 05:52:21 pm
I was using the sparkfun microSD shield with the SDFat lib. I have used the shield and the lib succesfully for very long logging times (~24 hrs) with no problems so it might have been a problematic card.
36  Using Arduino / Storage / Re: Destroying SD cards through low voltage on: February 06, 2011, 03:36:00 am
Thank you for the links guys, I 'm sure I 'll need to use them in the future. Unfortunately I have thrown away that card, all this happened quite a while ago, it's just that I only got round to writing about it now.

As far as I can remember, using a file browser to look inside the device was resulting in the device hanging and trying to format it was resulting in gparted just working indefinitely while the XP formatter was saying it was unable to format after a really long time. I was getting some I/O type of erros in the logs (Linux) but I can't remember what they were now.
37  Using Arduino / Storage / Destroying SD cards through low voltage on: February 05, 2011, 07:27:36 am
Hello forum. This is a question and a possible warning.

I managed to completely destroy an SD card. It got so badly mangled that two different computers each running both Windows and Linux refused to talk to it. What I think happened is that I left it logging data on a battery connected Arduino for too long and the battery fizzled out.

I know for a fact the battery was dead when I got the card back and after that the card was stone dead. I presume write operations with insufficient voltage killed it. Does anyone have any experience of this?

This raises the obvious question of monitoring input voltage level when on a not so secure power supply. Is there any way of getting to this info through software, other than grabbing Vin, dumping it through a voltage divider and measuring through an ADC pin?
38  Forum 2005-2010 (read only) / Bugs & Suggestions / Bug in function equals() of WString library. on: December 17, 2009, 01:23:20 pm
Hello, I 'm linking to a post I made originally as a question in the Syntax&Programs section.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261015776/0

It shows what appears to be a pretty strange error in the equals() function of the WString library.
39  Forum 2005-2010 (read only) / Syntax & Programs / Re: My class does not name a type on: September 29, 2010, 07:27:43 am
Ah, thank you. I was hoping I wouldn't have to write a library if all I want to do is use a small class but anyway, I did and it worked.
40  Forum 2005-2010 (read only) / Syntax & Programs / My class does not name a type on: September 28, 2010, 04:23:18 pm
Hello guys, I am having surprising amounts of trouble with something that ought to be trivial. The code below compiles fine:

Quote
class Foo {
  public:
    int x;
    
  Foo(float f) {
    x=(int)f;
  }
  
  int getX() {
    return x;
  }
  
};


void setup() {
  
  Foo f = Foo(3.1415927);
  
}

void loop() {
}


My class Foo is perfectly useable in setup and all is perfect with the universe. That is, until I try using it as a return value or an argument to a function e.g. adding this after loop():


Quote
Foo zonk(float f) {
  return Foo(f);
}


Gets me a:
error: 'Foo' does not name a type


while this:

Quote
int zonk(Foo f) {
  return f.getX();
}


tells me that:
error: 'Foo' was not declared in this scope

Why is the great big chunk of code defining the class at the start of the sketch not good enough when trying to use the class in this context?
41  Forum 2005-2010 (read only) / Syntax & Programs / Re: Array initialisation in a class on: June 15, 2010, 03:47:21 pm
Thanks guys, I 'll check out FIFO. However, can you let me know if the code I posted does what I thought it does or if it's a horrible monstrosity?
42  Forum 2005-2010 (read only) / Syntax & Programs / Array initialisation in a class on: June 15, 2010, 10:44:29 am
Hello forum, I was trying to write a quick and dirty ring buffer and have run into the following problem, I 'm not too sure what happens when I try to declare an array as a member of a class but initialise it in a constructor, e.g.

Quote
class myRingBuffer {
  public:
  
  int daBuffer[];
  
  myRingBuffer(int size) {
    daBuffer[size];
  }
};


void setup() {
  myRingBuffer mrb = myRingBuffer(10);
  mrb.daBuffer[9] = 3;
  Serial.begin(9600);
  Serial.println(mrb.daBuffer[9]);
}

void loop() {
}


So, the above compiles, uploads and prints 3 on the serial monitor. But is it doing what I assume it is doing, that is creating a 10 integer long array when the constructor gets called? Or does the single line in the constructor simply call an address "size" integers down from the start of the array and discard the result? What I 'm driving at is, when I read/write to the array after I instantiate "mrb" am I using a legal address or am I groping at random somewhere in memory?

One final worry, when trying to encapsulate stuff to keep things tidy, is there any worthwhile performance difference if using typedef and data structures instead of C++ classes?
43  Forum 2005-2010 (read only) / Syntax & Programs / Re: Freaky behaviour for equals() in WString on: December 17, 2009, 01:18:16 pm
Thanks, the problem can be bypassed by using contains() instead of equals() (and checking length as well if one wants to be absolutely sure). I will post it as well in the bugs section in case some developer wants to have a look.
44  Forum 2005-2010 (read only) / Syntax & Programs / Freaky behaviour for equals() in WString on: December 16, 2009, 09:09:36 pm
I 've got some really weird behaviour in function equals() of the WString library. Have a look at the following simple code:

Quote
#include <WString.h>

void setup() {
  Serial.begin(9600);
  
  String s1 = "ARGH";
  String s2 = "ARGH";
  
  if (s1.equals(s2)) {
    Serial.println("blip");
  } else {
    Serial.println("blop");
  }
  
}

void loop() {
}


Now, call me optimistic but I 'd have thought it would print out "blip". Failing that, it would print "blop". Still running it gets me a blank screen on my system using Arduino Mega, IDE 0017, 64-bit kubuntu Linux. WString.h has been patched as per instructions (~String() { free(_array); } // <--- add this line) on thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241618944/11

although, this does not seem to be making any difference (tried both with and without the extra line).

Now, it would seem the code gets lost in the equals() function but it gets weirder. Adding some print statements to clarify what's going on the code becomes:

Quote
#include <WString.h>

void setup() {
  Serial.begin(9600);
  
  String s1 = "ARGH";
  String s2 = "ARGH";
  
  Serial.println("About to compare the strings...");
  if (s1.equals(s2)) {
    Serial.println("blip");
  } else {
    Serial.println("blop");
  }
  Serial.println("Finished comparing the strings.");
  
}

void loop() {
}


I 'd have thought this would print "About to compare the strings..." and then hang. However, my output becomes:

About to compare the strings...
About to compare the strings...
About to compare the strings...


etc, about once per second  :o

How in the name of all possible deities do I get an infinite loop in setup()? Something somewhere must be very seriously broken. Any ideas?
45  Forum 2005-2010 (read only) / Syntax & Programs / Re: Installation of WString library on: November 06, 2009, 06:52:32 pm
Thanks guys. .../hardware/libraries/ worked for me as well. But I can't help but wonder why the instructions quote lib/targets/libraries. I also saw the same instructions while browsing some other library, can't remember where now. Maybe lib/targets/libraries is a folder used in older versions that the new IDE overlooks? Still, it would make sense to have a separate folder for libs which are not hardware related.
Pages: 1 2 [3] 4 5