Salut,
voila mon programme:
#include <built_in.h>
// LCD module connections
sbit LCD_RS at PORTD.B2;
sbit LCD_EN at PORTD.B3;
sbit LCD_D4 at PORTD.B4;
sbit LCD_D5 at PORTD.B5;
sbit LCD_D6 at PORTD.B6;
sbit LCD_D7 at PORTD.B7;
sbit LCD_RS_Direction at DDRD.B2;
sbit LCD_EN_Direction at DDRD.B3;
sbit LCD_D4_Direction at DDRD.B4;
sbit LCD_D5_Direction at DDRD.B5;
sbit LCD_D6_Direction at DDRD.B6;
sbit LCD_D7_Direction at DDRD.B7;
// End LCD module connections
char tab1[5];
char stepflag;
float stride, avgstride, accel_dat[50];
float maxavg, minavg, accel_avg, velocity, displace;
float distance;
int steps;
void get_sample(unsigned int *xdat, unsigned int *ydat, unsigned int *zdat);
char IsStep(float avg, float oldavg);
char flag;
unsigned int xdat;
int i, cycle_count, tot_samples, avgconst = 1, latency = 4, avglen = 8;
float rssdat, newmax, newmin, oldavg, newavg, avgthresh=1.0;
float walkfudge = 0.0249;
void get_sample(void)
{
xdat=0;
for(i=1;i <5;i++)
xdat=xdat+adc_read(2);
}
char IsStep(float avg, float oldavg)
{
// this function attempts to determine when a step is complete
float seuil;
float step_thresh = 1.0; // used to prevent noise from fooling the algorithm
if (stepflag == 2)
{
if (avg > (oldavg + step_thresh))
stepflag = 1;
if (avg < (oldavg - step_thresh))
stepflag = 0;
return (0);
} // first time through this function
if (stepflag == 1)
{
if (maxavg - minavg > seuil )
return (1);
if (avg < (oldavg - step_thresh))
{
stepflag = 0;
if (oldavg > maxavg)
maxavg = oldavg;
} // slope has turned down
return (0);
} // slope has been up
if (stepflag == 0)
{
if (avg > (oldavg + step_thresh))
{
stepflag = 1;
if (oldavg < minavg)
minavg = oldavg;
} // slope has turned up
return (0);
} // slope has been down
return (0);
} // IsStep()
// Function Prototype & variables
// functions
void main()
{
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
flag = 0;
DDRC =0xFF;
stepflag = 2;
maxavg = -10000.0;
minavg = 10000.0;
newmax = -10000.0;
newmin = 10000.0;
oldavg = 0.0;
newavg = 0.0;
cycle_count = 0;
tot_samples = 0;
steps = 0;
distance = 0.0;
accel_avg = 0.0;
velocity = 0.0;
displace = 0.0;
avgstride = 0.0;
PORTC0_bit=0;
flag = 1;
ADCSRA=0xE0;
SFIOR=0x00;
ADMUX=0xE2;
while (1) {
if (tot_samples > 7) // subtract first sample in sliding boxcar avg
{
oldavg = newavg;
newavg -= accel_dat[cycle_count - avglen];
} // if
get_sample(); // get data from accelerometer
rssdat = sqrt((float)(xdat/4)); // vector sum
accel_dat[cycle_count] = rssdat; // place current sample data in buffer
newavg += rssdat; // add new sample to sliding boxcar avg
if((abs(newavg-oldavg)) < avgthresh)
newavg = oldavg;
if (rssdat > newmax)
newmax = rssdat;
if (rssdat < newmin)
newmin = rssdat;
tot_samples++;
cycle_count++; // increment count of samples in current step
if (tot_samples > 8)
{
if (IsStep(newavg, oldavg))
{
steps++;
PORTC0_bit=~PORTC0_bit;
inttostr(steps,tab1);
lcd_out(1,1,tab1);
} // we have a new step
} // enough samples to start checking for step (need at least 8)
} // if timeout // continual loop
get_sample();
delay_ms(30);
}
quand je déroule ce programme il se bloque dans la fonction get_sample comment faire?
un grand Merci,
-----