Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing Memsic MXD2125 accelerometer to PIC18F2620

Status
Not open for further replies.

texasdeathstyle

Newbie level 5
Joined
Nov 22, 2010
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,347
I am trying to read the analog outputs from a dual-axis accelerometer. These outputs are fed to the RA0/AN0 and RA1/AN1 pins of the PIC. So I need to set up the ADC of the pic in order to interpret these values. I have done coding for the program but I find that even when the accelerometer is on a level plane, the output values after conversion are not consistent. They seem to be constantly changing which shouldn't happen in the first place if the accelerometer is not tilted. Is my ADC setup correct ? My oscillation freq is 4Mhz.


Code:
void Output(void){

		OpenADC(ADC_LEFT_JUST & ADC_FOSC_8 & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ,13);
		Delay10TCYx( 5 ); // Delay for 50TCY
//		SetChanADC(ADC_CH0);
		Delay10TCYx(100);
		ConvertADC();
		while(BusyADC());
		Y_AN0 = ADRESH;

		SetChanADC(ADC_CH1);
		Delay10TCYx(100);
		ConvertADC();
		while(BusyADC());
		X_AN1= ADRESH;
		CloseADC();
		Serial_out();						// Serial out   to  computer
		
}
 

Hi!

Is it possible to post a schematic of your circuit? How do you connect the accelerometer to the PIC? I have read the datasheet of your accelerometer and seen that its outputs are two digital PWM duty cycle outputs, not analogue! In that way, it is wrong to connect them to the ADC of the PIC! They are already digital. All you have to do is measure the duty cycle of the signals and convert it to acceleration. This is probably the reason why you see them to change constantly, because this is what they normally do! They are pulses!

Nick
 

Hi Nick,

The accelerometer's two digital outputs go through a RC filter to convert them to analog before being fed to the ADC of the PIC. I could just measure the duty cycle of the pulse signals and convert them but I have other uses for the timers/counters in the PIC which was why the hardware was fabricated to use the the ADC of the PIC instead.

Mark.
 

Hi Mark,

thanks for this clarification and sorry for my guess. I thought that you haven't put this RC filter at the accelerometer's output.. So, are you sure that it is a problem of your software? What values do you measure, that make you say that the output of the accelerometer is constantly changing? Is the supply voltage of the accelerometer constantly on? Or you have used power cycling? One simple test you can do is measure the value of the accelerometer's output after the RC filter with a volt-meter and be sure that what you read with the ADC is the same with what the accelerometer really outputs. And in this way, you'll be sure where the problem exists, at the hardware or at the software.

Nick
 

Hi Nick,
Well for now. the accelerometer is on a level plane. No tilt or whatsoever. Every time I run through the program, I get different values. For example, on the first run. I got

X_AN1 = 0x86
Y_AN0 = 0x84

On the second run

X_AN1= 0x80
y_AN0 = 0x7E

Third run

X_AN1 = 0x76
Y_AN0 = 0x75

I have to use the values of X_AN1 and Y_AN0 on various tilt angles to compute a formula. But I can't compute the values when X_AN1 and Y_AN0 are pretty inconsistent even a level plane. The accelerometer supply voltage is constantly on. Is this normal though ?
 

I'd suggest you to increase the acquisition time of your A/D conversion. The reason of these fluctuations that you see at the measured quantities may be that your acquisition time is too short and thus the sample/hold capacitance of the ADC device of your uC is not fully charged with the output value of the accelerometer, when the conversion starts. Read carefully pages 227-229 of the uC's datasheet. Also have in mind that the RC filter that you have put at the accelerometer's output also influence the required acquisition time.

Try to use a longer acquisition time and see what's happening. Hope that helps!

Regardless of this, personally, I would measure the output of the accelerometer after the RC network with a volt-meter, so as to know what value to wait from the ADC.

--
Nick
 
Last edited:
Hi Nick,

I did measure the output of the accelerometer after the RC network as you mentioned and found that there was actually quite a couple of hardware problems on the board itself. First I increased the capacitance value of the RC filter from 1uf to 10uf. The new value actually minimised the fluctuations alot to give a more consistent read. And I also noticed that the one of the output axis connections had contact problems. That was fixed up with a touchup of the soldering. The program works fine now. Thank you so much for you help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top