programme compilé dans mikcroc for avr
Répondre à la discussion
Affichage des résultats 1 à 2 sur 2

programme compilé dans mikcroc for avr



  1. #1
    invite32cc11f3

    programme compilé dans mikcroc for avr


    ------

    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,

    -----

  2. #2
    mat64

    Re : programme compilé dans mikcroc for avr

    ta fonction get_sample() appelle 4 fois adc_read(). Comme elle ne fait pas grand chose d'autre, c'est vraisemblablement adc_read() qui bloque. Il te reste à comprendre pourquoi.

Discussions similaires

  1. programme AVR STUDIO
    Par inviteb7a0f269 dans le forum Électronique
    Réponses: 10
    Dernier message: 15/05/2014, 20h23
  2. 2 Jupiters + M31 compile du WE
    Par astro31 dans le forum Matériel astronomique et photos d'amateurs
    Réponses: 5
    Dernier message: 29/09/2009, 02h38
  3. CodeBlocks ne compile pas..
    Par invite92f9622f dans le forum Logiciel - Software - Open Source
    Réponses: 9
    Dernier message: 18/12/2008, 12h26
  4. pourquoi mon programme ne compile pas?
    Par inviteb5f895f5 dans le forum Logiciel - Software - Open Source
    Réponses: 1
    Dernier message: 17/11/2008, 09h34
  5. Fusible dans AVR studio 4
    Par invited60b6f1f dans le forum Électronique
    Réponses: 0
    Dernier message: 19/11/2007, 09h17
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...