FFT for ICCAVR

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

Hi,

I'm looking for a fix point FFT library for ICCAVR, I had found some, but only for WinAVR, and I don't have the skill to translate all the ASM Code. The FFT code must be small and fast like the one written by (C)ChaN, 2005.

Thanks

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

It's true that translating that is not easy. I think that your best option is to implement one from scratch. There are dozens implementations out there based on precalculated coefficients. Just pick up one and try. A couple of links
http://www.mathworks.com/product...
http://www.relisoft.com/Science/...
and of course numericals recipes in C.
Gettind down to asm is not much harder.

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

It would be interesting to see is the cpu hog was the sin-cos or the other stuff. I guess I could compile my profiler in with the fft and run it and see where it spends most of its time. What are your specs? How many time points? How many freq points? (trick question). How much dynamic range (8 bits is about 42dB, 10 bits is about 54, 12 is 66). If you are looking for audio distortion 80 db down, you need an external a/d I think.

Imagecraft compiler user

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

Thanks bob,

My spec are
-8bit
-35khz sampling
-256 Points
-FFT time about 16ms
-it's for a audio spectrum analyser that will display the frequancy on not more than 15 vertical leds by 8 column.

Thanks

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

I believe this guy has exactly what you need.
http://elm-chan.org/works/akilcd...

Though it only does 128 FFT points, and samplerate is only 9.6kHz.
I see he has done 256 points also.

Quote:
This is written in assembler and is optimized for MegaAVRs

edit:
Oops, seems like you referred to his code in the first place..

I have no experience with ICCAVR, so can't help you there ..

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

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

I had try this fft, it's work, but I must use winavr, and all my work is done in iccavr, and because this library is almost in assembler I don't have the skill to translate this asm to iccavr.

Thanks

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

sylvain.bissonne wrote:
I had try this fft, it's work, but I must use winavr, and all my work is done in iccavr, and because this library is almost in assembler I don't have the skill to translate this asm to iccavr.

Thanks

I tried to compile the ffft.S file with avr-gcc and it didn't complain at all (so it works ether for winavr and for avr-gcc/as). This is the command:

avr-gcc -mmcu=atxmega256a3 -c -o ffft.o ffft.S

Calling gcc instead of as directly, invokes the preprocessor and redefines all the register's labels.
As I don't have iccavr to test with, can you provide the errors that it's giving you when trying to compile?
RM

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

The list of error make 10 pages even more, the way to write the asm is very different to my eyes

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

I have converted some asm from gcc to iccavr... There are a set of rules... 'convert all .EQU to =' and a couple more like that. Somebody that knows one of those text converter languages like perl could probably write a translator in one page. I have to sit there and do global search and replace for hours...
If you have 256 time points, does that mean you need 'only' 256 angles in the sin table? That's a big speedup right there.

Imagecraft compiler user

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

Clearly no one here but Sylvain has actually looked at Chan's avr-as source code! The tricky bit is not the AVR opcodes - clearly they'll port to any AVR build system that can do Asm. It's the intricate macros he uses in the code that cannot be easily duplicated for anything but avr-as. To give you a flavour...

.macro	ldiw	dh,dl, abs
	ldi	\dl, lo8(\abs)
	ldi	\dh, hi8(\abs)
.endm

.macro	subiw	dh,dl, abs
	subi	\dl, lo8(\abs)
	sbci	\dh, hi8(\abs)
.endm

.macro	addw	dh,dl, sh,sl
	add	\dl, \sl
	adc	\dh, \sh
.endm

.macro	addd	d3,d2,d1,d0, s3,s2,s1,s0
	add	\d0, \s0
	adc	\d1, \s1
	adc	\d2, \s2
	adc	\d3, \s3
.endm

.macro	subw	dh,dl, sh,sl
	sub	\dl, \sl
	sbc	\dh, \sh
.endm

.macro	subd	d3,d2,d1,d0, s3,s2,s1,s0
	sub	\d0, \s0
	sbc	\d1, \s1
	sbc	\d2, \s2
	sbc	\d3, \s3
.endm

.macro	lddw	dh,dl, src
	ldd	\dl, \src
	ldd	\dh, \src+1
.endm

.macro	ldw	dh,dl, src
	ld	\dl, \src
	ld	\dh, \src
.endm

.macro	stw	dst, sh,sl
	st	\dst, \sl
	st	\dst, \sh
.endm

.macro	clrw	dh, dl
	clr	\dh
	clr	\dl
.endm

.macro	lsrw	dh, dl
	lsr	\dh
	ror	\dl
.endm

.macro	asrw	dh, dl
	asr	\dh
	ror	\dl
.endm

.macro	lslw	dh, dl
	lsl	\dl
	rol	\dh
.endm

.macro	pushw	dh, dl
	push	\dh
	push	\dl
.endm

.macro	popw	dh, dl
	pop	\dl
	pop	\dh
.endm

.macro	lpmw	dh,dl, src
	lpm	\dl, \src
	lpm	\dh, \src
.endm

.macro	rjne	lbl
	breq	99f
	rjmp	\lbl
99:
.endm


.macro	FMULS16	d3,d2,d1,d0 ,s1h,s1l, s2h,s2l	;Fractional Multiply (19clk)
	fmuls	\s1h, \s2h
	movw	\d2, T0L
	fmul	\s1l, \s2l
	movw	\d0, T0L
	adc	\d2, EH ;EH: zero reg.
	fmulsu	\s1h, \s2l
	sbc	\d3, EH
	add	\d1, T0L
	adc	\d2, T0H
	adc	\d3, EH
	fmulsu	\s2h, \s1l
	sbc	\d3, EH
	add	\d1, T0L
	adc	\d2, T0H
	adc	\d3, EH
.endm


.macro	SQRT32	; 32bit square root (526..542clk)
	clr	T6L
	clr	T6H
	clr	T8L
	clr	T8H
	ldi	BL, 1
	ldi	BH, 0
	clr	CL
	clr	CH
	ldi	DH, 16
90:	lsl	T2L
	rol	T2H
	rol	T4L
	rol	T4H
	rol	T6L
	rol	T6H
	rol	T8L
	rol	T8H
	lsl	T2L
	rol	T2H
	rol	T4L
	rol	T4H
	rol	T6L
	rol	T6H
	rol	T8L
	rol	T8H
	brpl	91f
	add	T6L, BL
	adc	T6H, BH
	adc	T8L, CL
	adc	T8H, CH
	rjmp	92f
91:	sub	T6L, BL
	sbc	T6H, BH
	sbc	T8L, CL
	sbc	T8H, CH
92:	lsl	BL
	rol	BH
	rol	CL
	andi	BL, 0b11111000
	ori	BL, 0b00000101
	sbrc	T8H, 7
	subi	BL, 2
	dec	DH
	brne	90b
	lsr	CL
	ror	BH
	ror	BL
	lsr	CL
	ror	BH
	ror	BL
.endm

Have fun converting to another dialect!

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

Yes that's the code I use, it's very simple to use and it's fast but it's under winavr and all my other part of the code is written with ICCAVR

Yours truly,
Sylvain Bissonnette
www.microsyl.com

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

I don't see an easy solution to this. If you pick an FFT algorithm and code it in C it'll likely work but slowly - this is exactly the kind of thing where Asm is a real benefit. I think it'd be worse trying to port Chan's Asm then to port the other C to WinAVR. Or find some FFT in Asm for Imagecraft (seems a bit unlikely)

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

Yep. The macros all kicked out after I had gone to the trouble of making a directory and a project and edited the h file includes in the c files. There aint nuthin standard about macro syntaxes. The iccavr assembler has a .macro and .endmacro directive with parameters, but I cant quite get the argument syntax yet... Is there a simple generic 16.16 c math package?

Imagecraft compiler user