ADXL202JE Help Needed

Hi,

I have an ADXL202JE accelerometer from Analog Devices in my hands right now and I'm trying to figure out exactly how it works. I have it connected to a Basic Stamp II as follows:

I have four leads coming off the ADXL connected to my Stamp.

ADXL STAMP

+5 Vdd (+5V DC)

COM Vss (Gnd)

Xout Pin 4

Yout Pin 5

I'm using this code:

'{$STAMP BS2}

FREQ VAR WORD

T1x VAR WORD

T1y VAR WORD

T2 VAR WORD

LOW 7

HIGH 3

INPUT 4

INPUT 5

COUNT 8,500, FREQ (Not sure what this is for...)

T2=25000/(FREQ/20)

T1_LOOP:

PULSIN 5,1,T1x

T1y = 2 * T1x

PULSIN 4,1,T1y

T1x = 2 * T1y

DEBUG "FREQ: ",DEC FREQ, " ", "T1x: ", DEC T1x, " ", "T1y: ", DEC T1y, CR

GOTO T1_LOOP

I'm not sure where T2 comes into play. I know that X and Yout are giving me the Pulse Width Duty Cycle, so I need to know T2 in order to determine the Width of T1x or T1y with respect to T2. But how do I determine T2?

Right now when I run this code I get lots of zeros, but not much else. If I shake the ADXL quite hard I can get the numbers to change - but I must be doing something wrong. I know that the ADXL is more sensitive than this!!

If anyone has interfaced with the ADXL could you please lend me a hand!!!

My end goal is to build a balancing bot - If I can get the accelerometer to work!

Kelly

Reply to
Kelly Tobias
Loading thread data ...

Kelly -

IF I remember some old Stamp commands correctly, the "COUNT" command is counting the number of cycles of the signal on pin 8 in 500 msec, and storing it in the variable "FREQ." Then, the "FREQ" value is used to compute "T2;" maybe this is a conversion to seconds or something like that. You need to divide T1x and T1y by T2 to get the duty cycle, assuming these three variables are all in the same units.

Make sure you aren't using an accelerometer with analog outputs, and change the pin designation in the COUNT command to either 4 or 5, as this seems to be the inputs that are connected to the ADXL. I think 8 is wrong here. Doesn't matter if you use pin 4 or 5 to compute the FREQ, as they duty cycle for x and y axes are the same...

HTH, Bill

Reply to
Bill Turnip

I can see that the code you have comes from Analog Devices application note AN-596 which is available at:

That application note explains in very good detail how to hook the device to a basic stamp I or II and how to read and interpret the values.

Maybe you didn't get the code from that application note, and reading it would make your interface work properly.

Reply to
Alan Kilian

Go the the library and check out the second edition of my book, Robot Builder's Bonanza. See Chapter 41. It has a better example of hooking the ADXL202 to a Basic Stamp, and fixes some problems in the original app note (it is based on that app note). My version assumes you are using the evaluation board, and the pin-to-pin wiring I show is based on just plugging the eval board into the header of a BOE board (or a BS2 carrier board).

You likely will have a hard time creating a balancing robot just with an accelerometer. Most folks are also using a gyro. Analog makes one of those, too, but it uses a ball grid array connection, very difficult to solder. The eval board, with the gyro chip already attached, is recommended. They don't sample it out for free, however.

You should not expect a value of zero if the circuit is connected properly. The ADXL202 is always registering the DC-bias of earth's gravity (unless you're in space...you're not in space, are you?).

-- Gordon Robots for Less at Budget Robotics:

formatting link
Robot Builder's Sourcebook & Robot Builder's Bonanza

Kelly Tobias wrote:

Reply to
Gordon McComb

I tried this anyway just to see if it is possible and have some suggestions for anyone else trying it. I used a PIC16F628 and multiplexed the 2 accelerometer channels into its capture/compare pin. I used its USART to output the data to a computer so I could see what the PIC is measuring. PIC was 20MHz crystal (5MHz counter rate) with T2 ~ 1ms. I think longer T2 would be better for higher resolution, this gave about 2500 counts at 0g, +- about

600 counts at +/- 1g. I saved the data and graph if you want to see what sort of noise I had:
formatting link
Using a single channel perpendicular to gravity gives a signed linear approximation for angle (for about +/- 30 degrees) so I first tried using that. It works quite well for proportional control, but the signal is much too noisy to get a proper derivative due to the thing wobbling around trying to balance (causing extra acceleration). The other channel, in the same direction as gravity has a nonlinear relationship to angle and small magnitude, so noise makes it nearly unusable. My suggestion is to use both channels at 45 degrees to gravity with their positive directions up. This way both channels will be linearish for small angles and extra horizontal acceleration will be positive for one channel and negative for the other. If you average them the result should be (more) independent of the horizontal acceleration.

- Daniel

Reply to
Daniel Watman

Thanks for the help.

I do plan on using a gyro as well. I was looking at the PG-03 from GWS (helicopter gyro).

I think I may have baked the ADXL when I soldered on the leads... I managed to get it pretty hot. I think I may invest in the ADXL202EB Evaluation board.

I'm using the ADXL202JE 8 pin LCC... As I stated I only have 4 pins connected to my stamp. Do I need to connect Rset to a resistor?

Kelly

Reply to
Kelly Tobias

Yeah, they're very handy. Be careful of where you buy. Folks charge from $40 to over $80. Newark tends to be cheapest, but also try the others listed on the Analog site.

You only need two, X and Y, plus ground. Where you get the +5 is up to you, but if you want to power the ADXL from the stamp, you can do that. This doesn't mean you don't need to connect the other pins opf the ADXL to the Rset resistor and the filter/bandwith capacitors, as noted in the datasheet. These are not connected to the Stamp, and it's assumed you've wired those up as needed.

Parallax also offers a nice PCB for the Memsic (lower-cost spinoff from Analog). It's pretty cheap ($25), and if you're new to electronics, will save you some time and frustration. The Memsic 2125 works like the ADXL202.

-- Gordon Robots for Less at Budget Robotics:

formatting link
Robot Builder's Sourcebook & Robot Builder's Bonanza

Reply to
Gordon McComb

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.