Lee Barker wrote: > I'm trying to use the Analog Devices ADXL202E with a PIC16F877 running at > 20 MHz. I'm writing the code in CCS PIC C PCW Compiler version 3.068. I'm > trying to use the PIC to measure the PWM signal coming out of the > accelerometer. I was trying to use the PWM capture port on the PIC but > didn't fully understand the data being returned and I also didn't want to > be limited on using a PIC with a capture port. I would like to use one of > the small 8 pin PICs eventually. I looked into your code, because I have worked with ADXL products before and I was curious. Your approach seems overly complex for what you're trying to accomplish -- for example, using interrupts to measure time while the mainline code is doing essentially nothing. You're also lucky Olin doesn't do C on PICs, because he'd be all over you about your terrible source code formatting and comments. I'll try to be a little more gentle. First of all, you *must* use a fixed-pitch font for source code, especially if you're going to put ASCII-art diagrams into the comments. But your biggest problem you have is that the comments and function names are hopelessly out of sync with what the code actually does. By not keeping things up to date, you've thoroughly confused yourself. For example, you use an empty while() loop in several places to wait for an input to change state. Can you see what's wrong with the following comments? while (input(PIN_C1)==1) {;} //wait for the pulse to go low while (input(PIN_C1)==0) {;} //wait again for the pulse to go low The reason your code doesn't work is that the functions Measure_time_td() and Measure_time_te() are missing the initial wait loop. They just have a simple conditional, which means that they sometimes return without making any measurement at all. I'm sure that if you apply a little discipline to your coding, you'll be able to solve your problems in short order. -- Dave Tweed -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body