Needs help for Interrupt


may know there limit space or time isr run?
my code below:
code: [select]

// arduino timer ctc interrupt example
// www.engblaze.com

// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <wire.h>
#include <virtualwire.h>
#include <softi2c.h>
#include <ds3232rtc.h>

softi2c i2c(a4, a5);
ds3232rtc rtc(i2c);


#define ledpin 13
  // must download , install virtualwire.h hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round



int seconds = 0;
int j = 0;
int storage [100];
int yea [100];
int mont [100];
int da [100];
int hou [100];
int minu [100];
int secon [100]  ;

int tempvoltage;
int tempyea;
int tempmont;
int tempda;
int temphou;
int tempminu;
int tempsecon;
int k = 0;
char verify[2];
int precision1;
int precision2;
int precision3;
int mult;
float charf1;

void setup()
{
   
     serial.begin(9600);   // debugging only
    vw_set_ptt_inverted(true);    // required rx link module
    vw_setup(2000);                   // bits per sec
    vw_set_rx_pin(11);           // receiving on pin 23 (mega) ie rx pin module connects pin.
    vw_rx_start();                      // start receiver
    vw_set_tx_pin(3);     
 
 

    pinmode(ledpin, output);

    // initialize timer1
    cli();          // disable global interrupts
    tccr0a = 0;     // set entire tccr1a register 0
    tccr0b = 0;     // same tccr1b

    // set compare match register desired timer count:
    ocr0a = 256;
    // turn on ctc mode:
    tccr0b |= (1 << wgm12);
    // set cs10 , cs12 bits 1024 prescaler:
    tccr0b |= (1 << cs10);
    tccr0b |= (1 << cs12);
    // enable timer compare interrupt:
    timsk0 |= (1 << ocie1a);
    // enable global interrupts:
    sei();
   
   
}



isr(timer0_compa_vect)
{
        seconds++;
    if (seconds == 300)
    {
        seconds = 0;   
        readmysensor();
    }
}


void loop()
{
     
     uint8_t buf[vw_max_message_len];
    uint8_t buflen = vw_max_message_len;

    if (vw_get_message(buf, &buflen)) // non-blocking
    {
int i;
       
        digitalwrite(13, true); // flash light show received message
// message checksum received, dump it.
serial.print("got: ");

for (i = 0; < buflen; i++)
{
  verify[1] = buf[i]  ;
         
          serial.println(verify[1]);
}
       
       if (verify[1] == 'k')
       {
         vw_rx_stop();
          (j = 0; j < k; j++)
          {
                tempvoltage = storage [j];
           [b]//    tempyea = yea[j];[/b]
            tempmont = mont[j];
            tempda = da[j];
            temphou = hou[j];
            tempminu= minu[j];
        [b] //    tempsecon= secon[j];[/b]
            download(tempvoltage,tempyea,tempmont,tempda,temphou,tempminu,tempsecon);

          }
          vw_rx_start(); 
       }

        digitalwrite(13, false);
    }

}



void readmysensor()

      rtctime time;
    rtcdate date;
    rtc.readtime(&time);
    rtc.readdate(&date);
   [b] // yea[k] = date.year;[/b]
  mont[k]=date.month;
   da[k]=date.day;
   hou[k]=time.hour;
    minu[k]=time.minute;
[b]// secon[k]=time.second;[/b]
      digitalwrite(13, true);
      int sensorvalue = analogread(a0);
      float voltage = sensorvalue * (5.0 / 1023.0);
      precision1 = voltage * 1000;
      precision2 = voltage * 100;
      precision2 = precision2 * 10;
      precision1 = precision1 - precision2 ;
       
   
   
   
      if (precision1 >= 5)
      {
        precision2 = (voltage * 100) + 1;
         storage[k] = precision2 ;
       }
      else
    {
      storage[k] = voltage * 100 ;
    }

      digitalwrite(13, false);
      k++ ;
     if (k==100)
     {
      k = 0;
     }
}


void download( int f,int y, int m, int d, int h, int mi, int se ){
int charnum1 = (int)f/100;
int charnum2 = ((int)f/100)*100;
charnum2 = f - charnum2 ;
char msg[60];
sprintf(msg, "%i.%i  %i/%i/%i  %i:%i:%i", charnum1,charnum2, y,m,d,h,mi,se);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();

}



when run bold line code in code, arduino board hang up.i suspect timer isr long. know, isr should write short possible. however, there way solve problem? advance helps.

code: [select]
int sensorvalue = analogread(a0);
100 microseconds, right there.
hardly short.


Arduino Forum > Using Arduino > Project Guidance > Needs help for Interrupt


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62