PDA

View Full Version : Wave Form Identifier



INaPickle
- 31st October 2005, 01:56
I need to identify sine, square, and triangle wave forms being generated from a signal generator at a frequency of around 1MHz. Does any one have any ideas on how to accomplish this? I have a PIC18F252 or PIC16F84A at my disposal. The frequency and wave form ID will be displayed on an LCD screen. Thanks.

Melanie
- 31st October 2005, 09:31
1. You can easily detect the frequency by measuring the time between two (or more for greater accuracy) consecutive positive transitions. Or by counting pulses in a set time period (the greater the period, the greater the accuracy).

2. Assuming just a Digital I/O is available to you (such as with a 16F84), the ON period TIME will differ for SINE, TRIANGLE and SQUARE. This difference for each of the three waveforms will be a constant proportional to frequency. If your waveform isn't symetrical, then you'll have to use a little additional hardware to invert the negative going half-cycle and have the PIC measure that too. A little math to perform a sum and mean will then give you your figures to determine the waveform type.

How can you visualise what I am talking about? Get some graph or kiddie math paper (one square per number!). Draw a Square Wave, Sine Wave and a Triangle Wave where one positive-going half-cycle covers five squares high and five squares wide. Let's assume the vertical scale is one volt, and the PIC switches ON at say 1.25v (one and a quarter squres up) and draw a line across the graph. Assume everything above that line is ON, and everything below is OFF. You can immediately see that the ON time is different for each waveform, but it will always be proportional to the frequency.

Your PIC doesn't need to measure with any great accuracy, as long as it can differentiate between the three. If you chose a PIC with comparators, you can set the switching point at a level where differentiation between the three waveforms is most marked (say around 4v) and there is minimum margin for error and greatest margin to account even for sloppy programming. Then it's a simple matter just to say (for example) if the ON time > 80% it has to be SQUARE, if it's > 0 but < 20% it has to be TRIANGLE, otherwise it's SINE. Actually, a couple of Resistors or a POT will achieve this on any PIC without needing Comparators.

Acetronics2
- 31st October 2005, 09:49
Hi, Mel

You also can identify wave those wave forms by deriving them ( dU/dT ...) during the positive and ascending part

: the squarewave derived = 0
: the triangle wave derived = constant <> 0
: the sine wave derived = ...cosine > always changing value, but <> 0

just an idea ... for simple waveforms !!!

Alain

Melanie
- 31st October 2005, 09:57
Sure Alain, but you'll need to use a PIC with an ADC and take multiple readings... I wouldn't like to do that with a PIC (even one running at 40MHz) trying to measure a 1MHz waveform (which is what the original question was about). If you have an ADC, it would be easier to filter the signal (R and C), to charge the Cap and measure the voltage on it (kinda PWM D/A Convertor approach). With the correct value of R, you should get SQUARE at Vmax, TRIANGLE at < V50%, and SINE somewhere above TRIANGLE but below SQUARE.

Acetronics2
- 31st October 2005, 10:19
Of course Mel,

in fact, the question is : constant freq. or not ???

Alain

INaPickle
- 31st October 2005, 14:52
I'd like to start out by saying thanks to all who have replied to my post!!! Everyone has contributed invaluable information to help me solve some problems. As for the frequency, it will remain constant throught the testing period, I should have mentioned that (Sorry). Maybe after I get it working, I'll take it a step further. Comments?

INaPickle
- 31st October 2005, 14:53
I'd like to start out by saying thanks to all who have replied to my post!!! Everyone has contributed invaluable information to help me solve some problems. As for the frequency, it will remain constant throught the testing period, I should have mentioned that (Sorry). Maybe after I get it working, I'll take it a step further. Comments?

INaPickle
- 1st November 2005, 17:38
Please be patient, this is my first PIC project and I have many stumbles/crashes ahead of me.

500KHz to 1MHz FREQUENCY COUNTER & WAVE FORM IDENTIFIER

Please refer to attached schematic (Don’t laugh!!!), I know I need to start using some sort of design software (suggestions welcome).
See posts for problem statement; I’ll not repeat it here.

OK, let me walk you through the thought pattern for the circuit attached:

1.Set a Vref of ~4v on pin 5. This will be linked as a trigger to pin 13 CCP1, telling timer 3 to turn on and off at +4V (following the wave form).

2.Pin 11 RC0, will be used to calculate the frequency and will be linked to timer1.

3.Pin 13 CCP1, is used to compare the waveforms with their pre-determined waveform time values for sin, triangle, and square waves. Uses timer 3.

4.LCD Screen, 4 bit. First line to display the frequency and second line to display the waveform ID.

So, will this work or am I way off base?
I prefer to work with a correct circuit before I attempt the programming learning curve.
Thanks

INaPickle
- 6th November 2005, 07:13
OK, it doesn't look as though this project will become a reality. What a shame, I felt it was worth the effort. I can't determine if it is the circuit or the program, I even tried to dumb it down and just go for the frequency range reading only, NO luck! If anyone would like to help with any of the circuit or programming stuff just reply, and I'll evaluate it. Thanks

Acetronics2
- 6th November 2005, 09:49
Hi, Pickles

<< I have many stumbles/crashes ahead of me.>> absolutely right !!!

I think you've forgotten an input circuit ...as PIC 0/1 states specs are not exactly the values Mel gave you for shape detect ...

Second problem ... that don't work for a 1:2 input freq range ... need to mesure the freq. before looking for the waveform ...

Alain