Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] PWM based audio

2012-08-05 by Steven Holder

On 05/08/2012 01:57, englsprogeny1 wrote:
>
> Hi guys,
>
> I want to start including audio in my projects a bit more. So far I've 
> designed using MP3 modules that I purchased on EBAY. I now want to 
> design using the AVR's 16 bit PWM to create audio.
>
> I've found a project that does this:
>
> http://elm-chan.org/works/sd20p/report.html
>
> When I download and build the 'firmware' found at:
> http://elm-chan.org/works/sd20p/sdsg.zip
>
> Everything builds ok.
>
> Unfortunately when I change the processor from attiny861
> to an attiny2313 (in the makefile) the build does not work.
>
> ### Target device
> #DEVICE = attiny861
> DEVICE = attiny2313
>
> Build results:
>
> main.c :
> avr-gcc -c -std=gnu89 -gdwarf-2 -mmcu=attiny2313 -Os -mcall-prologues 
> -Wall -Wextra -DF_CPU=16000000UL -DMODE=2 
> -Wp,-M,-MP,-MT,obj_hr/main.o,-MF,obj_hr/main.d main.c -o obj_hr/main.o
> main.c: In function 'chk_input':
> main.c:93: error: 'GIFR' undeclared (first use in this function)
> main.c:93: error: (Each undeclared identifier is reported only once
> main.c:93: error: for each function it appears in.)
> main.c: In function 'audio_on':
> main.c:135: error: 'PLLCSR' undeclared (first use in this function)
> main.c: In function 'wait_status':
> main.c:178: error: 'PCIE1' undeclared (first use in this function)
> main.c:179: error: 'WDTCR' undeclared (first use in this function)
> main.c: In function 'main':
> main.c:339: error: 'WDTCR' undeclared (first use in this function)
> main.c:341: error: 'PCMSK0' undeclared (first use in this function)
> main.c:342: error: 'PCMSK1' undeclared (first use in this function)
> make.exe: *** [obj_hr/main.o] Error 1
>
> > Process Exit Code: 2
> > Time Taken: 00:01
>
> ----------------------------------------------
>
> Looking at the datasheet for the attiny2313 I don't see the GIFR 
> (register) and others listed above. I thought that the register 
> structure for all AVRs would be the same or at least the same within 
> the 'tiny_xx' versions.
>
> When I change the processor to an atmega8
> I get different issues with the build. It points to the assembly file 
> within this project. I thought that assembly was the same across all 
> AVR processors.
>
> Thanks for any input.
>
> I'm not stuck with implementing this project using the source that I 
> found above (If anyone has any other suggestions).
>
> 
Hi,

The atmel processors have similar architectures but do have different 
register names and addresses. One way to get round this is to do a 
interface header file that can cope with different processors and using 
conditional compiler directions to cope with different register and bit 
definitions.

Example : In the main code swap all instances of GIFR with GIFR_REG, and 
define GIFR_REG in a header file that is processor dependent so we could 
say (pseudo code)

#if defined (__AVR_ATTINY861__)
     #define GIFR_REG GIFR
#endif

#if defined (__AVR_ATTINY2313__)
     #define GIFR_REG EIFR
#endif

If you do this with all the registers above and do the same for atmega8 
you should a processor independent build. The actual bits and registers 
the code users will be processor dependent as well, but what works for a 
mega 8 should also work fr a mega 16 with little or no modifications.

Regards



-- 
*Steven Holder*
s.holder123@btinternet.com
/www.sh-tec.co.uk/
/Mob:0792 1237035/


[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.