Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Seeking equivilant registers on Atmega328
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Seeking equivilant registers on Atmega328

by lopeysnapes on Fri Mar 20, 2009 6:56 pm

Hello,

So I am trying to upload a sketch that refers to registers that only exist on
Atmega168 and/or Atmeg8 but not on Atmega328 The code snippet as follows:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void audioOn() {
#if defined(__AVR_ATmega168__)
// Set up PWM to 31.25kHz, phase accurate
TCCR2A = _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);
#else
// ATmega8 has different registers
TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20); // <-------------------????
TIMSK = _BV(TOIE2);//<-----------------------------------------????
#endif
}
*************************************
so what are the alternative Atmega328 registers to use instead of
TCCR2 WGM20 COM21 CS20 TIMSK TOIE2??
I compared spec sheets but I don't know which ones to swap out.
lopeysnapes
 
Posts: 10
Joined: Thu Sep 25, 2008 3:26 pm

Re: Seeking equivilant registers on Atmega328

by westfw on Fri Mar 20, 2009 8:38 pm

The registers should be the same on mega328 as on mega168; you should just need to fix the conditional:
Code: Select all | TOGGLE FULL SIZE
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__)

westfw
 
Posts: 1652
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Seeking equivilant registers on Atmega328

by adafruit on Tue Mar 24, 2009 10:37 pm

close! you want

#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)

note the P :)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Seeking equivilant registers on Atmega328

by mtbf0 on Tue Mar 24, 2009 11:33 pm

this might work, too.

Code: Select all | TOGGLE FULL SIZE
#if defined (_AVR_IOMX8_H_)

has the advantage of working for a '48, an '88, a '168 or a '328.

maybe.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.