Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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!




List of 30 messages in thread
TopicAuthorDate
help with duty cycle measurement            01/01/70 00:00      
   woefully incomplete            01/01/70 00:00      
      Definitions            01/01/70 00:00      
         gobbelygook            01/01/70 00:00      
   Routines            01/01/70 00:00      
   sorry for the gobbelygook            01/01/70 00:00      
      A job for the PCA?            01/01/70 00:00      
      now that is clear            01/01/70 00:00      
      4 errors found in your smt_1.asm pgm            01/01/70 00:00      
         maybe only 3            01/01/70 00:00      
   cannot change            01/01/70 00:00      
   SMT160 example code in C            01/01/70 00:00      
      why            01/01/70 00:00      
         It is absolute necessary !            01/01/70 00:00      
            on the fly            01/01/70 00:00      
               Thus I use assembler !            01/01/70 00:00      
                  not assembler but int            01/01/70 00:00      
                     It must be XCH !            01/01/70 00:00      
                        still wrong to read with running            01/01/70 00:00      
                           not wrong, since it is tested !            01/01/70 00:00      
                              OK            01/01/70 00:00      
            Thanks to all            01/01/70 00:00      
   Thanks Peter            01/01/70 00:00      
      Do some simple tests first            01/01/70 00:00      
         Problem solved But            01/01/70 00:00      
   Modified code and mistakes            01/01/70 00:00      
   smt160.asm example            01/01/70 00:00      
      Thanks for example            01/01/70 00:00      
   Please explain            01/01/70 00:00      
      Yes            01/01/70 00:00      

Back to Subject List