Show Posts
Pages: 1 ... 74 75 [76] 77 78 ... 91
1126  Forum 2005-2010 (read only) / Interfacing / Re: Reading high impedance analog inputs quickly on: June 27, 2010, 11:27:14 am
But that's the trick.  You're not pulling against 10K.

I've got the 1M pulldowns and the touch switches on A0 and A1  I've got the 10K pulldown on A2.  

And I read the pins like so:

a0 = analogRead(0);
a1 = analogRead(1);

So the 10K is connected only for a moment... Which because it is relatively low impedance, is long enough for it to pull the ADC down to 0v.

Then I connect the pin with the switch and the 1M pulldown.  And the 1M pulldown is enough to keep the pin at 0V.  

Until you touch the switch that is.

Once you do that, you're now effectively connecting a pullup whose reisstance is much less than 1M.  

How much less?  I'm not sure.  But it seems to work.  

Generally with a dry finger I can get readings of around 256 if I apply pressure.  I think that means I'm 3/4 of the way to 0V, which would put the resistance of my finger around 750K.  

Anyway, the theory of operation here is that my finger can do a better job pulling up the ADC than the 1M pulldown can do pulling it down, and that 1M pulldown may have a long way to go to get to 0V.  Also, by doing this, I'm starting at a solid base of 0V, and the only way to go is up, and if I'm not touching the switch it shouldn't rise at all with that 1M pulldown holding it down.

Here's my actual code btw:

const int analogLeftTouch = 0;
const int analogRightTouch = 1;
const int analogLeftServoTrim = 4;
const int analogRightServoTrim = 5;

const int analogDelay = 1; // The number of milliseconds to pause between analog readings.

analogRead(2); // 10K pulldown
tmp = analogRead(analogLeftTouch); delay(analogDelay); a0 = (a0 + analogRead(analogLeftTouch)) / 2;
tmp = analogRead(analogRightTouch); delay(analogDelay); a1 = (a1 + analogRead(analogRightTouch)) / 2;    
a4 = analogRead(analogLeftServoTrim);
a5 = analogRead(analogRightServoTrim);

As you can see, I'm doing a little more than simply reading the touch switches after reading the pin with the 10K pulldown.  I'm also doing a running average, and switching to the pin then waiting for 1ms before reading it.

The above isn't necessary to get good values though.  I'm not even sure if I need the delay, that's just the state the code was in when I went to bed this morning.

But anyway, if you take out the code that reads the pin with the 10K pulldown on it, everything goes pear shaped and the values read from the touch switches end up all over the place.  That is, unless those delays are more like 20-40ms.  But even then, the values are still kinda noisy, and I tried all sorts of schemes to debounce them, including writing a kind of software schmitt trigger to consider the switch on when it rises above a certain value and off when it goes below another.  Nothing worked.

With the above setup however, all I need to do is check to see if the reading I get from the touch switch pins is higher than 8, and they work beautifully.  They're extremely responsive, and they happily stay off when not being touched.  There's a little bouncing if if try to brush the touch switches as lightly as possible, but simply placing a finger between the contacts with little to no pressure gives a solid trigger.
1127  Forum 2005-2010 (read only) / Interfacing / Reading high impedance analog inputs quickly on: June 27, 2010, 03:58:25 am
I've been wracking my brain all night with a problem, and I think I've found a solution, but I thought I'd run it by you.

I have two resistive touch switches in my circuit.  The two analog pins they're connected to are pulled down via 1M resistors, and one of the contacts is connected to +5v.  When you bridge the two contacts with your finger, you pull the analog pins up because your finger has less resistance than the pulldown resistor.

Sounds good on paper, but when first tried doing this, I was getting all kinds of crazy readings.   GrumpyMike explained that the analog pins are multiplexed... that there's only one ADC to read voltages on the microcontroller, and it just switches it between the pins.  And because my pulldown resistor was so large, it couldn't pull the ADC down quickly enough to get a proper reading.  The solution he explained, was to read the pin twice, with a delay between.  The first read would switch the multiplexer to the appropriate pin and allow it time to pull it down.  The second would read the actual value.

The problem is, I can't have my program sitting there doing nothing for 40 milliseconds.  I have other pins I need to update.  I tried using the millisecond timer to perform the same task while still being able to do other stuff, but it worked terribly, and I had no idea why, since I wasn't accessing any of the other analog pins while I was waiting for the pins to discharge.

So I started looking for a hardware solution.  And the solution I came up with after many false starts is deceptively simple:

I connected one analog pin to ground via a 10K pulldown.

Now why would I do this?  

Well, when I ws having problems reading these switches in the first place, GrumpyMike explained to me that the analog pins are all connected to a multiplexer which switches them to a single ADC in the microcontroller.  And the reason I was getting readings that were all over the place was because my 1M pulldowns weren't pulling the ADC's input down fast enough.

The solution he offered to this problem was to add those delays.  Read the pin once, wait for it to settle down, then read it again.  

But I didn't have time for that.  And my attempts to borrow time by switching to the pin, doing stuff, then going back to read it had failed.

So I wondered if there wasn't some way I could pull that input down faster, as if I had 10K resistors on my touch switches?

That's when it occured to me that I could attach the 10K pulldown to a spare analog pin I had.  Then, because internally it was connected to the same thing as the pins my high impedance switches were conneced to, I could simply read it to switch the multiplexer to it briefly, pull the ADC input down to near 0v, and then switch to the pins I wanted to read which could be pulled up faster than they could be pulled down because skin has a lower resistance than the pulldown I'd stuck on the pin.

The results I got from this change were immediate.  Rather than values that were all over the place, I now got very clean readings, even when reading the pins with no delay at all.

As far as I know, what I've done shouldn't harm the Ardunino at all.  It's just a pulldown resistor.  I will need to do more tests to see if I get any better results if I add a small delay or read the ports twice, but the raw numbes I'm getting are so good I don't think I'll need to do much more than a running average to smooth them out a little more.

So what do you think?  Good technique?
1128  Forum 2005-2010 (read only) / Interfacing / Re: Question about standalone atmega328 on: June 26, 2010, 11:27:51 am
I'm no expert on this, but I did get a standalone AtMega up and running using the schematic for the Realt Bare Bones Board:

I used one of the AtMegas with the preburned bootloaders from Sparkfun as I don't have time at the moment to figure out how to burn a bootloader onto a chip myself.

With the above schematic, I was able to add the software reset cap and hook the board up to the SparkFun 5v basic breakout, and it seems to work perfectly, even if I normally run the chip off less than 5v.
1129  Forum 2005-2010 (read only) / Interfacing / Re: Does updating a servos position draw more current? on: June 26, 2010, 02:17:04 pm
If there's no load, and you don't want the library to keep pulsing the servo, just deatch it.

Hm... I guess I could do that when my servo arms are down. They're likely to remain in that position for long periods of time, and the parts they're attached to would be tucked away inside the prop so they couldn't be easily moved by hand.


Gotta check to see if attaching them causes them to twitch or pause though.  Having that happen every time you activate the movement wouldn't be good.
1130  Forum 2005-2010 (read only) / Interfacing / Re: Does updating a servos position draw more current? on: June 26, 2010, 02:12:17 pm
I've just now commented out the servo control code in my program, and found that the deciding factor in whether the servos hold position or not is whether I've called the attach() method.  So it is indeed the servo library doing it, not the servos.

And if the servo library is updating their position constantly, then I suppose it doesn't matter if I'm trying to update their position or not.
1131  Forum 2005-2010 (read only) / Interfacing / Does updating a servos position draw more current? on: June 26, 2010, 02:01:15 pm
Hey guys,

Obviously moving a servo draws more current than not moving it.  That's not my question. :-)

My question is this:
If my servo is already centered, does it draw more current if I constantly tell it to recenter, than if I leave it be?

The reason I ask is I'm wondering, for power conservation reasons, whether I should check the current position of the servo in code before updating it to see if it needs to be updated.

Also, the servo I'm using is this one:

It's an analog servo.  Yet even when I'm not updating the servo's position in code, it seems to be holding its position, like I would expect a digital servo to do.  (It makes noise when I try to move the servo arm.)  

Have I made a mistake in my code, or does the servo library constantly update the positions of the servos itself?
1132  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 26, 2010, 10:38:22 am
Okay just for the sake of completeness, I tested the two regulator setup again.

* With an apparently nearly dead 9v that's putting out only 7v, the circuit doesn't work properly.  The Ardunio resets when i try to move the servos.

* With a fresh 9v the circuit works great.  But for how long it will run great, I have no idea.  (Keep in mind, I got this same result using a single regulator.)

* And with with six somewhat stale AAAs putting out 8.3v, my leds dim very slightly.

I don't have six fresh AAAs to test with, though I imagine they'd work as well as the 9v.

I think this proves that I can power my circuit from 9v if I wish.  The question is for how long.  The very rapid battery draining yesterday I suspect was due to my wiring mistake.

To determine if that was the case, I tested my battery before and after a test.  For the test, I cycled the servos 100 times, at a rate of one cycle per second.

Before the test, my battery read 8.84v on my meter.
After the test, my battery read 8.51v on my meter.

From that I can conclude that I'll lose around .31v every 100 cycles.

And with a fresh 9v reading 9.21v, and knowing that at 7v my circuit won't run, and at 8.3v the leds start to dim, I can surmise that I would probably get at most, 400 cycles of the servos out before the prop stops functioning completely, with the LEDs beginning to dim significantly at around 300.

Is that within reasonable operating parameters for this prop?  Maybe.  This prop is a scanning device and is something the user might take out of their pocket, turn on, use for a minute activating the servo motion one or twice, and then put away to use again a few minutes later.  

In extreme cases though it might be used for extended periods.  Five minutes or so at a time, and may be used throughout the day in this manner.  In that case, I'm not so sure tha 9v would hold up.  However, if the batteries held up for half a day of intermittent use, that would be good enough.

Still, not convinced the 9v is up to the task.  But what about the AAAs?  Well, they've got twice the capacity.  So they should hold up twice as long.  This is all very approximate.  But twice as long would be 800 cycles of the servos instead of 400.  Is that enough?  Maybe.

AAs are twice again as powerful as AAA's.  If these numbers hold true then if i used six of those I'd get 1600 cycles out of the prop.  That seems like a really good number.  Unfortunately, I don't know that I could fit six of those in the prop.  Might I fit four and use a LDO regulator?  Maybe.  Very tight sueeze probably.  Using a LDO regulator would change the equation of course, but with the extra capacity of the AAs I migtht still be fine.

So hm...

Here's the current state of things:

* I know that using two regulators doesn't really solve anything.
* I know that using capacitors isn't a solution.
* I know that using exotic methods to regulate current isn't a solution either.
* I know that using resistors to limit the current a no go too.

* In fact, I now know all potential methods of limiting the current are a no-go, because last night I calculated the speed of the arms on the prop in the film and they are about as fast as what the fastest servos can manage when running at 6v.

* As a result of the above calculation, I'm now once again considering going with a single 5v LDO regulator, which I may try powering off 6v.

* On the other hand, 4.8v isn't much less than 5v and I could power the servos with a regulator and the Arduno directly off a 4.5v battery pack.  If I can find a way to fit 9v and 4.5v battery packs in the prop.

* I've got some numbers to work with now on how long different batteries might last.  I don't know how accurate those numbers are, but they're a starting point.

* Small rechargable batteries, like rechargable AAAs, are starting to look mighty appealing for their ability to supply large amounts of current for longer at higher voltages.

* But rechargable battery packs are still out of the question.  The chargers are too expensive.

I think that about covers it.  I at least have a few potential paths to a workable solution now.
1133  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 26, 2010, 08:59:37 am
I found out something important last night which I forgot to mention.

I discovered that the power rails on my Sparkfun board were not in fact, broken in the center.  

I'd thought they were.  I was sure they were.  I've been using jumpers to bridge the rails since I got the breadboard.  I could have sworn I found out about the issue because another project didn't work because they were broken.

But apparently they're not.  Last night I noticed power was getting from my voltage regulator to the Arduino, and there was no path for it other than those rails.

That means that my experiments with the two regulators are null and void.  They were attached to the same voltage rail, just at different positions along it which I thought weren't electrically connected.
1134  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 26, 2010, 01:58:16 am
The capacitor is a 10uf (10 microfarid). If the "u" I drew looks like "n", then there may also be visual issues. Perhaps you are just not familiar with typical electrical symbols.

My bad.  I keep mixing up uF and nF.  I'm not used to dealing with such small metric units.

1135  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 26, 2010, 01:03:31 am
And add a diode "check valve" on the supply to the capacitor to prevent the servos from draining the capacitor when they pull the supply voltage low.

I still don't get understand that first circuit you posted.  The diode on the output pin of the regulator makes sense if you want to prevent current from the capacitor from flowing into the servo, but what's the diode on the adjust pin for?

And a 10nF cap seems awfully small to me.  How do I know if that will be enough to supply current to the rest of my circuit?

And why does your servo say it's being supplied by +5.7v if you're using a 7805 regulator which is a fixed 5v?

And what's the transistor for?
1136  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 26, 2010, 12:41:16 am
A solution for working around "peaky" loads like your servos is to add as much capacitance as possible to form a "storage tank" buffer that will supply the peak currents when the battery can't

So how do I do that?  How do I calculate how large a capacitor I need?  How do I connect it to the circuit?
1137  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 25, 2010, 10:25:07 pm
I've been trying to think of ways to limit the current to the servos when they start up so as to ensure the rest of the circuit still has adequate current.

I just remembered that the datasheet for the LM317 said it could be configured as a current regulator.  And I'm wondeirng if perhaps I could stick that on a servo and limit the current flowing through it.

I don't know anything about current regulation, but I'm looking at a tutorial now, and it says current regulation comes at the cost of voltage regulation.  That sounds bad.

But speaking of current regulation, that reminds me... I've also been looking at Op-Amps.  I'd heard they could be used to convert voltage to current.  I just found this page on using them as a current source:

I'm not sure if something like that might do the job.  Or how complicated they are to implement in a circuit.  Or how they differ from a current regulator.

But back on the subject of the current regulator...  

If a current regulator behaves like a voltage regulator, and a voltage regulator can take in 9v and output 5v burning the rest off as heat, but can't give you 5v if you only input 4v... Then does that mean a current regulator can take in 500mA, and output 300mA, burning the excess off as heat, but if it's only got 200mA to work with it can't give you 300mA?

I'm thinking since the servos are the cause of there not being enough current, if I stuck a current regulator on them, that would remove that viariable.  

So instead of:
WhatBatteriesCanSupply - CurrentServosDemand = WhatsLeftOverForTheArduino

I'd have:
WhatBatteriesCanSupply - 200mAOrLess = PlentyLeftOverForArdunioUnlessMyBatteriesAreNearlyDead

But there's still that voltage thing I'm not sure about.  What the tutorial said about not being able to regulate voltage if you're regulating current.  Does me no good to have 200mA at 1v.

Another thought I just had, was... what about switching voltage regulators?  Those can take 1v and upconvert it to 5v, right?  At the cost of current I presume?  Does such a thing as a switching current regulator exist?  Trading voltage for current when needed?   Not really sure if that would even be useful here... just a thought.
1138  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 25, 2010, 07:03:37 pm
The wires on the battery pack are 26 AWG.  I'm pretty sure all the jumpers I'm using are as well.  As far as I know that's good enough for 2A.

I don't disagree with anyone that I may not have enough current.  That certainly seems to be the case.  But I'm limited by several factors, including the size of the prop, and the cost.  I can't use any sort of rechargable battery that could supply large amounts of current for example because they're too expensive, they'd require the end user to have a charger, and I can't ensure people won't stick alkalines in there and then complain about poor performance.

So I need to find some other solution.  If that means I need a more expensive voltage regulator, or I need to reduce the speed of the servos somewhat, than that's what I need to do.

There is still a small possiblity I can fit more batteries inside the prop than what I'm trying to run my circuit off now, but as I don't have the prop in hand yet to take measurements, I can't assume I'll be able to do that, and I need to look for alternative solutions.

If I was troubleshooting your problem I would use my o-scope and monitor the voltages as the the board was running to watch what the voltage levels were actually doing.

I don't have an oscilliscope, and can't afford one at the moment.

I was wondering the other day if it wouldn't be possible to construct a crude one with another Arduino though.  I mean the main function of an oscilliscope is to plot voltage over time, right?  And the Arduino can read voltages with 10-bit accuracy, can it not?  

Hm.  It appears it can.  And it appears someone has done this:

And someone else did it better:

Perhaps I'll upload that onto one of the spare Arduinos I have.

As a quick test why don't you try a much larger battery just to see if that solves the problem.

Don't have any AA's or a battery pack for them at the moment.  But I'll try that when I get a chance.
1139  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 25, 2010, 06:20:40 pm
So nobody has any other suggestions?

Here's a few ideas I've been thinking about:

1) Add resistors to the servo power lines.  This will force less current to flow, but may slow the servo down and reduce its torque.  By how much, I don't know.  I suppose that depends on the size of the load, which in my case won't be very large.  I shouldn't need a very large resistor to get significant results.  

2) If the problem is my batteries can't supply enough current, then what if I wired them in parallel?  I read a post once by GrumpyMike which said it was bad to wire batteries in parallel because one pack might drain into the other, but I think that he meant without any supporting circuitry.  If I use a couple of those Schottky diodes with the low voltage drop, then I think I can wire the packs together safely.  Space is still an issue, but if it turns out that 4.5v is enough to power everything however, but I have space for six AAA batteries, then perhaps it would be better to go with two 4.5v in parallel instead.

3) Go with two seperate power sources.  This has been suggested many times in oither threads to avoid issues with noise, and it would certainly work to solve the problem of the servos drawing too much current away from the rest of  the circuit.  I don't really want to do this though, and I don't know if I have the space to.  And I honestly can't believe that AAA batteries can't put out enough juice to power a couple submicro servos which don't even have a load on them.  I've seen sites showing that AA's can put out at least 2A, and 9V can put out 1A.  And with a 9v having AAAA size cells in it, it seems like the AAA ought to be right there in the middle.

4) Add an inductor like GrumpyMike has in his motor tutorials?  I'm not really sure this would actually do anything.  I mean, insofar as poweing the rest of the circuit when the servos activate.  I think the inductor is just there to suck up excess power when a motor shuts down.  So it probably wouldn't help when one starts.

5) Capacitors.  I've tried decoupling capacitors up to 100nF, and they haven't done squat.  I would have thought they would provide the extra juice needed when supplies ran low as the servos activated, but my understanding of how capacitors work isn't really that great.  Maybe they don't assist in current dips, only voltage dips.  I don't know.  But I don't know that I would have room to use anyhting much larger than a 100uF capacitor on my board.  The 470uF's they had at radio shack were pretty freakin' huge.
1140  Forum 2005-2010 (read only) / Interfacing / Re: Provide more current to servos when they need it? on: June 25, 2010, 05:37:31 pm
Servos can draw a good bit of power when they start or are under load. What you posted indicates you just assumed the power requirements for the servos and never actually measured their current draw, especially the starting current.

The reason I haven't measured the current is twofold:

1) I don't have a multimeter capable of measuring more than 200mA.  As the servos would likely draw much more than that, hooking them up to the meter would just blow the fuse.
2) Measuring the current draw of my servos wouldn't provide me with particularly useful information because I can't count on these same servos being used with the final circuit.  I have to design the circuit with all sub-micro servos in mind.  And the best way to do that which is within my budget is to find someone who's tested lots of different servos to see how much current they draw at peak usage.

Like this fellow for example:

The LEDs dim and the board/servos may have performance issues because you are not able to supply adequate current when the servos start. Your regulator/battery setup is inadequate for the job.
A standard 9v battery is not made for powering servo motors and you are just waisting your $$$ trying to do so. Kind of like trying to start your car using flashlight batterys

If that's true then why does the circuit run fine off a 9v, but poorly off of six AAAs?  Aren't AAAs capable of supplying way more current than a 9v battery?

I have yet to find a good source of information on the web on how much different types of batteries can source, but it looks like a AA might be good for 700mA to 2A, and a 9V might be good up to 1A.  AAAs would obviously source less than a AA, but as far as I know, a  9v simply contains a bunch of AAAAs, and as such should supply less current than a AAA can.

I'm not saying you're wrong about the current it can supply.  I mean it sure seems like it's getting drained fast.  And I know the maH rating is far lower than the AAAs.  But SOMETHING was going on in my circuit to cause the 9v to light everyhting properly and t make the servos run at higher speed.  And something is causing the AAAs to fail at supplying enough current to keep the LEDs lit uniformly.  Simply stating that the batteries csan't supply the current needed doesn't explain these things.

Noise is not your issue, being under powered is

I know that.  I didn't title the thread "How do I provide more current to servos when they need it?" for nothing. :-)

(see if you recognize your battery holder in the below link)

That fellow is trying to power 12 servos.  I'm trying to power two.  

I've provide potential success paths, but they just seem to be questioned or ignored. It is like Rippley's "Believe it or Not" musem at the beach, you can believe it..., or not.

I'm questioning your suggestions because you're not providing enough information.  

Telling me to stick a capacitor and a diode on there is of no help if I don't know how to wire them up, or how they're supposed to fix my problem.  Do you expect me to order a couple diodes with a low voltage drop from Mouser, pay $5 for shipping, wait three days for them to arrive, stick them in my circuit, and hope they work, with no understanding of why they're supposed to work, and no guarantee that they will work?

Here's the first suggestion you offered:

You told me I should wire my circut up like this, but you gave no explanation for what any of these diodes were supposed to do.

Then pwillard had this to say:
You REALLY REALLY want to ISOLATE the Servo Supply from the rest of the circuit.  Your current solution will still let the servo loading and spiking to impact the stability of the pseudo 5V source you now have relying on voltage drop on diodes.

Which apparently was a comment on the circuit you posted.

So you're telling me to do one thing, and he's telling me that's bad.  And nobody else has any comment on the matter.  And I don't have a clue.  And you're not offering any explanation for how your circuit is supposed to work.  

And you're surprised that I question this?

The next suggestion you offered was:
Power the rest of the circuit thru a low voltage drop (.1v) diode, and use a high value capacitor down stream of the diode to minimize the voltage disturbance to the circuit.

The problem with that is:

1) As far as I can tell, no such diode exists.  Even those Schottky diodes you've suggested only seem to go down to 0.3v.

2) There's still that thing that pwillard said about it being bad to power your circuit through diodes which concerns me.

3) You never did answer what you meant by a "high value capacitor".  Is 47uF high value?  Is 100uF?  220uf?  470uF?

4) Your explanation for how to wire the circuit is unclear.  "Stick a capacitor downstream" is meaningless to me.  

Do you want me to do this?

Regulator output -> Servo ->
  • Diode[-] ->
  • Capacitor[-]- -> Arduino

I don't know how that would work.  If I understand capacitors correctly, the capacitor would pull down on the Ardunio's voltage line as the capacitor charges, assuming there's some route to ground.  Then once the capacitor is fully charged, current would simply stop flowing.  The Arduino would never power up.

Or do you want me to do this?

Regulator output -> Servo ->
  • Diode[-] ->
  • Capacitor -> Arduino Vcc
Capacitor[-] -> Ground

That would function I guess, but how is it a solution to my problem?  how is that different from any other bypass capacitor, of which I have tried several?  What does the diode do that makes it different?

Does the diode allow the capacitor to charge, but prevent it from discharging back into the servos perhaps?  

5) You said doing this will minimize the voltage disturbance to the circuit.  But you just said the problem with my circuit was not noise, but being under powered because the batteries can't supply enough current.

So how is a solution designed to minimize voltage disturbance, which I read as "minimize noise", going to solve my problem of not having enough current?
Pages: 1 ... 74 75 [76] 77 78 ... 91