DSPRelated.com
Forums

DSP/BIOS Float[] Vs float[]

Started by Fran MacCarthy January 26, 2004
Hi all,

I'm new to the C6711DSK and have a question regarding DSP/BIOS data
types. I'm outputting a 100Hz sin wave from my 88.2kHz DAC. To produce
this signal, I've filled a buffer of size 882, as follows -

Float sig[100];

Void main()
{
	Int i;
   
   	for(i=0;i<882;i++)
		sig[i] = cos(2*PI*100*i/(Float)(SR));
    
	McBSP_Init();
	EDMA_Init();

    return;    
}

With this code I get a load of about 70%, but when I change my
declaration to -

float sig[882];

and change nothing else, the load drops to 15% or so. Why is this? 

I've also noticed that if I set the frequency of the output signal to
400Hz, with the same buffer size, my output has a slight distortion.
This glitch appears as if one of the samples is being outputted
incorrectly for every cycle of the signal. Its as if, a value is being
writen to the sig buffer which shouldn't be there. This glitch occurs
if I declare sig as -

float sig[100];

but disappears if I use -

Float sig[100];

If I declare the following -

float sig1[100];  //not used
float sig[100];

the glitch again disappears. When should I use DSP/BIOS data types and
when should I not?

I plan to write a PC application which allows the user to specify the
frequency they wish to output. To do this I was going to create a
memory segment of size 882, at base 0x20. I have the DSP set for 3 way
cache. The PC would then write in the samples to this buffer for
outputting. The available frequencies would be multiples of 100Hz. Is
this the best approach?

Thanks,

Fran.
rockall_rebel@yahoo.com (Fran MacCarthy) writes:
> Float sig[100];
...
> for(i=0;i<882;i++) > sig[i] = cos(2*PI*100*i/(Float)(SR));
Undefined behaviour. Phil -- Unpatched IE vulnerability: history.back method caching Description: cross-domain scripting, cookie/data/identity theft, command execution Reference: http://safecenter.net/liudieyu/RefBack/RefBack-Content.HTM Exploit: http://www.safecenter.net/liudieyu/RefBack/RefBack-MyPage.HTM
Fran MacCarthy wrote:

> Hi all, > > I'm new to the C6711DSK and have a question regarding DSP/BIOS data > types. I'm outputting a 100Hz sin wave from my 88.2kHz DAC. To produce > this signal, I've filled a buffer of size 882, as follows - > > Float sig[100];
... Please enlighten me. Why (how?) do you send a float to a DAC? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
<snips>
> Float sig[100]; > > for(i=0;i<882;i++) > sig[i] = cos(2*PI*100*i/(Float)(SR));
(A) The line Float sig[100]; reserves space for 100 f.p. numbers. By using a loop counter i which exceeds the maximum allowable array index value of 99 (i.e. 100 - 1), you are writing to memory areas beyond the allocated array space. You are trashing other variables stack. This can result in almost any behaviour/crash symptoms from the system. Recommmend you allocate 882 items (same value used as maximum loop count). (B) I am unfamiliar with TI DSP's, so I do not know what the following does: &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;McBSP_Init(); &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;EDMA_Init(); so I assume it is a legitimate way to send data to the DAC, but I don't see any parameters being passed, (like array base address & itemcount) which I would have expected. (C) Could you clarify what you mean by "load of xx%"? If this refers to some sort of CPU idle loop indication, changes to the declared array size will result in different kinds of crash. The CPU is doing a BTN (Branch to Telephone Number). Hope this helps Jim Adamthwaite
On 26 Jan 2004 09:53:57 -0800, rockall_rebel@yahoo.com (Fran
MacCarthy) wrote:

Other people have answered (at least partly) your other questions,
although I would repeat that there are some fundamental flaws there!

>I plan to write a PC application which allows the user to specify the >frequency they wish to output. To do this I was going to create a >memory segment of size 882, at base 0x20. I have the DSP set for 3 way >cache. The PC would then write in the samples to this buffer for >outputting. The available frequencies would be multiples of 100Hz. Is >this the best approach?
It's one approach, and it might work if you use RTDX. If you're looking to use the HPI you'll proably have difficulty getting it to work; the HPI is notoriously flaky on the C6711DSK. Have a google for some older threads on C6711 DSK HPI problems. Best Regards John McCabe To reply by email replace 'nospam' with 'assen'
Sorry, I copied that array wrong - it is infact Float sig[882]; Late
night... Hers my code in more detail -

#pragma DATA_SECTION(hundred, "SIN_BUFFER")
float sin[882]; // changing this to Float changes the CPU load
dramatically

Void main()
{
  Int i;
    	
  for(i=0;i<882;i++)
    sin[i] = 0.25*cos(w(700.0)*i/(float)(SR));

  McBSP_Init();
  EDMA_Init();

  return;    
}

Void AudioSWI(PIP_Obj *in, PIP_Obj *out)
{
    Uns *src, *dst;
    Uns size;
    Uns f1,f2;  //each channel in floating point form
    Uns size;
    Int j=0;

    size = getBuf(in, &src);  // size = 128
    allocBuf(out, &dst);

    for (i = 0; i < size/2; i++)
    {
      if(j==882)
        j=0;

       f1 = sin[j]; // set channel 1 sample 

// channel 1 and 2 stored as 32-bit 
       FloatToUns(*(dst+i),f1,f2);
     }

    putBuf(out, size);
    freeBuf(in);
}

me <secad@netspace.net.au> wrote in message news:<bv467o$2pr5$1@otis.netspace.net.au>...
> <snips> > > Float sig[100]; > > > > for(i=0;i<882;i++) > > sig[i] = cos(2*PI*100*i/(Float)(SR)); > > (A) > The line > Float sig[100]; > reserves space for 100 f.p. numbers. > > By using a loop counter i which exceeds the maximum allowable array > index value of 99 (i.e. 100 - 1), you are writing to memory areas > beyond the allocated array space. You are trashing other variables > stack. This can result in almost any behaviour/crash symptoms from the > system. Recommmend you allocate 882 items (same value used as maximum > loop count). > > (B) > I am unfamiliar with TI DSP's, so I do not know what the following does: > &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;McBSP_Init(); > &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;EDMA_Init(); > so I assume it is a legitimate way to send data to the DAC, but I don't > see any parameters being passed, (like array base address & itemcount) > which I would have expected. > > (C) > Could you clarify what you mean by "load of xx%"? If this refers to > some sort of CPU idle loop indication, changes to the declared array > size will result in different kinds of crash. The CPU is doing a BTN > (Branch to Telephone Number). > > Hope this helps > Jim Adamthwaite
On 26 Jan 2004 09:53:57 -0800, rockall_rebel@yahoo.com (Fran
MacCarthy) wrote:

>With this code I get a load of about 70%, but when I change my >declaration to - > >float sig[882]; > >and change nothing else, the load drops to 15% or so. Why is this?
What is the result of evaluation sizef (FLoat). The code in std.h: #if defined(_80_) || defined(_SUN_) || defined(_67_) typedef float Float; #else typedef double Float; #endif may be something to do with it if you haven't got the flags set properly in the DSP/BIOS to say that it is a C67x Processor. Best Regards John McCabe To reply by email replace 'nospam' with 'assen'
Thats the problem, thanks. The thing is though, in my DSP/Bios config,
I have set the Target Board Name to C6711 and the CSL to 6711. I'm
presuming that the compiler thinks that I'm working on a C6211. What
else might cause this?

Thanks.

john@nospam.demon.co.uk (John McCabe) wrote in message news:<4016a43b.31008077@news.btclick.com>...
> On 26 Jan 2004 09:53:57 -0800, rockall_rebel@yahoo.com (Fran > MacCarthy) wrote: > > >With this code I get a load of about 70%, but when I change my > >declaration to - > > > >float sig[882]; > > > >and change nothing else, the load drops to 15% or so. Why is this? > > What is the result of evaluation sizef (FLoat). The code in std.h: > > #if defined(_80_) || defined(_SUN_) || defined(_67_) > typedef float Float; > #else > typedef double Float; > #endif > > may be something to do with it if you haven't got the flags set > properly in the DSP/BIOS to say that it is a C67x Processor. > > > Best Regards > John McCabe > > To reply by email replace 'nospam' with 'assen'
On 28 Jan 2004 03:35:50 -0800, aine_canby@yahoo.com (?ine Canby)
wrote:

>Thats the problem, thanks. The thing is though, in my DSP/Bios config, >I have set the Target Board Name to C6711 and the CSL to 6711. I'm >presuming that the compiler thinks that I'm working on a C6211. What >else might cause this?
Select "Project" => "Build Options". Under the "Compiler" tab, what have you got set for "Target Version" under "Basic"? Also in the "Preprocessor" section, have you defined CHIP_6711;BOARD_6711DSK in the "Define Symbols (-d)" option? Best Regards John McCabe To reply by email replace 'nospam' with 'assen'
Cool, thanks very much John. 

john@nospam.demon.co.uk (John McCabe) wrote in message news:<4017c200.18295737@news.btclick.com>...
> On 28 Jan 2004 03:35:50 -0800, aine_canby@yahoo.com (?ine Canby) > wrote: > > >Thats the problem, thanks. The thing is though, in my DSP/Bios config, > >I have set the Target Board Name to C6711 and the CSL to 6711. I'm > >presuming that the compiler thinks that I'm working on a C6211. What > >else might cause this? > > Select "Project" => "Build Options". Under the "Compiler" tab, what > have you got set for "Target Version" under "Basic"? > > Also in the "Preprocessor" section, have you defined > CHIP_6711;BOARD_6711DSK in the "Define Symbols (-d)" option? > > > Best Regards > John McCabe > > To reply by email replace 'nospam' with 'assen'