Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help Writin Complex Code

Status
Not open for further replies.

b0rna

New Member
hey all, im going to be building a nice and hard project and i need some help coding my pic. im not sure of the name of the pic i will be using, but it has an analog-2-digital converter, onboard. now leaving that apart, i will be inputin an audio signal. what i need this pic to do, and i will be overclockin it to 20 MHZ for the fastest processing, is that i need this pic to convert the audio signal to digital, and than count the length each digital signal lasts, and based on its length, output a specific voltage to one if its outputs. this will be a full wave spectrum analyser. basically, if the audio signal is within 0-600HZ, bass noise, it will look at this signal, and based on its length from 0-600 hz output lets say if its 300, 1/2 volts to pin 6; than i will use an led driver set for a reference of from 0-1 volt to drive 10 leds for that specific frequency range. i will have as many drivers/channls as i have output pins for and what i need help with is not the conversion to digital, but how do i go about making this pic count the Length of a single digital wave at a time and store it in one of its registers for the next step which is processing it and outputtin a voltage. thank you for your read of this long post and i hope someon can help.
 
b0rna said:
hey all, im going to be building a nice and hard project and i need some help coding my pic. im not sure of the name of the pic i will be using, but it has an analog-2-digital converter, onboard. now leaving that apart, i will be inputin an audio signal. what i need this pic to do, and i will be overclockin it to 20 MHZ for the fastest processing, is that i need this pic to convert the audio signal to digital, and than count the length each digital signal lasts, and based on its length, output a specific voltage to one if its outputs. this will be a full wave spectrum analyser. basically, if the audio signal is within 0-600HZ, bass noise, it will look at this signal, and based on its length from 0-600 hz output lets say if its 300, 1/2 volts to pin 6; than i will use an led driver set for a reference of from 0-1 volt to drive 10 leds for that specific frequency range. i will have as many drivers/channls as i have output pins for and what i need help with is not the conversion to digital, but how do i go about making this pic count the Length of a single digital wave at a time and store it in one of its registers for the next step which is processing it and outputtin a voltage. thank you for your read of this long post and i hope someon can help.

What you're describing there is basically a frequency counter, it would only work on a single input frequency at a time, not as a spectrum analyser.

For a spectrum analyser you use FFT (Fast Fourier Transform) which is a very complicated mathmatical method. This isn't a good project for a PIC due to the highly intensive maths and memory requirements involved, the mid-range PIC16F877 probably isn't up to it!. However, if you search for FFT on the PICList you will find a project for an FFT spectrum analyser using a high-end PIC which actually feeds a VGA monitor for a display.

BTW, 20MHz isn't overclocking a PIC, many of them are designed to work at 20MHz, with some of the high-end ones at 40MHz.
 
i was just not searchin the right thing and the frequency counter returned many results of similar projects... my question now is, is there a limitation on the frequecny the pic can count? general audio at cd quality is something like 100HZ-12KHZ can the pic count such high frequencies? and why would it only work on a single input frequency? i was building a spectrum analyser using audio filters and 10 led drivers, the lm3915's i think, but i just found it too hard to build 15 audio frequency filters and do the calculations to get the right parts and i was not getting results, and even when my filters worked, they all needed amplifications and the driver did not respond to them, so i thought of making the audio into digital signals of highs and lows and all the pic had to do is cound the length each take...some more help would be nice im learning very fast in electronics and im only in grade 11, thank you.
 
b0rna said:
i was just not searchin the right thing and the frequency counter returned many results of similar projects... my question now is, is there a limitation on the frequecny the pic can count? general audio at cd quality is something like 100HZ-12KHZ can the pic count such high frequencies? and why would it only work on a single input frequency? i was building a spectrum analyser using audio filters and 10 led drivers, the lm3915's i think, but i just found it too hard to build 15 audio frequency filters and do the calculations to get the right parts and i was not getting results, and even when my filters worked, they all needed amplifications and the driver did not respond to them, so i thought of making the audio into digital signals of highs and lows and all the pic had to do is cound the length each take...some more help would be nice im learning very fast in electronics and im only in grade 11, thank you.

FFT is not too hard. You would take samples as fast as possible, but within a limited window. Correct me if I'm wrong but I think the ADCs of the PIC line all have the same speed. 12.86uS recommended acquisition time 19.2uS conversion, so it could theoretically do 31ksamples/sec, thus able to sample a 15Khz signal. You would need a lowpass filter since this does not include the entire audio range. If you want better, you will need to get an external ADC. Many faster ones are available.

All the FFT math comes after the fact. So lower speed only changes how often you can update the result. Also be aware that the number of samples you can acquire is strongly limited by the available RAM on the part. With 2 bytes per 10-bit sample, that's only 16mS of data. In reality, you'll need a lot of that overhead for the FFT routines and other usage. I don't know how FFTs work if you don't have enough samples to assemble an entire cycle of a frequency component- at this size of window, frequencies below 62Hz don't fit into it.
 
b0rna said:
i was just not searchin the right thing and the frequency counter returned many results of similar projects... my question now is, is there a limitation on the frequecny the pic can count? general audio at cd quality is something like 100HZ-12KHZ can the pic count such high frequencies? and why would it only work on a single input frequency? i was building a spectrum analyser using audio filters and 10 led drivers, the lm3915's i think, but i just found it too hard to build 15 audio frequency filters and do the calculations to get the right parts and i was not getting results, and even when my filters worked, they all needed amplifications and the driver did not respond to them, so i thought of making the audio into digital signals of highs and lows and all the pic had to do is cound the length each take...some more help would be nice im learning very fast in electronics and im only in grade 11, thank you.

A mid-range PIC running at 4MHz makes an effective frequency counter up to 50MHz, it's a standard application note, back from many years ago.

However, a spectrum analyser is a very different device, it has to detect specific frequencies amongst many others, including harmonics.

If you feed just two frequencies into a frequency counter, one at 1KHz and one at 10KHz, how does it know which is the start and finish of which?. The result is likely to be a constantly changing reading, none of which is likely to be correct!.

If you filter each individual frequency band, rectify it and measure the level with a PIC you could easily do it - but that's only replacing the LM3915 with a PIC, you still need to build all the filters.

As I mentioned before, FFT is the uP way to do it.
 
forgive me if im talkin stupid nonesense, but is there an application of the FFT that just Filters a signal, does not do Any spectrum analysing, but to just filter a range and o/p on sevral pins?
 
b0rna said:
is there an application of the FFT that just Filters a signal, does not do Any spectrum analysing, but to just filter a range and o/p on sevral pins?
no , a FFT will show all frequiencies present , and harmonics as well.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top