|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Working with ADXL |
Posted: Sun Feb 26, 2006 1:08 am |
|
|
Hi
I'm trying to work with an ADXL202 accelerometer using a PIC16F873A. Having no previous experience with the PICs, I'm having quite a bit of troubles and would appreciate any help I can get from gurus out there.
First thing first, I'm trying to get the PIC to read the PWM output from the ADXL to measure the tilt of the sensor. (As far as I understand, the ADXL outputs PWM with varying duty cycles based on the tilt of the sensor)
I've already read few topics that seem to deal with similar applications, but the information I've found on them were rather vague or somewhat overwhelming. If anyone out there can give me some advice as to how to go about it, it would help me out very much. At least something to get me started on the right track would be much appreciated. |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Sun Feb 26, 2006 7:33 am |
|
|
To get you started:
You will want to use one of the Capyure/Compare modules to measure the PWM ouput of the ADXL. You will also need to set up timer1, as it is the timebase to this module.
So:
1) Use the setup_timer_1 command to set timer1 to run off the internal oscillator, and set its frequency such that it will give you your desired measurement resolution for the input PWM signal.
2) use the setup_ccp1 command to setup for capture of a rising edge.
3) set the CCP1 capture interrupt bit to 0.
4) wait until the CCP1 interrupt bit is not 0.
5) use the set_timer1 command to zero the timer. Now you've zeroed the timer at the input rising edge.
6) set the cCP1 module to sample a falling edge and reset the CCP1 interrupt bit to zero.
7) wait until the CCP1 interrupt is not zero.
8) use the get_timer1 command to get the timer value. This value is the number of timer clock periods between the rising edge and falling edge of the ADXL output.
9) Now you've got to do some processing to turn that into an acceleration and voila, you're done. The ADXL datasheet will give you a transfer function between the PWM output and the acceleration being measured.
In order to do this properly, you will have to also measure and store the ADXL output when its acceleration is zero (i.e. some initial calibration routine), as the PWM output varies with temp, etc.
I hope this is helpful.
r.b. _________________ The difference between genius and stupidity is that genius has its limits... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|