Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Timer counter erratic in '2343

Timer counter erratic in '2343

2008-06-09 by John Johnson

Hello All,

I'm glad you all, and this group, are here. I hope I will be able to
contribute to this group myself.

I'm working on a small project to keep our coffee pots from boiling
dry at the office.
I'm using an AT90S2343-10PU (I think it's a PU) that I have left over
from previous piddling.
The problem is, sometimes it seems to run in slow motion, and
sometimes it is okay. I cycle the power, and it will run at the
correct speed one time, then a few times in "slow mode", then it's
okay again.
I reduced the WinAVR/gcc code down to a simple ISR that counts a
variable down. When it's 0, it changes an LED's state. It should be
one second on, one second off. When it goes into "slow mode" it is
more like 6 seconds on, 6 seconds off.

The code (from memory) goes something like:

#define F_CPU 7372800

#include // avr stuff

#define OVFS_PER_SEC (F_CPU / 64 / 256)

volatile int16_t ovfs;
volatile uint8_t secs;
volatile uint8_t mins;
volatile uint16_t hours;

ISR(timer overflow 0) // I forget the exact signal name
{
  if (ovfs-- <= 0) {
    ovfs = OVFS_PER_SEC;
    secs++;
  }
}

void ioinit()
{
  TCCR0 = _BV(CS1) | _BV(CS0); // or whatever clk/64 is
  TIMSK = TOIE0;
  sei();
}

int
main(void)
{
  uint8_t old_secs;

  ioinit();

  for(;;) {
    _delay_ms(250);

    if (secs != old_secs) {
        if (secs >= 60) {
          secs = 0;
          mins++;
          // mins and hours processing
        }
        if (secs & 0x01) {
          PORTB |= 0x01;
        }
        else {
          PORTB &= 0xFE;
        }
      }
    }
}

That is the essence of the code.

As far as hardware, it's on a solderless breadboard. I've added bypass
caps all over the place, a 100nf from gnd, across the IC to Vcc. I
have 100nf, 1uf and 10uf on the supply strips (tried a 470uf too).
I've tried a linear, as well as a switching 5v supply. Added inductors
in series with the supply line. Added a bypass cap for the oscillator
(which I verified runs at the right frequency). Tied reset to Vcc.
Incidentally, grounding reset does not cure the problem. It starts
back in "slow mode" if it already was running slow.

Any help greatly appreciated!

-- 
Regards,
 JJ

http://www.pcbgcode.org

Re: [AVR-Chat] Timer counter erratic in '2343

2008-06-11 by Cat Hotmail

I might be wrong, but I don't trust solderless breadboards.
I wouldn't think of trying anything on one but the simplest DC (or so) 
circuit.
Too many uncertainties... I would try prototype board instead.

Good luck

Cat
...
> As far as hardware, it's on a solderless breadboard. I've added bypass

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.