Gas station without pumps

2015 July 12

Differential ADC not working in ATMega32u4

Filed under: Data acquisition — gasstationwithoutpumps @ 08:56
Tags: , , , ,

I spent considerable time last night trying to get the differential ADC inputs working on my Arduino Leonardo board, and finally gave up.  Here is what I found:

  • It was easy to set up the MUX to get differential inputs to do something—I wasn’t having trouble selecting the appropriate pairs of pins.
  • The signal was much smaller than expected.  I expected a 2-fold reduction in signal, as the range for the 10-bit conversion goes from [0,+5V) to [–5V, +5V], but what I saw was an 8-fold reduction in the signal.
  • Despite clear descriptions in the manual of how the differential inputs are supposed to work, the 8-bit output of the differential ADC is not aligned with the the MSB in the same place as the 10-bit single-ended DAC.  This further means that setting the ADLAR bit to get left-alignment of the outputs does not left align the signal, but leaves it a factor of 4 short of that goal.  With the gain set to 10, there seemed to be one bit less, and so the signal seemed to have not a gain of 10, but of 10/16, rather defeating the point of having an amplifier.
  • The signal was far noisier than just reading the two channels separately and subtracting in software.  Setting the gain to 10 seemed to amplify the noise more than the signal.
  • When using the paired inputs with a gain of 10, I saw random negations of the signal, flipping its sign a few times per second, not correlated with the input signal.
  • I tried looking at the signal both with ADLAR set and without, and ADLAR seemed to be just doing a left-shift of 6 bits, as the documentation claims—the problems are in the alignment of the ADC output before shifting.

I read the documentation for the 32U4 differential ADC several times, and finally concluded that the chip I had was not behaving at all according to the specs (which themselves had several typos—Atmel writes some of the worst-checked documentation I’ve seen from a major manufacturer).

It is possible that the chip I have has been subtly fried (though the single-ended ADC seems to work fine), but I can’t find much evidence on the web that anyone uses the 32U4 with the differential inputs, particularly not with the output left-aligned.  If anyone has a Leonardo Arduino board (or other ATMega32U4-based board), I’d be interested in hearing whether you can get the differential ADC inputs on the board to work properly.  If you do get differential inputs to work properly, please send me some information about how you did it, because I’m frustrated.  Perhaps I’m missing some crucial tidbit of information that would make everything make sense.

In the meantime, I’m regarding the differential ADC channels of the 32U4 as an unimplemented marketing lie, and not going to try to use them in PteroDAQ (which wastes a couple of days work on refactoring the code to make it easier to handle boards with different gain on different differential channels).  At least the code still works with the KL25Z differential channels, which seem more limited than the 32U4 ones (only 2 pairs and both have gain of 0.5), but which actually work as documented.

2013 January 3

Plumbing karma

Filed under: Uncategorized — gasstationwithoutpumps @ 18:42
Tags: , , , , ,

A couple of days ago in Is coding for everyone?, I wrote

Atwood makes an analogy to everyone learning to do plumbing, as if that were a ridiculous idea.  Personally, I think that everyone should learn a little plumbing: enough to clear a toilet or sink trap, or replace a faucet washer, and to know when to call in a professional plumber.

So, naturally, yesterday the kitchen faucet started dripping for the first time in about 15 years.  I figured I knew how to change a faucet washer, and that it would just take a few minutes today. Ha!

The first problem was that the faucet had not been opened up in so long that the threads had seized, so it took two people to get it apart: one under the sink holding onto the valve body with channel-lock pliers, the other using a lot of leverage with an 8″ adjustable wrench.  Even that wasn’t enough, so I had to go down to the hardware store for some penetrating oil and let it soak in for a while.

The Grohe faucet cartridge from the kitchen faucet.

The Grohe faucet cartridge from the kitchen faucet.

Eventually, the threads eased up and the the faucet came apart.  But there was no washer to replace.  Instead what I had was a Grohe washerless faucet cartridge.  The Grohe cartridges are pretty good (which is why I hadn’t had to do anything with the kitchen faucet in so long), but when they fail, there’s not much you can do but replace the cartridge.

I tried smearing everything with vaseline and replacing the cartridge, just in case the problem was with the rubber gaskets, but the drip continued as before.

Unfortunately, the local hardware store does not carry Grohe parts (too upscale for Ace Hardware), so I had to bicycle 3.7 miles across town to Bay Plumbing, the closest place I could find that stocked the part.  I was pleased that their prices were essentially the same as I would have paid online (cheaper than some of the online places), and I could get the part immediately, rather than waiting 3–5 business days for delivery.

I was not so pleased that Bay Plumbing had no bike parking, so I told them about the Santa Cruz County Regional Transportation Commission bike parking program.   Unfortunately, I found out when I got home that SCCRTC no longer has the Bike Secure parking program.  That’s a shame, because there are still a lot of businesses that need bike parking!

In other news, the Arduino Leonardo that I had ordered arrived today. I ordered the Leonardo to test whether the data logger code worked with the Leonardo’s different way of handling the serial interface and different pin mapping.  But I goofed—despite my admonitions to the students in the circuits class to make sure that they got the right USB cable to go with the Arduino board they bought, I had not checked to see if we had a micro-B USB cable in the house.  We had so many USB cables sitting around, that I was sure one of them was a micro-B.  It turns out that they were all either B or mini-B, not micro B, so we were unable to test the data logger code on the Leonardo until I got a new cable.  (Actually, we had one micro-B cable, but it was a power-only cable for recharging my son’s bicycle headlight.)

I ordered a couple of the cables online earlier in the day, but they won’t come until next week, so after buying the faucet cartridge at Bay Plumbing, I stopped in next door at Santa Cruz Electronics to pick up a cable. Unlike Bay Plumbing, their prices were about three times what the online price would have been, so the only reason to buy there was to get the cable immediately. I’ll report on the status of the data logger software later, when I get an update from my son on the code he’s been adding today and when we’ve had a chance to test the Leonardo.

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 315 other followers

%d bloggers like this: