??? 01/28/05 14:21 Read: times |
#86022 - Do some simple tests first Responding to: ???'s previous message |
GK, since you know the pulse widths involved, try only measuring either the high or low width and compare your measurements with the cro. Then try the other, then try both. I'm sure you will stumble across the problem.
If you want to try the PCA, here is some example code in 'C' that should translate into assembler quite easily. [pre] // // init the PCA for capture on 3 & 4 // #define CAP_POS 0x21 #define CAP_NEG 0x11 CMOD = 0x00; // /6 clock CCAPM3 = CAP_POS; CCAPM4 = CAP_POS; CR = 1; .....more init code....... void task0(void) { unsigned int duty,period; unsigned long l; static int xoffset = 0,yoffset = 0,a,b,xact,yact; float angle,mag; EC = 0; duty = x_duty; period = x_period; EC = 1; l = duty * 800L; //12.5% = 1G. we want result in milliG l = l / (unsigned long)period; //result width/period * 2000 b = l; EC = 0; duty = y_duty; period = y_period; EC = 1; l = duty * 800L; //12.5% = 1G. we want result in milliG l = l / (unsigned long)period; //result width/period * 2000 a = l; xact = b - xoffset; yact = a - yoffset; l = (xact * xact) + (yact * yact); //calculate hypotenuse by plato's theorem mag=sqrt(l); //mag = magnitude // printf("Testing 123rn"); sprintf(&lcd_in[40],"%d ",yact); // sprintf(&lcd_in[60],"%d,%d",y_period,y_duty); sprintf(&lcd_in[60],"%d ",xact); sprintf(&lcd_in[20],"%d %d ",xoffset,yoffset); angle = atan2f(yact,xact); sprintf(&lcd_in[00],"%.3f ",angle * 57.29577951); sprintf(&lcd_in[10],"%.3f ",(mag * 9.8)/27.77778); // // any key pressed = ZERO // if (got_key()) { xoffset = b; yoffset = a; } task_timers[0] = 100; reset_task(0); } void CCA_int(void) interrupt 6 { // // the ADXL02 gives us a fixed period with variable duty cycle // the determine the measured 'G' force. // The rising edges are fixed // The falling edge is variable // static char ystate = 0,xstate = 0; static unsigned int yprev = 0,ycurr = 0,yduty = 0; static unsigned int xprev = 0,xcurr = 0,xduty = 0; if (CCF3) { temp++; if (ystate == 0) //expect a fixed rising edge { ycurr = CCAP3L; ycurr +=(CCAP3H<<8); y_period = ycurr - yprev; y_duty = yduty - yprev; yprev = ycurr; ystate = 1; CCAPM3 = CAP_NEG; CCF3 = 0; } else //expect a falling edge { yduty = CCAP3L; yduty |= (CCAP3H<<8); ystate = 0; CCAPM3 = CAP_POS; CCF3 = 0; } } if (CCF4) { if (xstate == 0) //expect a fixed rising edge { xcurr = CCAP4L; xcurr +=(CCAP4H<<8); x_period = xcurr - xprev; x_duty = xduty - xprev; xprev = xcurr; xstate = 1; CCAPM4 = CAP_NEG; CCF4 = 0; } else //expect a falling edge { xduty = CCAP4L; xduty |= (CCAP4H<<8); xstate = 0; CCAPM4 = CAP_POS; CCF4 = 0; } } } [/pre] Obviously there's some trigonometry in this calculation that doesn't apply to your app. For everyone else - here's some sample code to read an Analog Devices ADXL02 dual accelerometer! |