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.

A Microcontroller based Analogue Waveforms Analyzer Project

Status
Not open for further replies.
-

Thanks for all the advice, Nigel!! 8)

One more question about testing the program on PC. After I have written a program that works, how am I going to test what resolution work best and how many samples I need to calculate? :roll:

PS:I apologize for my poor understanding. :(
 
Re: -

km said:
Thanks for all the advice, Nigel!! 8)

One more question about testing the program on PC. After I have written a program that works, how am I going to test what resolution work best and how many samples I need to calculate? :roll:

PS:I apologize for my poor understanding. :(

Basically you need to generate data for different waveshapes, a sinewave is the obvious first choice, and you can generate that from the Sin() function included in most high level languages. As you're planning an 8 bit A2D, the maximum value can go from 0-255, so you need to write the generation routine accordingly - scaling it to give results in that range.

For a start I would try generating a run of 256 samples, and try your maths on that - then try 128 samples, and see if you get the same result, then 64 samples - you can do this easily by only using every 2nd sample, or third sample etc.

This simulates different numbers of samples, while keeping the data identical. You should also try doing the same with other waveshapes, to simulate real world conditions.

To try different A2D resolutions, scale the original numbers differently, this time from 0-1023 for 10 bit resolution - although this will give you even more memory problems on an 8 bit PIC. But I see no reason why 8 bit resolution won't be OK.
 
C code for calculations

Nigel Goodwin said:
Write in whatever software you are experienced in, Delphi, BASIC, C, Pascal, Prolog, Java - any language you like, just to prove it works

Is it you mean to prove the programming code can be used to perform the calculations?
:arrow: For Example:
The C code for RMS calculations:

total = 0;
for (i=0; i<SMP_CNT; i++) //SMP_CNT=Sample Count
{
total += (sample*sample);
}
RMS = sqrt(total / SMP_CNT);


PS: Anyone has the C code for the frequency/peak-to-peak/average/duty cycle calculations feel free to send me. Thank you :wink:
 
Re: C code for calculations

km said:
Nigel Goodwin said:
Write in whatever software you are experienced in, Delphi, BASIC, C, Pascal, Prolog, Java - any language you like, just to prove it works

Is it you mean to prove the programming code can be used to perform the calculations?
:arrow: For Example:
The C code for RMS calculations:

total = 0;
for (i=0; i<SMP_CNT; i++) //SMP_CNT=Sample Count
{
total += (sample*sample);
}
RMS = sqrt(total / SMP_CNT);


PS: Anyone has the C code for the frequency/peak-to-peak/average/duty cycle calculations feel free to send me. Thank you :wink:


That's the sort of idea, now generate some sample waveforms and make sure it works - then try different numbers of samples, to try and find the optimum point between small numbers of samples and high numbers of samples. Presumably there will be a point where you start to lose too much accuracy, you need to find it and keep just above it.

P-P is easy, simply search for the lowest and highest values, they are the two peaks.
 
How to test?

Nigel Goodwin said:
Basically you need to generate data for different waveshapes, a sinewave is the obvious first choice, and you can generate that from the Sin() function included in most high level languages.

What you mean by generate data for different waveshapes? Is it means that find the most suitable number of samples for different types of waveshape? The waveforms that I need to generate is it a function in the programing part, for example: y=sin(x) and from here I test different number of samples on it?

All the test is it mainly on the programming part only :?:

What others waveshape I need to generate? (analogue waveforms)


:( Sorry, this is the first time I do these. So, I need to be 100% sure.
 
Re: How to test?

km said:
Nigel Goodwin said:
Basically you need to generate data for different waveshapes, a sinewave is the obvious first choice, and you can generate that from the Sin() function included in most high level languages.

What you mean by generate data for different waveshapes? Is it means that find the most suitable number of samples for different types of waveshape? The waveforms that I need to generate is it a function in the programing part, for example: y=sin(x) and from here I test different number of samples on it?

All the test is it mainly on the programming part only :?:

What others waveshape I need to generate? (analogue waveforms)

Yes, different analogue wave shapes, obviously a sinewave is probably the first one to test (as it's a common wave shape and easy to generate), you should also test square waves (again, easily generated), triangle waves (still easy), sawtooth waves (easy again) - then more complicated waves, the sort of wave shapes you get in the real world, a note from a guitar, or a trumpet, a voice etc.

For the 'real world' type samples you would probably find it easiest digitising a sample in Windows, and using data from the WAV file. Or you could simply plot analogue wave shapes manually.
 
-

Nigel Goodwin said:
Yes, different analogue wave shapes, obviously a sinewave is probably the first one to test (as it's a common wave shape and easy to generate), you should also test square waves (again, easily generated), triangle waves (still easy), sawtooth waves (easy again) - then more complicated waves, the sort of wave shapes you get in the real world, a note from a guitar, or a trumpet, a voice etc.

Thanks Nigel :wink:
Is square waves also consider as an analogue waveform too :?:
For my project, is it necessary to test a more complicated waves like what you had mentioned:a note from a guitar, or a trumpet, a voice etc?

I thought that my project is only use to measure electric signal? :?
 
Re: -

km said:
Nigel Goodwin said:
Is square waves also consider as an analogue waveform too :?:
For my project, is it necessary to test a more complicated waves like what you had mentioned:a note from a guitar, or a trumpet, a voice etc?

I thought that my project is only use to measure electric signal? :?

Test what you need to, a square wave is an analogue signal, although it could also be considered a digital signal as well. As for measuring electrical signals, any kind of waveform in an electrical circuit is an electrical signal - what sort of electrical signals had you in mind?.
 
-

Nigel Goodwin said:
As for measuring electrical signals, any kind of waveform in an electrical circuit is an electrical signal - what sort of electrical signals had you in mind?.

At first, I thought that it would be only sinewave that I need to consider. Well, I think I'm wrong now. Actually, I don't really get it why I need to test for a more complicated waves as well? Do I really need to measure those you have said for my project? eg: a note from a guitar, trumpet, and a voice. :roll: OR is it just only a test to determine the number of samples for different types of waveform?
 
Re: -

km said:
At first, I thought that it would be only sinewave that I need to consider. Well, I think I'm wrong now. Actually, I don't really get it why I need to test for a more complicated waves as well? Do I really need to measure those you have said for my project? eg: a note from a guitar, trumpet, and a voice. :roll: OR is it just only a test to determine the number of samples for different types of waveform?

Your requirement was to display RMS values for the incoming data, if your incoming data is always a sinewave you can do so very, very simply, a normal cheap analogue or digital meter will do that - both types just read the sinewave directly, and simply scale it to read RMS - BUT THIS ONLY WORKS FOR THE EXACT WAVE IT WAS CALIBRATED FOR!.

If you want to read RMS values for differing waveshapes it's a lot more complicated, you need to calculated the RMS value, and if you don't test it with differing waveshapes how do you know if it works or not?.
 
-

Nigel Goodwin said:
If you want to read RMS values for differing waveshapes it's a lot more complicated, you need to calculated the RMS value, and if you don't test it with differing waveshapes how do you know if it works or not?.

Thanks for your advice!! Nigel :wink: I have the idea now.
After I had done the test for different waveshapes, how can I apply it to my project? (Since there are different values of sample for different waveshapes) :idea:
 
Re: -

km said:
Thanks for your advice!! Nigel :wink: I have the idea now.
After I had done the test for different waveshapes, how can I apply it to my project? (Since there are different values of sample for different waveshapes) :idea:

You simply use the tried and tested maths routines that you used on the PC, knowing full well that they work and give correct RMS readings for any waveshape you happen to feed it. The waveshape you monitor with your PIC design then doesn't matter, it will be correct for any waveshape - as an RMS routine has to be.
 
Question

Nigel Goodwin said:
You simply use the tried and tested maths routines that you used on the PC, knowing full well that they work and give correct RMS readings for any waveshape you happen to feed it.

hmm, I don't really get what you mean, Nigel. :roll: You asked me to simply use the tried and tested maths routines on the PC to confirm that it gives correct readings for any waveshape. Is it test on the programming part by feed in different values?(in the code that i write for different waveshapes :?: )

Nigel Goodwin said:
The waveshape you monitor with your PIC design then doesn't matter, it will be correct for any waveshape - as an RMS routine has to be.

What about peak-to-peak, frequency, average and duty cycle routines? The results will be correct also?
 
Re: Question

km said:
Nigel Goodwin said:
You simply use the tried and tested maths routines that you used on the PC, knowing full well that they work and give correct RMS readings for any waveshape you happen to feed it.

hmm, I don't really get what you mean, Nigel. :roll: You asked me to simply use the tried and tested maths routines on the PC to confirm that it gives correct readings for any waveshape. Is it test on the programming part by feed in different values?(in the code that i write for different waveshapes :?: )

No, you need to write code that works with any waveshape, if you have to write different code for different shapes your routine isn't working. RMS means Root Mean Square, and gives the same heating effect as the same DC voltage - so 230V DC fed to a heater works the same as 230V RMS, the waveshape doesn't matter, it still contains the same amount of energy.

Nigel Goodwin said:
The waveshape you monitor with your PIC design then doesn't matter, it will be correct for any waveshape - as an RMS routine has to be.

What about peak-to-peak, frequency, average and duty cycle routines? The results will be correct also?

You need to write different routines for them, they are totally different things - but RMS is the hard one!.

Have a look at http://www.epemag.wimborne.co.uk under downloads and PIC's, they have done various projects over the years, including scope type designs. "Micro PICScope" uses an LCD and a PIC16F877 to give a simple scope, it also calculates frequency and P-P, it could be worth looking at. They also did a PIC based scope that connects to the PC parallel port, the PC software (written in BASIC) could be worth a look.
 
Question

Nigel Goodwin said:
No, you need to write code that works with any waveshape, if you have to write different code for different shapes your routine isn't working....
:arrow:
You need to write different routines for them, they are totally different things - but RMS is the hard one!.

All the codes (for different waveshapes) & routines should write in a single program correct?

Thanks for your information, Nigel!! :wink: I have already seen it earlier. For the PICScope, can I use the code for my peak-to-peak and frequency calculations? Do you know the rating of the MICRO-PIC Scope?
 
Re: Question

km said:
Thanks for your information, Nigel!! :wink: I have already seen it earlier. For the PICScope, can I use the code for my peak-to-peak and frequency calculations? Do you know the rating of the MICRO-PIC Scope?

I see no reason why you can't use the routines, design your project round a similar scheme.

The rating of the MICRO-PICScope isn't really given, it just specifies "basically audio", but it does give 17KHz as the highest frequency, limited by the sampling rate.
 
PIC Programmer

Hi Nigel, I have something to ask you. My college programmer doesn't support PIC 16F628. Do I need to buy a programmer :?: OR build one :?:
 
Re: PIC Programmer

km said:
Hi Nigel, I have something to ask you. My college programmer doesn't support PIC 16F628. Do I need to buy a programmer :?: OR build one :?:

You could do either, the P16PRO40 is available very cheaply as a kit, hardly worth sourcing the components yourself.
 
-

Nigel Goodwin said:
An obvious easy value (for an 8 bit processor) would be 256 samples, but you don't have anywhere to store them in a 16F84.

After I have determined how many samples I need, how can I know my PIC has sufficient memory to store the samples?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top