On Mon, 28 Dec 2009, enkitec@gmail.com wrote:
> Please verify if the clock source fuses are set up to cristal
> oscillator.
My fuses are (Low, Extended, High): 0xee, 0xff, 0xdf.
I've come one step further as I noticed changing OCR0A
*did* make a difference when I increased its value far
enough. Actually, more accurately, this more or less
means we're more or less "back to square one", except
I think I understand a bit better what I'm doing now.
Perhaps I need to give a bit more detail.
Here are the relevant code snippets:
#define TIMERFREQ 7812
#define HALFWAVE 3906
void setup_timer(void)
{
TCCR0A=(0<<WGM02)|(1<<WGM01)|(0<<WGM00); // CTC mode
TCCR0B=(1<<CS01)|(1<<CS00); // 8 mhz/64
OCR0A=15; // 8 mhz/64/(15+1)= 7812.5
TIMSK=(1<<OCIE0A); // Enable Counter Overflow Interrupt
sei();
}
ISR (TIMER0_COMPA_vect)
{
// calculate polyphonic square wave (individual
// amplitudes)
int stat=0;
w1=(w1+f1)%TIMERFREQ;
w2=(w2+f2)%TIMERFREQ;
w3=(w3+f3)%TIMERFREQ;
if (w1<HALFWAVE) stat+=amplitude1;
if (w2<HALFWAVE) stat+=amplitude2;
if (w3<HALFWAVE) stat+=amplitude3;
PORTB=stat;
}
(Full code is here:
http://ringbreak.dnd.utwente.nl/~mrjb/electro/polyphonic.c )
This works and gives notes at the right pitch.
However, if I set OCR0A to 7, this should
cause 15625 interrupts per second, right?
When I do this and
#define TIMERFREQ 15625
#define HALFWAVE 7812
the pitch actually drops. When lowering OCR0A
further, pitch remains constant, which seems
to indicate the ATtiny2313 is simply working
as hard as it can but simply cannot keep up.
So this brings me to my original question:
Is the 2313 simply too slow for the task,
or should I use assembly instead of C?
What special voodoo magic have you people
been using to generate 200kHz sine waves?
Best,
MarcMessage
Re: [AVR-Chat] ATtiny2313 audio- w/source
2009-12-28 by Marc R.J. Brevoort
Attachments
- No local attachments were found for this message.