Light sequencer on AVR DSP Problem please help

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

Hi folks :)

I`ve been searching AVRfreaks forum and google and I haven`t found any simillar open project to mine which I want to create.
I hope you will help me with it.

I want to make Disco Light Sequencer which will be based on Digital Signal Processing.
Most of Light Sequencers were made from analog active filters.

How it should work:

Let`s assume that we have analog signal and then we convert this signal to digital.Then we have written in AVR uC 4 filters which pass or stop desired frequencies. According to level of signal we control appropriate PWM (PWM1,PWM2,PWM3 and PWM4).(green bulb,red bulb, blue bulb, and another color)
One advantage of using AVR microcontroller is that we can program desired sequences (for example bass tone going from one side to another :) )

audio signal range: 20 - 20 000 [Hz]
I think that sampling : 30 0000 [Hz] will be enough becase we can sample frequency up to 15 000 [Hz]
which is enough.

I created 4 FIR(finite impulse response) filters based on Parks-McClellan method of finding coefficients.
Their center frequencies are:

1: 200 [Hz]
2: 550 [Hz]
3: 1500 [Hz]
4: 5000 [Hz]

Below i am enclosing their frquency responses:

1:

2:

3:

4:

There is no more than 148 taps in each filter.

Now my main questions are:

1. Have you ever made simillar device ??
2. Is it posiible to do it on atmega8 or other not specialized DSP microcontroller.
3. How to measure level of the filtered signal ??
4. Maybe you know other way how to do it on microcontroller or maybe you have links to other projects ??

Please maybe you have some suggestions how to do it ?

Code for the filter is :


/*
float input     new float input sample
float *coef     pointer to filter cefficients
int n           number of coefficients in filter
float *history  history array pointer
*/
float fir_filter(float input, float *coef, int n, float *history)
{
int i;
float *hist_ptr, *histr_ptr,*coef_ptr;
float output;

hist_ptr=histor;
hist1_ptr=coef +n-1; /*use for history update*/
coef_ptr = coef +n -1; /*point to last coef*/

/*form output accumulation*/
output = *hist_ptr++ * (*coef_ptr-);
for(i=2;i

Thanks in Advance

Adam

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

I've done second order statevariable filters on avrs. If you use 8 bit a/d you can get 32khz sample rate on the converter. I wanted to do an octave band filter, but I couldnt get the filter freq to work at freqs higher than about half the nyquist freq. Blew up. I think you could get good light-to-beat correlation by tracking the envelope of the music...booomp-booomp-boomp is pretty easy to detect.... grab a big buffer fill of samps, look for a max, look for a min. Use a mega64 or mega128 so you can hang an external 64k ram on it.

Imagecraft compiler user

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

Yeah that`s true but:

From the datasheet we can read:

Quote:
By default, the successive approximation circuity requires an input clock frequency between 50 KHz and 200 KHz to get maximum resolution. If lower resolution than 10 bits is needed, the input clock frequency to the ADC can be higher than 200 kHz to get a higher sample rate

But what is the highest sample rate ??

Secondly

Quote:

think you could get good light-to-beat correlation by tracking the envelope of the music...booomp-booomp-boomp is pretty easy to detect

That`s true but we should think about music and light delay. It will always be but not to big in this case ??

How to measure signal from other filters??
Lets remind that we have four of them for each bulb
and it would bee good to measure very quiclky filtered signal and then control PWM.

By the way that is my first big project wich I would like to make.

I have never used external RAM before :roll:

Still waiting forother suggestions what I should do ??

Adam

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

I think you should decide if you want to to be able to dim the lamps under computer control, or just sequence them. Get a board with an avr, make a 1 channel dimmer controlled by a menu on the serial port. Add a digital envelope detector and get that one channel to bump to the beat. If you are only using 25% of flash at this point, try to extend to 4 channels.

Imagecraft compiler user

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

I designed something much like this about 20 years ago although I did it with analog filters.
One thing you learn very quickly is that digital filters are compute intensive. Have you tried executing the code you posted and timed how long it takes to execute on an AVR? The AVRStudio simulator is handy for this. Armed with this information, get ready for the concept of 'tradeoff'. Firstly, consider dynamic range - you probably only really need 8 bits, so with some tricks, you can eliminate the floating point calcs, thus gaining a speed improvement. You could also look at simplifying the filters - my design used two pole sallen & key filers (3 of them) - basically a tone control(hi,mid,low)! So, I would suggest you don't need a high order filter for the application, in fact, only crude filtering is needed.

For the analog input I used a simple automatic gain control circuit to allow a wide range of signal input - it consisted of a simple rectifier and low pass filter to control a gain stage. This you could feed to the AVR's adc and then the rest is up to the code. As for determining the relative signal strength of your processed signal, for DTMF reception a TI app note used a RMS calculation to determine the signal strength. You might then want to put that through a lookup table to give you a brightness value.

Then there's dimming the lights. If you're planning on using PAR lamps similar to the picture, you'll most likely have to do phase control of triacs (a light dimmer). That alone will take some cpu time. Along with the DSP processing this may tax the AVR somewhat.
The cpu I used years ago was slower than the AVR but had hardware assist for the phase control, but it did MIDI and DMX512 that taxed the cpu a bit, so DSP was not an option.

DSP offers no real technical advantage in this application apart from reducing the amount of components needed.

Nevertheless a good project that has a degree of technical complexity.

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

Quote:
But what is the highest sample rate ??

Each sample takes 13 adc clock cycles, so the fastest would be 200kHz/13 which is about 15kHz. Of course, this is for 10 bit accuracy. Going to 8 bit you could get faster.

Quote:
How to measure signal from other filters??
Lets remind that we have four of them for each bulb

As Kartman said, this could be rather compute intensive. You might find that you need one avr to do the digitizing and one avr for each bulb, and then maybe even another to coordinate the result. I would suggest that an AVR32 would be a more appropriate chip to use. They have specific functionality for DSP applications.

Regards,
Steve A.

The Board helps those that help themselves.

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

Adam:

Research the Goertzel Algorithm. There is a good article in the Sept.2005 Circuit Cellar mag. Can be done on a 5 mips pic in C. Think what you can do with 20 mips and hdwr mult.
Aso this. http://www.embedded.com/story/OEG20020819S0057

Rick

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

Hi ! :D

Sorry for such a long delay in responding but I was searching many algorithms for this application.
At first I would like to thank you all guys for your remarks.

Actually the problem is that we have music which has to be sampled and processed in microcontroller.

Frequency of the music is: 20 - 20 000 [Hz]
The highest frequency for our application would be 15 000 which means that our sampling frequency should be 30 000 [Hz]Thus,coputations for the microcontroller are so high !

The Goertzel Algorithm is very interesting I read it twice :) Actually it is IIr filter. I am not sure if we can apply it t this circuit. I think it is better for searching specified tones.

I also found nice note called "AVR223: Digital Filters with AVR" from Atmel
From this note I found some examples of digital filters but they were using only 2 or 8 taps of the filter.

In my opinion we are able to do this on specialized microcontroller or on DSP dedicated microcontroller.
Anyway computation are very demanding.

Costs of few microcontrollers or DSP microcontrollers are really high.

Costs of few op-amp are silly. So we can make 3 active analog filters and then through almost each microcontroller control level of signal from each filter.

I think it`s better sollution and not so demanding and by the way you still have an opportunity to make sequences like:

mode 1)1 bass - 1 lamp,2 bass - 2 lamp, 3 bass - 3 lamp and so on.
mode 2) ...
mode 3)...
mode 4)...

and here is my next question connected with 4th mode:

For example coming 1 bass tone and I want to chose random lamp.
coming 2 bass tone chose another random lamp.

How to implement this in C language
random() ???

Thanks

Adam

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

C has a function which returns a seemingly random number. rand() or srand() or something, see any C reference or book.

I kind of like the analog filter idea, then the AVR would only require to sample four analog signals at 1kHz or another low sample rate to determine which lights should go on or off.

Note that you could design filters so that the AVR can use digital IO to control the bandpass/lowpass/highpass frequencies, maybe by connecting and disconnecting resistors via analog multiplexers or analog switches, or by digital potentiometers.

- Jani

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

It is simpler way !!

You can do that by hardware in AVR microcontroller !
Each ADC has built in multiplexer so I am able to choose which input I want to sample.

In this way first I sample ADC0 then ADC1 then ADC2 and then ADC3 and finding out what is the level of the signal of each band pass :)

If you are interested just look into datasheet of particular microcontroller

Adam

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

I know the AVR has a mux.

I meant that if you only have four filters, they have only four fixed frequencies you have selected the components for. You could use the AVR to control or fine tune what bandpass frequencies the four filters have.

But this gives me an idea, you could also have 6 or 8 fixed frequency filters, but you could select in your code which 3 or 4 of them to use at any time, like for different kind of music etc..

- Jani

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

I still think the lights should respond to envelope rather than freq content.... if you have tone bursts of low freqs..... booomp booomp booomp you want to see something getting brighter everytime you hear a booomp. If you have rimshots... tone bursts of hi freq white noise..... whack whack whack.... you want to see something flashing to the whack. I think the algo is... grab a bunch of samples.... run the samples thru 3 averagers with 3 time constants... short medium fast.... flash ea channel proportional to the envelope of the averager outputs.

Imagecraft compiler user

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

Or the analog filter part can output the envelope of the filtered content for the AVR.

- Jani