The amount of time I've solved a problem to do with AVR by reading this forum is amazing but now a problem eludes me and I think I must make my first post.
I have an ATMEGA32 hooked up with a tlc7524 DAC via PORTA
For now I just want to play some audio samples through it at 8-bit/8 Khz.
If I understand correctly I just convert the audio I want to play into an 8 bit unsigned wav at 8khz and strip the audio samples out of it and put it in my code.
I set up the timer to trigger every 125us (8000hz)
DACTimerInit: LDI Temp, 0x0A ; Set Timer Mode OUT TCCR0, Temp LDI Temp, 0x02 ; Enable Timer Interupts OUT TIMSK, Temp LDI Temp, 0xF8 ; Set timer to correct cycles OUT OCR0, r16 RET
The simulator shows that this timer interrupt does indeed run every 125us exactly:
timerHandle: IN Temp, PortD ORI Temp, 0x04 ; Set bit 4 (ie DAC latch) OUT PortD, Temp NOP ;Wait 4 cycles for DAC latch just to be sure NOP NOP NOP ANDI Temp, 0xFB ; Clear bit 4 (ie DAC latch) OUT PortD, Temp LPM temp, Z+ ; Get next byte from ROM and OUTput it to PORTA OUT PORTA, temp ;......Some code to ensure looping snipped....... RETI
The simulator runs perfectly it presents each byte of data to PORTA and sets the latch bit at 8000 Hz.
Alas when I run it on my circuit I get a really strange noise.
I recorded the noise and took a picture of the waveforms.:
1) Original Sound
2) The noise I recorded off my circuit at 8 Khz
3) As the noise coming off my DAC was twice as long as the original so I halved the timer to see what would happen. It sounds pretty much the same.
I'll post the part of the schematic I'm trying to get working here. Sorry its a bit messy but I think you can see if I've done something terribly wrong.
Haha I there just a random floating GND there, just ignore that.
Does anyone recognize the sound? It definitely follows a pattern.
Thanks for any help,
Edit: Also if you zoom in on the output waveforms you can see that it keep dipping up and down almost like a square wave. Very weird....