Forums

Reducing sampling rate, compiler optimization bug???

Started by bernd007 December 3, 2007
Hello,

I use the PADK (Professional Audio Development Board) with a TI
TMS320C6727 DSP and I want to reduce the sampling rate to 8kHz... The
problem is, that the minimum possible sampling rate of the board is 32
kHz, so I have tried to solve the problem with a simple counter...
I have an interrupt service routine (ISR), which is called with 32 kHz. In
this routine I have a counter, counting to 4 (because of 8 kHz) and then I
set a flag (run = TRUE).

My main program is an endless loop with these commands:
While(1)
  {
  if (run == TRUE)
    {
    do_work();
    run = FALSE;
    }
  }

Now my problem: The program only works if I switch all compiler
optimizations off. It seems to be, that the compiler throws the while loop
during optimization away...
Do you have any solutions for sampling rate reducing without optimization
disadvantages...?

Cheers,
Bernd

PS: BTW, I am using Code Composer Studio 3.1...


bernd007 wrote:
> Hello, > > I use the PADK (Professional Audio Development Board) with a TI > TMS320C6727 DSP and I want to reduce the sampling rate to 8kHz... The > problem is, that the minimum possible sampling rate of the board is 32 > kHz, so I have tried to solve the problem with a simple counter... > I have an interrupt service routine (ISR), which is called with 32 kHz. In > this routine I have a counter, counting to 4 (because of 8 kHz) and then I > set a flag (run = TRUE). > > My main program is an endless loop with these commands: > While(1) > { > if (run == TRUE) > { > do_work(); > run = FALSE; > } > } > > Now my problem: The program only works if I switch all compiler > optimizations off. It seems to be, that the compiler throws the while loop > during optimization away... > Do you have any solutions for sampling rate reducing without optimization > disadvantages...? > > Cheers, > Bernd > > PS: BTW, I am using Code Composer Studio 3.1... > >
Maybe you have a race condition on the run flag which tends to show up when optimisations are turned on (because the code is running faster) ? Paul
On Dec 3, 8:49 am, "bernd007" <qwedsa...@gmx.net> wrote:
> Hello, > > I use the PADK (Professional Audio Development Board) with a TI > TMS320C6727 DSP and I want to reduce the sampling rate to 8kHz... The > problem is, that the minimum possible sampling rate of the board is 32 > kHz, so I have tried to solve the problem with a simple counter... > I have an interrupt service routine (ISR), which is called with 32 kHz. In > this routine I have a counter, counting to 4 (because of 8 kHz) and then I > set a flag (run = TRUE). > > My main program is an endless loop with these commands: > While(1) > { > if (run == TRUE) > { > do_work(); > run = FALSE; > } > } > > Now my problem: The program only works if I switch all compiler > optimizations off. It seems to be, that the compiler throws the while loop > during optimization away... > Do you have any solutions for sampling rate reducing without optimization > disadvantages...? > > Cheers, > Bernd > > PS: BTW, I am using Code Composer Studio 3.1...
It appears that you are trying to reduce your sample rate by simply taking every 4th sample. You better make sure that your input is band- limited to 4 KHz or there will be aliasing. Otherwise, you need to use a decimating filter on the input (e.g., CIC). This is a common DSP operation and you will find plenty of examples on the web.
Hi Bernd,

You have to define your run variable as volatile. The CCS compiler is 
*very* aggressive at optimizing loops and will always assume that a 
global variable won't be changed by an ISR. CCS will check if you modify 
the variable somwehere in the call-tree of do_work() though.

I'm sure your problem will just go away if you declare it as volatile.

Another thing you might want to do (won't help with your problem, but 
while we're at it...) is to tell CCS not to inline the do_work function.

The compiler might think he is clever and optimize your while loop. It 
will spawn multiple copies of the functions and run them in parallel. In 
your case this gives you no benefit, will increase the code size and 
reduce the performance due to instruction cache trashing. The 
FUNC_CANNOT_INLINE pragma will do that job for you.

Regards,
   Nils
Hi Nils,

thank you very much for yor help....
You have solved my problem...

Cheers,
Bernd
bernd007 wrote:
> Hi Nils, > > thank you very much for yor help.... > You have solved my problem...
Your problems are only just starting. Did you read Darol's post? Regards, Andor
bernd007 schrieb:
> Hi Nils, > > thank you very much for yor help.... > You have solved my problem...
:-) Nils