AVR6613 / Atmega168

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

Hi,

I'm using an Atmega168 and got a strange behaviour, it looks like there is some memory problem...

I'm using an array with 2 elements of the struct eval_button_struct_t.

I don't even need to use the element of the struct, only make a declaration of the array.

The non-working struct:
typedef struct {
SwitchStatusType sample;
SwitchStatusType debounced_value;
EvalButtonStatusType value;
EvalButtonStatusType lastOutput;
boolean pulse_01;
u16 debounce_timer;
u16 pulse_timer;
boolean continuously_buffered;
volatile u8 sp_cnt;
} eval_button_struct_t;

It works when I change one of the variables below to 8 bit instead of an enum(16 bit by default?) or if I use the compiler flag "-fshort-enums".

typedef struct {
SwitchStatusType sample;
u8 debounced_value;
EvalButtonStatusType value;
EvalButtonStatusType lastOutput;
boolean pulse_01;
u16 debounce_timer;
u16 pulse_timer;
boolean continuously_buffered;
volatile u8 sp_cnt;
} eval_button_struct_t;

/Daniel

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

Hi Danung - either your question does not have enough context around it, or the title was missleading (I think you can edit the thread name if you started it). I am guessing you are updating and debouncing in an ISR, you could pad out the ISR with nops a little to see if the behaviour changes, in which case it's not the data size, but possibly the instruction generation.

Try expanding the code snapshot a bit more, if you were me, I would try tweaking the optimisation level -O arg.

Conrad Braam - www.softcircuitry.blogspot.com - www.plcsimulator.org
Always start off poorly, that way when you finally figure it out, you can get a few surprise hits in.