variable overflow issue

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

short version: When I roll a char or int in an interrupt, program execution halts.

long version:
I have a simple timer overflow interrupt which increments a counter:

volatile static uint8_t t1_ovf_count;

//running @14.3 MHz with no prescaler
ISR(TIMER1_OVF_vect)
{

    ++t1_ovf_count;

}

I have an LCD displaying the count value (as evidence of program execution) as well as some other data. With the counter being 8 bit, the value increments as it should until it hits 0xFF at which it stops and the whole system seems to stop as well, as if all interrupts are disabled. With the count being 16 bits (uint16_t) all is well until 0xFFFF is reached at which point the same thing happens.

Do I need to do something with the way my interrupt is written or is there some other reason overflow of an 8 or 16 bit value causes problems?

Other info: using atmega64, external interrupts and timer interrupts

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do I need to do something with the way my interrupt is written

No.
Quote:
or is there some other reason overflow of an 8 or 16 bit value causes problems?

You would have to show us what you do with t1_ovf_count outside the ISR. The problem is most certainly there, not in the ISR.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

all I do outside the interrupt is reference the variable

fprintf(LCD,"t:%-6d",t1_ovf_count");

In the ISR, I use a modulo on the count to test when a 1/4 of a second has passed

    if(!t1_ovf_count%(F_CPU/262144))
    {
        thetemp = getTemp();
        flow_Hz = int_flow_ticks << 2;
        flow_mlps = int_flow_ticks/20;
        flow_total += int_flow_ticks;
        //200 ticks/sec = 1 L/s
        //.2 ticks = 1 ml/s
        //div by 4 since .25 sec
        // mL/s = ticks / 20;
        int_flow_ticks = 0;
    }

EDIT: tried to prevent over flow by using a modulo on the counter value

counter %= max_value;

the program now crashes/stops when counter reaches max_value. Also removed static keyword from variable declaration.

Finally, I made the interrupt an empty function and every thing (except stuff waiting for what happens in the interrupt) works well. Unfortunately, I need this interrupt to work for my project to work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

crashes/stops

Which? And how are you determining this?