generate keypad interrupt on ATMega128

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

Hello,

I'm new to AVR development and trying to figure out some basic things such as interrupts, timers, and others. I have setup my development environment with AVRStudio, WinAVR, Procyon AVRLib, Eclipse (I was able to debug my C source in AVRStudio from Eclipse...). But I'm still waiting for my development board.
Meanwhile, I'm a bit stuck in understanding something which is probably basic to all of you: I'd like to generate an interrupt upon a keypress (let's say a 5 buttons keypad connected to PA0:PA4, with debounce as an option...). Oh yes, all this on an ATMega128.
My final goal is also to have interrupts generated each x msecs to interact with the environment and in addition, I'd like if possible not to touch the timers/counters used by AVRLib (for PWM purpose....)
Of course, I'll go step-by-step: keypad first !

I got the butterfly sources, and tried to "port" it to ATMega128, but I'm a bit lost (especially without the HW) with all registers and so on. I'm also looking at the great AVR Tutorials in forums.

Thanks !
V.

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

Suggest you do NOT try to generate interrupts from buttons (with the notable exception of an interrupt to wake the AVR out of sleep mode). You are far better off polling the buttons either in the mainline or on a timer interrupt. Otherwise bounce is going to be a BIG problem:

http://www.ganssle.com/debouncin...

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

Ok. Thanks for the pointer to the doc...
So I guess I'll go with the timer interrupt. It is the approach used in butterfly, isn't it ?
So, for my project I'd need:
- a timer interrupt for buttons
- a timer to call a function at regular interval (maybe the same as above, depending on timing)
- two timers for PWM

Am I right ?
Has the Mega168 enough timers in my case ? I'm a bit lost with OCxy (X=1..3,Y=A..C) and the 128 datasheet, is well.... a datasheet...

AVRLib seems to handle OC1A and OC1B.... so I'd have to handle the rest manually ? the key + function timers are of course internal timers/interrupts.

Thanks.
V.

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

Well you can probably "piggy back" a button scan (say every 10ms) on the back of one of your PWM timers.

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

Yes, it's what I'll probably do once I have understood timers/interrupts from the datasheet, and the implementation in AVRLib.

Thanks.

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

Oh, and one more stupid question: the ATMega168 has the following:
1 Timers/Counter 8-Bit 2 Channel,
and
1 Timers/Counter 16-Bit 2 Channel, 8-Bit PWM 2

What does the "channel" refer to ? Is there 4 timers in total, sharing prescale 2 by 2 ?

Thanks.

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

The "channels" are the PWM generators. There are 6 in all, two on each timer.

There are 3 individual timers:

timer 0 - 8 bit
timer 1 - 16 bit
timer 2 - 8 bit