Searching \ for 'Sine' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=sine
Search entire site for: 'Sine'.

No exact or substring matches. trying for part
PICList Thread
'SINEWAVE OUT OF PWM'
1995\09\21@065452 by *DO_LATER

flavicon
picon face
I am currently doing a project and would like to know if it is
possible to generate a sinusoidal analogue waveform using the PWM on
the PIC16C74. I would also like to know if it is possible to generate
a quadrature pair of sinusoids.


'ITU programmers? In business?'
1996\05\02@182907 by Eric T. Brewer
flavicon
face
Hi folks,

I have been trying to call ITU all day today and their phone has been
busy. There Fax line is busy as well. Their web page is till working...
Don't know what's up? Anyone else know?

Based upon a couple of old mails to the list, I am intereseted in buying
one for a client. Are they still good? Has anyone had problems?

thanks,
eric

1996\05\03@090605 by Odriozola Belden

flavicon
face
I've been using an ITU programmer and had no trouble. The only thing that
bothers me is that I learned to use the ASPIC that came with it and nobody
else seems to use it, or am I wrong ? Almost all the source code examples
you find in the net comes in another asembler. Anyway its an easy change
from one to the other.

Rogerio


At 03:20 PM 2/05/96 -0700, you wrote:
{Quote hidden}

1996\05\03@092848 by Norm Cramer

flavicon
face
I also have the ITU programmer and it works great.  I hve only used it to
program the 16C84 at this point.

I have the ASPIC assembler but use MPASM since it is available free from
Microchip.

Norm

At 08:04 AM 5/3/96 -0500, you wrote:
>I've been using an ITU programmer and had no trouble. The only thing that
>bothers me is that I learned to use the ASPIC that came with it and nobody
>else seems to use it, or am I wrong ? Almost all the source code examples
>you find in the net comes in another asembler. Anyway its an easy change
>from one to the other.
>
>Rogerio
>

1996\05\03@102015 by chris
flavicon
face
Eric,

We are very much still in business!  If you are still having problems
contacting us today, please send e-mail directly to me.

Thanks for your interest in our products!
----------------------------------------------------------------------
Chris B. Sakkas (spam_OUTchrisTakeThisOuTspamitutech.com)  http://www.itutech.com
ITU Technologies (.....infoKILLspamspam@spam@itutech.com)    ftp://itutech.com
*** Complete PIC programming packages starting at only $39! ***
*** VISA and MasterCard accepted     (513) 574-7523         ***

1996\05\03@145441 by David E. Queen

flavicon
face
At 08:26 AM 5/3/96 -0500, you wrote:
>I also have the ITU programmer and it works great.  I hve only used it to
>program the 16C84 at this point.
>
>I have the ASPIC assembler but use MPASM since it is available free from
>Microchip.
>
>Norm
>
>At 08:04 AM 5/3/96 -0500, you wrote:
>>I've been using an ITU programmer and had no trouble. The only thing that
>>bothers me is that I learned to use the ASPIC that came with it and nobody
>>else seems to use it, or am I wrong ? Almost all the source code examples
>>you find in the net comes in another asembler. Anyway its an easy change
>>from one to the other.
>>
>>Rogerio
>>
>
So, is it generally accepted that a newbee like me would be better off learing
with MPASM? Does MPSAM work well with the ITU unit and does anyone use the pair?

1996\05\03@155628 by Martin J. Maney

flavicon
face
On Fri, 3 May 1996, David E. Queen wrote:

> So, is it generally accepted that a newbee like me would be better off learing
> with MPASM? Does MPSAM work well with the ITU unit and does anyone use the
pair?

I dunno, sounds like a religious issue.  :-)  Yes and yes.

1996\05\03@170712 by Norm Cramer

flavicon
face
At 02:56 PM 5/3/96 -0500, you wrote:
>On Fri, 3 May 1996, David E. Queen wrote:
>
>> So, is it generally accepted that a newbee like me would be better off
learing
>> with MPASM? Does MPSAM work well with the ITU unit and does anyone use the
> pair?
>
>I dunno, sounds like a religious issue.  :-)  Yes and yes.
>
>

Well it is sort of a religious issue but there are good reasons to use
MPASM.  Mainly since most people use it, code examples from the list can be
used directly.  Also assembler help is easyer to find.  It runs as a Windows
application not as a dos shell.  I am sure there are more but these are
enough for me.  In fact the first one is enough for me.

Norm

1996\05\03@204702 by Steve Budde

flavicon
face
>> So, is it generally accepted that a newbee like me would be better off
>learing
>> with MPASM? Does MPSAM work well with the ITU unit and does anyone use the
> pair?
>
>I dunno, sounds like a religious issue.  :-)  Yes and yes.
>
>
I use both the MPASM compiler and the ITU PIC-1 programmer.  I am extremely
happy with both of them (but I wish their new programmer, that handles all of
the PICs was out at the time I bought mine)

One thing, the MPASM is great because it is free.  And, as several others
have mentioned, most of the code examples both on this list and in all of
the app
notes are aimed toward this compiler. This makes it much easier to start
learning how to program these little goldmines.

I initially bought my programmer for using on my senior project this semester.
We used a 16C65, and had no trouble with using the programmer (even through
a dos window within Windows 95). The kit was easy to build, and had the
whold thing working in about an hour.

So from my limited experience anyway, I would recommend using MPASM, and using
an ITU programmer.  I have used the PROMATE programmer, and was happy with
it, but for a poor student like me, I could not afford one.  I have also
used a Tribal Microsystems programmer, which programmed just about
everything under the sun......but about twice the price of PROMATE.

anyway, my $.02

Steve
--
Steve Budde
e-mail: sbuddespamKILLspamsiu.edu
WWW:    http://www.silug.org/~budde
        http://www.prairienet.org/~sbudde

1996\05\04@014133 by David E. Queen

flavicon
face
At 04:04 PM 5/3/96 -0500, you wrote:
>At 02:56 PM 5/3/96 -0500, you wrote:
>>On Fri, 3 May 1996, David E. Queen wrote:
>>
>>> So, is it generally accepted that a newbee like me would be better off
>learing
>>> with MPASM? Does MPSAM work well with the ITU unit and does anyone use the
>> pair?
>>
>>I dunno, sounds like a religious issue.  :-)  Yes and yes.
>>
>>
>
>Well it is sort of a religious issue but there are good reasons to use
>MPASM.  Mainly since most people use it, code examples from the list can be
>used directly.  Also assembler help is easyer to find.  It runs as a Windows
>application not as a dos shell.  I am sure there are more but these are
>enough for me.  In fact the first one is enough for me.
>
>Norm
>
I guess there are no Windows 95 issues or you would have said something.

1996\05\06@090059 by Norm Cramer

flavicon
face
At 12:46 AM 5/4/96 -0500, you wrote:
>>
>I guess there are no Windows 95 issues or you would have said something.
>

I have been running the programmer in a DOS window under Windows 95 without
any problems.


'62.5 Hz sine wave'
1996\10\29@101626 by Shawn Ellis
flavicon
face
Hey all, this will be the first real problem I have presented this list and
I hope SOMEONE can come through for me.

Buttering up aside, I have a 12-bit DAC (AD737) interfaced to a PIC16C74.
I'm useing the PCW "C" compiler from CCS.  I am trying to build a
ultra-stable AC synchronious motor driver.  So I have a sine wave
represented as a 160-point data set that I generated with a basic program
and imported into my code as an array.  This data-set represents one half of
one period of the sine wave.  The PIC sends each value in the set out to the
DAC and at the end of the set subtracts the numbers from half scale to
produce the negative part of the period, then the whole thing loops.  The
PIC is looking at a 20Khz, 90% duty cycle ttl square wave that comes from
the PWM module.  This square wave also updates the DAC.  The result should
be a 62.5 Hz, +5VDC to -5VDC sine wave coming out of the DAC.  The PIC loads
the new DAC value only after seeing the DAC get updated by the 20 Khz pulse
and then waits for the next DAC update before loading the next number.  The
DAC update is then fed into an APEX high voltage amp to produce a large sine
wave.

The problem is that the resulting sine wave is really 62.52 Hz (5 us too
fast).  I have used several different sources for the 20Khz update pulse
with no change in performance so I don't think that could be the problem.

The device this control is intended for needs stability better than +/- 1us.
(Thats less than +/- 1us per revolution at 62.5 Hz)
Right now we are running it with a 62.5 hz ttl square wave, being fed into
an inverting amplifier, then a transformer to produce a +/- 60 V square wave.

Anybody have any suggestions on:
1. What could this problem be?
2. Is there a better/easier way to achieve an ultra-stable sine wave?
3. Is there a ultra-stable motor-driver I can buy ready-made?
4. Is there another solution besides a synchronious motor that could provide
a more stable rotation at these speeds?

I hope there's someone out there smarter than me!

Shawn

1996\10\29@111509 by Martin J. Maney

flavicon
face
On Wed, 30 Oct 1996, Shawn Ellis wrote:

> The problem is that the resulting sine wave is really 62.52 Hz (5 us too
> fast).  I have used several different sources for the 20Khz update pulse
> with no change in performance so I don't think that could be the problem.

I can't see offhand how the system described could be causing this error,
especially if you've used an external clock source.  I wonder if you have
a problem caused by the measurement technique?  If you're measuring the
period of a single cycle, you may be seeing the effect of a bit of
hysteresis in the input conditioning.  Well, it's a thought.

1996\10\29@114157 by Shawn Ellis

flavicon
face
>I can't see offhand how the system described could be causing this error,
>especially if you've used an external clock source.  I wonder if you have
>a problem caused by the measurement technique?  If you're measuring the
>period of a single cycle, you may be seeing the effect of a bit of
>hysteresis in the input conditioning.  Well, it's a thought.
>
Well, I've used the frequency counter on a fluke oscilliscope but the
ultimate sign of error is the time between activations of an optical sensor
I have looking at a hole in a wheel attached to the motor is 5 microseconds
too fast.
Also bear in mind that the 62.5 Hz square wave I described before runs this
same setup at the correct frequency, but with more acceleration/deceleration
variences than I'd like.

1996\10\29@162722 by Scott Dattalo

face
flavicon
face
Shawn,

You might want to check out some simple sine wave theory:

http://www.interstice.com/~sdattalo/technical/theory/sinewave.html

And an implementation with a PIC:

http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

These may give you a couple of more ideas.


I realize that "generating" your sine wave is not necessarily
the problem. From your description, it sounds as though if there
is a timing problem. Specifically, you're generating 320 samples
for a 62.5Hz sine wave, which translates to 1/62.5/320 = 50us
per sample. This means you need to update the DAC exactly once
every 50us. And I assume that you're synchronized to the 20kHz
PWM output to achieve this update rate. Is it possible that your
crystal is too fast? (62.52-62.5)/62.5 ==> 0.032% error is not
much error.


This problem is solvable by adding more precision to your
frequency variable. Currently, I assume every 50us you automatically
increment some kind of "frequency" variable to access the next
location in the sine wave table:

f = f + 1;   /* Increment at each sample */
if f>=160 then ... rollover/reverse

However, instead of incrementing by exactly 1.000, you could do
something like so:

f = f + 1 + eps;   /* Increase f at each sample */

where |eps| << 1. (way less than, not shift left by)

In your case, if the problem really is a fast crystal, then eps
will be 0.00032. So that after 160 samples, spaced 99.968us
apart (fast crystal) f will rollover at:

 160 (1 + eps) * 99.968us = 62.5 times per second

The down side is that now you must (perhaps must is too strong)
interpolate between entries in the sine table array.

There are scaling issues that greatly simplify the problem of
dealing with floating point numbers. Furthermore, the scaling
can be designed such that you can take advantage of roll-over
arithmetic. I'll elaborate if this is not too clear.


I've used a variation of this technique for phase-locking to a
60Hz frequency before. There I used 20bits of resolution in the
phase increment.

Scott

1996\10\29@164342 by Beacham, Bill HSD

flavicon
face
From: owner-piclist
To: Multiple recipients of list PICLIST
Subject: 62.5 Hz sine wave
Date: Wednesday, October 30, 1996 10:09AM

Hey all, this will be the first real problem I have presented this list and
I hope SOMEONE can come through for me.

Buttering up aside, I have a 12-bit DAC (AD737) interfaced to a PIC16C74.
I'm useing the PCW "C" compiler from CCS.  I am trying to build a
ultra-stable AC synchronious motor driver.  So I have a sine wave
represented as a 160-point data set that I generated with a basic program
and imported into my code as an array.  This data-set represents one half of
one period of the sine wave.  The PIC sends each value in the set out to the
DAC and at the end of the set subtracts the numbers from half scale to
produce the negative part of the period, then the whole thing loops.  The
PIC is looking at a 20Khz, 90% duty cycle ttl square wave that comes from
the PWM module.  This square wave also updates the DAC.  The result should
be a 62.5 Hz, +5VDC to -5VDC sine wave coming out of the DAC.  The PIC loads
the new DAC value only after seeing the DAC get updated by the 20 Khz pulse
and then waits for the next DAC update before loading the next number.  The
DAC update is then fed into an APEX high voltage amp to produce a large sine
wave.

The problem is that the resulting sine wave is really 62.52 Hz (5 us too
fast).  I have used several different sources for the 20Khz update pulse
with no change in performance so I don't think that could be the problem.

The device this control is intended for needs stability better than +/- 1us.
(Thats less than +/- 1us per revolution at 62.5 Hz)
Right now we are running it with a 62.5 hz ttl square wave, being fed into
an inverting amplifier, then a transformer to produce a +/- 60 V square
wave.

Anybody have any suggestions on:
1. What could this problem be?
2. Is there a better/easier way to achieve an ultra-stable sine wave?
3. Is there a ultra-stable motor-driver I can buy ready-made?
4. Is there another solution besides a synchronious motor that could provide
a more stable rotation at these speeds?

I hope there's someone out there smarter than me!

Shawn

............................................................................
.........

The 62.5 hz wave is a 16 ms signal. With 160 points, this corresponds to
100us resolution. If you are interrupt driven this should not be a problem.
I would wonder, however, that since you are only 5 us off, what about the
time effect of the code that is executed after the interrupt is received.
The delay in code, if equal for all points, would shift the waveform equally
for the first and last point, resulting in no error. If you have a decision
process in the code that is different netween the first and last point, then
one or the other could be shifted. I'm new to the PIC arena so I don't know
what timing is consumed for each instruction but 5 us doesnt sound like much
- Perhaps only a few instructions could account for the error.

Good luck

1996\10\29@191620 by Steve Hardy

flavicon
face
> From: Shawn Ellis <.....sellisKILLspamspam.....MERC.RX.UGA.EDU>
> >I can't see offhand how the system described could be causing this error,
> >especially if you've used an external clock source.  I wonder if you have
> >a problem caused by the measurement technique?  If you're measuring the
> >period of a single cycle, you may be seeing the effect of a bit of
> >hysteresis in the input conditioning.  Well, it's a thought.
> >
> Well, I've used the frequency counter on a fluke oscilliscope but the
> ultimate sign of error is the time between activations of an optical sensor
> I have looking at a hole in a wheel attached to the motor is 5 microseconds
> too fast.
> Also bear in mind that the 62.5 Hz square wave I described before runs this
> same setup at the correct frequency, but with more acceleration/deceleration
> variences than I'd like.
>

I'm in a very analogue mood today, so I would suggest feeding your
existing square wave into an analogue band pass centred on that freq.
I don't think the motor would notice a little 3rd harmonic distortion.
If the motor still runs fast you definitely have a problem in your measuring
equipment.

Certain analogue filters will also give sine _and_ cosine output, which
could be put to good use generating a nice rotating magnetic field:
two coils angled at 90 deg to each other.  Stick a permanent magnet
inside this and voila - a synchronous motor.

Regards,
SJH
Canberra, Australia

1996\10\29@220202 by Gerhard Fiedler

flavicon
face
At 10:09 30/10/96 -0500, Shawn Ellis wrote:
>The problem is that the resulting sine wave is really 62.52 Hz (5 us too
>fast).  I have used several different sources for the 20Khz update pulse
>with no change in performance so I don't think that could be the problem.
>...
>1. What could this problem be?
>2. Is there a better/easier way to achieve an ultra-stable sine wave?

You might try to check your sine wave output synchronized to your 20kHz
input (a counter does this very well), this might tell you whether the
precision of the input frequency is your problem.

And you can reduce the number of your points to the half -- did you ever
notice that the second half of your half sine wave is exactly the first half
in reversed order? With half the points you go forth and back, then negative
forth and back...

1996\10\30@010421 by dfr

flavicon
face
Shawn Ellis wrote:

> The problem is that the resulting sine wave is really 62.52 Hz (5 us too
> fast).  I have used several different sources for the 20Khz update pulse
> with no change in performance so I don't think that could be the problem.

Just some thoughts on this one...

The error is not really 5us. Note that 50(62.52-62.5)=1, which implies
that an additional cycle is added every fifty seconds (3125 cycles).
Also note that 3125*320=1,000,000. Hmmmm. The sine table is being
advanced an extra position once every 1,000,000 sync cycles.

Are you also running an ISR at the same time, and possibly
over-correcting the table pointer?

If the 62.52Hz figure is accurate then the above numbers look
significant to me. Revealing their meaning is another matter.

Hope this serves as food for thought.

Regards, Dana Frank Raymond

1996\10\30@090406 by Shawn Ellis

flavicon
face
>
>Certain analogue filters will also give sine _and_ cosine output, which
>could be put to good use generating a nice rotating magnetic field:
>two coils angled at 90 deg to each other.  Stick a permanent magnet
>inside this and voila - a synchronous motor.
>
Interesting suggestion, let me clarify by saying the motor I'm using is a
Globe model with 3 coils at 120 Deg. apart.

1996\10\30@090615 by Shawn Ellis

flavicon
face
>
>And you can reduce the number of your points to the half -- did you ever
>notice that the second half of your half sine wave is exactly the first half
>in reversed order? With half the points you go forth and back, then negative
>forth and back...
>
I tried that at first, but the PIC had to make too many decision that way
and I had trouble doing everything before the next update pulse.(50us)  And
I'm already running at 20 Mhz!

The main time-eater is the fact that I half to keep track of and load three
different DAC's for three different phases of the motor. (0, 120, 240)

1996\10\30@091853 by Shawn Ellis

flavicon
face
>
> The 62.5 hz wave is a 16 ms signal. With 160 points, this corresponds to
>100us resolution. If you are interrupt driven this should not be a problem.
>I would wonder, however, that since you are only 5 us off, what about the
>time effect of the code that is executed after the interrupt is received.
>The delay in code, if equal for all points, would shift the waveform equally
>for the first and last point, resulting in no error. If you have a decision
>process in the code that is different netween the first and last point, then
>one or the other could be shifted. I'm new to the PIC arena so I don't know
>what timing is consumed for each instruction but 5 us doesnt sound like much
> - Perhaps only a few instructions could account for the error.
>
>Good luck
>
I wish that were the problem, but the DAC's all update on an independent 20
Khz square wave no matter what the cod is doing.  I just have to get the
value intot the DAC's regesters before the update pulse...  And I can't see
that taking to long, since I've timed it by fliping a bit before and after
the loads and watched this on the 'scope with the 20 Khz and it seemed to be
happening well within the 20 Khz

1996\10\30@092311 by Shawn Ellis

flavicon
face
At 02:23 PM 10/29/96 -0800, you wrote:
{Quote hidden}

Good suggestion!  But I've never done that sort of math before...  also
things don't really point to the 20 Khz since I already tried an independent
update pulse coming from a counter in a computer sitting on my desk and the
results were EXACTLY the same.  I also tried three different 20 Mhz crystals
in the PIC prduceing the 20 Khz, with no change... So I can only assume this
frequency is correct.

1996\10\30@214233 by Steve Hardy

flavicon
face
> From: Shawn Ellis <EraseMEsellisspam_OUTspamTakeThisOuTMERC.RX.UGA.EDU>
>
> >[SJH wrote:]
> >Certain analogue filters will also give sine _and_ cosine output, which
> >could be put to good use generating a nice rotating magnetic field:
> >two coils angled at 90 deg to each other.  Stick a permanent magnet
> >inside this and voila - a synchronous motor.
> >
> Interesting suggestion, let me clarify by saying the motor I'm using is a
> Globe model with 3 coils at 120 Deg. apart.
>

Motor theory is one of the many things I'm ignorant of.  Do these
3-coil motors have a permanent magnet rotor?  3-phase AC motors have an
inductively coupled 'squirrel cage' rotor which would slip relative to
the rotating field if non-zero torque was applied.  I presume this is
the same for those small single phase 'synchronous' motors used to
drive tape recorder capstans etc.  I presume for a permanent magnet
rotor, it will stay in lockstep with the rotating field, with a varying
lag depending on the required torque.

Anyway, now I see why analogue filtering of a single square wave wasn't
satisfactory for you, since you need three phases.  Since your clock is
20KHz, it needs to be divided by 320 to get the 62.5Hz fundamental.
Rather than using the PIC to generate 3 sine waves, how about using it
to divide the 20KHz by 320, producing 3 square wave outputs 120 degrees
apart.  The three square waves are fed into separate filters tuned to
the same frequency (62.5Hz).  Unfortunately, 320 is not divisible by
3.  You can get around this in several ways:
       . Use the PIC to interpolate.
       . Use a PLL to multiply the 20KHz up to 60KHz, and use this as
         the clock.
       . Just don't worry: use phase spacing of 107, 107 and 106 cycles.
In the latter case, the worst case angular error of the field vector
will be of the order of 12 minutes of arc.  This would probably be
better than the accuracy at which the field coils were placed.  Of
course you would have to ensure there is no torsional resonance at
harmonics of the rotational speed in any case.

Another technique may be to use phase shift networks to produce
successive phase lags of 120 degrees.  This may have the advantage of
being able to tweak the outputs for maximum smoothness of the
rotation.  If you used a 320-count shaft encoder (Litton, HP etc.) you
could compare the 20KHz output from the encoder with the clock signal -
use an XOR gate which would show up any speed difference as a varying
PWM, or the PIC could count the encoder pulses to derive an error
signal.  The possibilities are endless.  Good luck.

Regards,
SJH
Canberra, Australia

1996\10\30@234943 by dfr

flavicon
face
Shawn Ellis wrote:

> Well, you'll be interested to know that I tried putting a check in my code
> and at every 3125 th data point, I held all the indexes back one point.
> This worked!  But is very bad for stability since the wave jumps by one data
> point every 50 secs.  Now if only I could figure out why that happens or how
> to spred that one point across 3125 points...

Its one of those "gotta be there" kind of problems. In previous messages
you mentioned that you are running your PIC at 20Mhz. As well, you
stated that you are measureing the 62.52Hz at the spindle. This is what
I would do:

1) Verify that my frequency counter is not the source of there error.

2) Measure the frequency of the sine waves themselves as the mechanical
elements of the system may be converting instantaneous error (glitches)
into a smooth frequency error.

3) Use a logic analyser (with a large memory) to log all values written
into the 3 DACs over a long period of time. Analyze the data for
discontinuities or other instantaneous errors. Veryify that the output
frequency (not the spindle RPS) is in fact in error.

4) Verify that worst case timing meets minimum spec at all times.

5) Ensure that the 20Khz sync signal does not contain any noise or
sloppy transition delays (slew rate, etc).

6) Examine the CCS code for errors or funnies. I've had to do this for
other PIC C compilers, though I have no experience with recent CCS
versions.

7) Ensure that the CCS produces code that DISABLES interrupts, not just
IGNORES them. What about peripherals unused and THOUGHT to me inactive?

8) Post the code for public comment. (there may be non-disclosure issues
here).

I can't think of anything else.

Happy hunting shawn.

--
Regards, Dana Frank Raymond

1996\10\31@041724 by fastfwd

face
flavicon
face
Shawn Ellis <PICLISTspamspam_OUTMITVMA.MIT.EDU> wrote:

> things don't really point to the 20 Khz since I already tried an
> independent update pulse coming from a counter in a computer
> sitting on my desk and the results were EXACTLY the same.  I also
> tried three different 20 Mhz crystals in the PIC prduceing the 20
> Khz, with no change... So I can only assume this frequency is
> correct.

Shawn:

Is there a chance that you're not really sending exactly the number
of DAC values that you think you are?  Maybe you're "doubling-up" on
one of your lookup-table values?

You can check this by replacing all the sine values in your lookup
table with alternating full-scale (FF or whatever) and zero-scale
(00) numbers, then look at the resulting output square wave and see
if any double-wide pulses or gaps are generated.

-Andy

Andrew Warren - @spam@fastfwdKILLspamspamix.netcom.com
Fast Forward Engineering, Vista, California
http://www.geocities.com/SiliconValley/2499

1996\10\31@042354 by Bjarne Nebelong

flavicon
face
Shawn,

I think that I want to bother you with some vector theory that I am using on
a three phase generator that I made for a costumer (in a 87C749, sorry).

You got three coils and the current in these can only go in two directions:

           Coils           I
           ____
       ---|____|---    -->    <--
           ____
       ---|____|---    -->    <--
           ____
       ---|____|---    -->    <--

This gives only six possibilities. i.e. with 3-bits you can control a rotation.

                                  uvw
                 A             A: 100     1=Current + to -
               _____           B: 110     0=Current - to +
            F /     \ B        C: 010
             /       \         D: 011     Count A-F-A-F... gives clockwise dir.
             \       /         E: 001     Count F-A-F-A... gives the other dir.
            E \_____/ C        F: 101
                 D

With the above table you got a rotation in only six values, six corner vector.
The problem with this is that the corners is rather long from a perfect
circle, it gives overmagnetisation there (harmonic distortion), this is
solved by adding corners:

         A
       _____ B
            \__A
               \
                \B
                 \
This gives 18 corners, that are suitable for most situations. I can provide
you with that table if you want. (48 steps)

If you want to control the output voltage, with your sinewave you change the
amplitude, you have to switch to a non "currentfloating" mode, 000 or 111.
Intelligent stopping means that you select the one that only change one bit
to do the stop. i.e.:
       100     ->      000
       110     ->      111
       010     ->      000
       011     ->      111
       001     ->      000
       101     ->      111

This can be done with a trianglewave, a comparator and the reference. I use
the PWMoutput on the MCU that got a built in comparator. Input the
comparator output in a MUX 74HC157:

       u ----> A1       Y1 ----> U
       v ----> B1       Y2 ----> V
       w ----> C1       Y3 ----> W

 stopbit -+--> A2
          +--> B2
          +--> C2

    STOP ----> Select A/B

    stopbit 1 if 111
            0 if 000

       STOP 1 = stop (from comparator or PWM output)
            0 = RUN

I am doing this outside the MCU becouse the timing is essential here, no
time for IRQ.

To control the output stage you need the complement:
                  uvwuvw
          UVW     +++---
       A: 100     100011
       B: 110     110001
       C: 010     010101
       D: 011     011100
       E: 001     001110
       F: 101     101010
                               +
               _________________________________
               |               |               |
            b  |c           b  |c           b  |c
       u+ ---|<        v+ ---|<        w+ ---|<
               |e              |e              |e
               |               |               |
               +-- L1          +-- L2          +-- L3
               |               |               |
            b  |c           b  |c           b  |c
       u- ---|<        v- ---|<        w- ---|<
               |e              |e              |e
               |_______________|_______________|
                               -

You will also nead some kind of deadtime generator, but I suppose that you
got that already.

Hope you got some help out of this, feel free to contact me if you nead more.

Best regards and good luck.

Bjarne Nebelong
_____________________________________________________________
 Bjarne Nebelong      Internet : KILLspamb.nebelongKILLspamspamhelsingborg.se
 nebelong systems  Phone & Fax : +46 42 12 82 21
 Wrangelsgatan 25       Mobile : +46 70 579 05 50
 25440 Helsingborg, SWEDEN
______--_--__-__--_____-__-__-_-_-__-__-_-_-__--_-___-_______


'Running a Consulting Business'
1996\12\12@053341 by fastfwd
face
flavicon
face
Dudes:

I really don't want to spend too much time discussing this topic on
the list, but the following may be helpful to anyone contemplating
going into my line of work.

There's a guy here on the list (he just lurks, though... I think
he's posted exactly ONE message) who taught me what I think are the
three most important things you need to know about running an
engineering-consultation business.

Aside from his sure-fire way of knowing exactly WHEN and BY HOW MUCH
to adjust your rates for inflation, which I won't describe until I
get his permission (and maybe not even then, since it's sorta
embarrassing to admit that I set my rates that way), he told me:

   1.  When an engineer who's only done garage-type development
       tells you how long it'll take him to perform some task,
       multiply it by two and bump the unit of time to the
       next-larger convenient measure.

       Example:

           I ask an eager but inexperienced engineer how long it'll
           take him to change a resistor value on his schematic.  He
           says thirty seconds.

           I multiply thirty by two and get sixty, then bump the
           units from seconds to minutes... I come up with sixty
           minutes, which is about what it'll REALLY take him by
           the time he's made the change to his schematic, printed
           it, checked it, noticed that he forgot to update the
           revision level, bumped the rev, printed it again,
           checked it again, looked up the new part number and made
           the change to the BOM, and informed the PCB designer and
           anyone else who needs to know.

       This works on big projects, too... Witness the recent
       back-and-forth list discussions regarding the time that it
       takes to do an "average" PIC project.  One guy says 2 weeks;
       the next says 4 months.

   2.  Take only:

       a) interesting jobs, from
       b) nice people who
       c) have money.

       Once you're established and have a reputation, you'll be
       offered more work than you can handle... There's no reason,
       at that point, to settle for anyone who doesn't meet all
       three of the above-mentioned criteria.

       When you're first starting out, of course, you may have to
       take some uninteresting jobs... But don't waste your time
       working for anyone who fails the "nice people" or "has
       money" tests.

-Andy

=== Andrew Warren - RemoveMEfastfwdTakeThisOuTspamix.netcom.com                 ===
=== Fast Forward Engineering - Vista, California          ===
===                                                       ===
=== Custodian of the PICLIST Fund -- For more info, see:  ===
=== http://www.geocities.com/SiliconValley/2499/fund.html ===


'Measuring frequency of sine wave'
1997\01\07@082724 by Stephen Brown
flavicon
face
Hi,

I'm interested in measuring the frequency of a pretty clean sine wave
(output from a switched cap (not to narrow bandwidth) bandpass filter)
using a 16c84. This is for a musical instrument tuning
application. Presumably I would need a 0-5v square wave coming into the
pic for a frequency counter routine. Any ideas on the best way to
convert a sine wave to a square wave for this purpose
(e.g. comparator, overdriven amplifier, PLL)? I played around with a
LMC568 PLL circuit to lock onto the sine wave signal and output a
pulse train, it works but the problem is that the lock in frequency
range for this device is +-60% of the center frequency -- too narrow
for this application. Ideally, I need to be able to handle a bit more
than an octave above and below 440 Hz (i.e. about 200Hz-1000Hz). The
CD4046 ??  PLL chip can be configured for a much wider range, but it
is my understanding that it needs a square wave input itself (am I
wrong?). The nice thing about these PLL things is that they can create
a logic signal indicating when they are locked onto a frequency signal
-- i.e. they can tell you when a valid input is there.

Anyway, any hints would be appreciated.

Steve Brown

spamBeGonesbrownspamBeGonespamned.ara.com
TakeThisOuTbrownsEraseMEspamspam_OUTsover.net

1997\01\07@085640 by BLEGER

flavicon
face
    Steve,

    How about this for simplicity:

    Rectify the sine wave with a diode, then use a zener diode and
    resistor to limit the voltage to logic levels (approx 0 to 4 volts)
    then use a schmidt trigger to clean up the edges of the waveform.
    This assumes the sine wave is high enough. If not it can be amplified
    with a trasistor or op amp.

    In__|\|___
        |/|  /
             \ R        |--------|
             /__________|Schmidt |_______ Out
             |          |Trigger |
             __/ Zener  |Logic IC|
            //\         |--------|
              |
              |
             ///Ground


______________________________ Reply Separator _________________________________
Subject: Measuring frequency of sine wave
Author:  pic microcontroller discussion list <RemoveMEPICLISTspamTakeThisOuTMITVMA.MIT.EDU> at smtp
Date:    1/7/97 8:29 AM


Hi,

I'm interested in measuring the frequency of a pretty clean sine wave
(output from a switched cap (not to narrow bandwidth) bandpass filter)
using a 16c84. This is for a musical instrument tuning
application. Presumably I would need a 0-5v square wave coming into the
pic for a frequency counter routine. Any ideas on the best way to
convert a sine wave to a square wave for this purpose
(e.g. comparator, overdriven amplifier, PLL)? I played around with a
LMC568 PLL circuit to lock onto the sine wave signal and output a
pulse train, it works but the problem is that the lock in frequency
range for this device is +-60% of the center frequency -- too narrow
for this application. Ideally, I need to be able to handle a bit more
than an octave above and below 440 Hz (i.e. about 200Hz-1000Hz). The
CD4046 ??  PLL chip can be configured for a much wider range, but it
is my understanding that it needs a square wave input itself (am I
wrong?). The nice thing about these PLL things is that they can create
a logic signal indicating when they are locked onto a frequency signal
-- i.e. they can tell you when a valid input is there.

Anyway, any hints would be appreciated.

Steve Brown

sbrownEraseMEspam.....ned.ara.com
EraseMEbrownsspamsover.net

1997\01\07@094353 by efoc

flavicon
face
Stephen Brown wrote:
{Quote hidden}

Why not simply drive it into a schmitt trigger inverter



Peter .......
--
==================================
= New Ideas come from those who  =
= didn't know it wasn't possible =
==================================

1997\01\07@120416 by Stuart Allman

flavicon
face
try measuring the zero crossings.  It seems to work for other projects I
have seen.

Stuart Allman
RemoveMEstudioTakeThisOuTspamspamhalcyon.com

1997\01\07@171208 by peter

flavicon
face
Stephen Brown wrote:
>
> Hi,
>
> I'm interested in measuring the frequency of a pretty clean sine wave
> (output from a switched cap (not to narrow bandwidth) bandpass filter)
> using a 16c84. This is for a musical instrument tuning
> application. Presumably I would need a 0-5v square wave coming into the
> pic for a frequency counter routine. Any ideas on the best way to
> convert a sine wave to a square wave for this purpose
> (e.g. comparator, overdriven amplifier, PLL)?

just use an opamp overdriven,
this will give you a nice square wave to feed the pic, you'll
probably find you don't need to use the filter

Alternately you could try an opamp conected
to a diode conected to a zener conected to a schmitt
conected to an inverting schmitt conected to
the washing machine

--
Peter Cousens
email: EraseMEpeterspamspamspamBeGonecousens.her.forthnet.gr
snailmail: Peter Cousens, karteros, Heraklion, Crete, 75100, Greece,
phone: + 3081 380534,    +3081 324450   voice/fax

After Bill Gates announced to the world that he was Microsoft,
his wife was asked to comment. She said that as his wife, she
had been the first to notice this problem

1997\01\07@191658 by n Medical Technologies

flavicon
face
Stephen Brown wrote:
{Quote hidden}

To convert a Sine wave to a square wave, you could use either a
single-supply comparator or op-amp.  A bit of hysteresis would be good.
Actually, depending on the amplitude of the sine wave, the best and
simplest bet might simply use a CMOS Schmitt Trigger.

I haven't used a PLL in a bunch of years, so I've forgotten how to do
this. Sorry.

Al Cohen
Boston Medical Technologies

1997\01\08@022456 by Oyvind Kaurstad

flavicon
face
Stephen Brown wrote:

{Quote hidden}

You could do this:

Take two resistors (100k for instance) and use them for
a voltage divider from your 5v and to ground.
This will give you half the supply voltage.
Feed this into the comparator. (Either input)
Make a similar voltage divider for the other comparator input
and couple your sine wave to this input using a proper
capacitor (0.1 uF will do). This will DC shift (and high-pass filter)
your incoming signal to half the supply voltage. Cut-off frequency of
the filter will be at approx 30 Hz. The comparator will give you
a nice square wave. You will probably not need any hysteresis since you
have a clean input signal.

-Oyvind         spamBeGoneoyvindSTOPspamspamEraseMEnofac.abb.no


'PIC as controller for sinewave inverter - magic si'
1997\02\03@071245 by Mike
flavicon
face
Hi gals and guys,

I'm looking (again) at feasability of using HC11 architecture as controller
for sine-wave inverters 48V DC in for 240V AC out 50Hz and 5000VA.

Now after being exposed to PICs - I'm considering using a PIC with built
in A to D...

Although I have most experience with 8051 architecture, it seems that the
HC11 with OTP would be a more viable solution in terms of usability
of programming model and level of integration - thats an option but, can
anyone care to suggest a suitable PIC for such a task ?

There has been some discussion in various hobby magazines about 'magic
sinewaves' in 384 bit sequences - anybody know about these or the
background maths etc - I was going to look at Taylor's series etc to
produce the HC11 table constants but there might be a more efficient way ?

I'm interested in any +ve/-ve comments/observations on this...

Rgds


Mike
KILLspamerazmusspamBeGonespamwantree.com.au

There is no a'priori reason that the ultimate truth will be interesting
or even useful, those moments of frustration during philosophical debate
would be replaced by the sheer terror which accompanies true knowledge.

1997\02\03@191707 by Dave Mullenix

flavicon
face
Mike wrote:

>There has been some discussion in various hobby magazines about 'magic
>sinewaves' in 384 bit sequences - anybody know about these or the
>background maths etc - I was going to look at Taylor's series etc to
>produce the HC11 table constants but there might be a more efficient way ?
>
>I'm interested in any +ve/-ve comments/observations on this...

Don Lancaster has written about "magic sinewaves".  Don has a homepage at

http://www.tinaja.com/

Enter the Reference Library, then the Magic Sinewaves Shelf and find this blurb:

                              Don  Lancaster's
                           Magic Sinewave Library

         "Magic sinewaves" are repeating long sequences of ones and
         zeros.  Digital sinewaves with precisely controlled amplitudes
         and amazingly low distortions.

         Compared to traditional PWM, magic sinewaves can offer far
         higher efficiencies and lower distortions. With circuitry that is
         elegantly simple and microcontroller friendly.  For use in such
         applications as induction motor speed controls, electric autos,
         solar panels, power factor correction, inverters, home energy
         efficiency improvers, and specialized utility services.

         There are more magic sinewaves than there are particles in the
         universe. Only recently have specialized analysis tools become
         available. Don Lancaster, Synergetics, and several Synergetics
         Partners are in the forefront of this billion dollar opportunity.

         Extensive seminars, consulting, sourcecode, tutorials, and a new
         Partners program are now being offered.


These files are available for downloading:

Magic Sinewave Development Proposal.
Formal proposal outlining seminars, partners, and services.
A wide range of opportuinities and possibilities are listed,
along with full references.

Blatant Opportunist #35  MAGSINE.PDF (*)
Magic sinewaves are a brand new method of driving ac induction
motors, solar panels, inverters, or electric cars. Offer ing outstanding
simplicity and efficiency. Introductory Don Lancaster tutorial.

Blatant Opportunist #37  EMERGOP4.PDF (*)
Fourth annual release of emerging technical opportunities.
Push me pull you. The TeraHertz mystery band. PIC microcontollers.
Magic Sinewaves. Solitons. DNA computing. Binary chain codes.

Bionomial Goes Binary ONESWORD.HTML *
A PostScript utility to generate all possible binary words of length
"n" having "k" ones in them. Use for magic sinewaves and exploration
of the binomial theorm. Requires two way recordable com.

An analysis of Magic Sinewave Higher Harmonics.
Just where do those square corners come from on a low harmonic
waveform? Jim Fitzsimons analyzes the first 999 (!) harmonics
of five typical 384 bit non-delta magic sinewaves.

Demo sampler of 288-Bit Magic Sinewaves.
A detailed analysis pf a few of the 288-bit "delta Friendly"
magic sinewaves. There are 49 amplitudes in the complete
288 sequence, having distortions as low as 0.01 percent.

Tech Musings #101  MUSE101.PDF ( June 1996 )
Using Delta-Wye transforms, Professional audio resources,
Acrobat amber beta software, Building your own Tesla coil,
Three phase magic sinewaves, more.

Tech Musings #93  MUSE93.PDF ( October 1995 )*
More on magic sinewaves, stepper motor driver chips, yet
another patent horror story, mid range Mench computer, a
collection of PCMCIA plug-in card resources.

Tech Musings #90  MUSE90.PDF ( July 1995)*
Fourier Series analysis, alternatives to plated through holes,
classic computer resources, a $200 GPS receiver, Newtek's
new video toaster for Windows.

Hardware Hacker #87  HACK87.PDF  (April 1995 )*
AC motor drive fundamentals. New Basic Stamps from Parallax.
PIC Microcomputer resources. Additional details on forced zero
magic sinewaves. Dealing with "too good to be true" results.

Hardware Hacker #86  HACK86.PDF  (March 1995 )*
The DNA computer language. Some wavelet book resources.
Magic digital sinewave codes. Engineering economics review.
Hot new fringe FM RBDS tuner.

1997\02\03@194411 by Steve Hardy

flavicon
face
{Quote hidden}

So-called 'magic sinewaves' seem to be a pet subject of a bloke
called Don Lancaster.  The actual mathematics to generate the
sequences is not in the public domain; however there are a few
published sequences of length 384 and above - look at his web
page.  I'm not sure about this, but I think it is possible to
patent algorithms in the US.  However, you can't in Australia so
if you can discover his algorithm for yourself there would be
nothing to stop you commercially develping products in Oz.

Basically, there are an infinite number of PWM sequences which will
generate 'sine waves' with a greater or lesser harmonic content.
The aim of 'magic sinewaves' is to minimise (or even zero) the first
n harmonics, such that the first non-zero harmonics will be at a
very high frequency and thus easy to filter using an LC low-pass
power filter.  The complete cycle (20ms) is divided into fixed
time slots (20ms/384).  Each slot is then assigned an output voltage
of +V, 0 or -V.  Naturally, because of the 4-fold symmetry of a sine
wave only one quadrant of the sine wave needs to have table entries.
The power of the fundamental (which is what you want) is proportional
to the total number of +V slots (= the number of -V).

The mathematical technique is based on Fourier analysis (not
Taylor series, AFAIK).

If you need to regulate the output, you can presumably narrow the
utilisation of the +/-V slots.  Thus you would aim for 50% duty cycle
(of the slot) for no-load output, allowing this to rise to 100%
for full load.

As it so happens, I am currently designing a 6KW inverter, except
that I am using rectified 3-phase as the power source (giving about
580V avg).  The DC (with 4.2% ripple) is switched by a full bridge
of MOSFETs using opto-isolated control.  Control will be provided
by a 16C74 - primarily because I have a few of these floating around.
The '74 will be used to monitor voltage and current (current being
crudely measured from the voltage drop across the MOSFETs Rds(on)).
It will also determine frequency of operation and PWM sequencing.
Might also add temperature sense.

One of the most difficult things about controlling 600 odd volts at
50KHz is the tremendous dV/dt (those FETs switch fast!) which will
couple through the tiniest capacitance to potentially disrupt ones
delicate control circuitry.  I am having to build up my own
opto-isolators and isolated power supplies.  Total capacitance has to
be limited to 0.2pF, otherwise currents of over 1mA will be induced
(6000V/us).

I would be interested in your overall converter topology.  Please
correspond privately since this is wildly off-topic.

Regards,
SJH
Canberra, Australia

1997\02\04@111945 by Brian Boles

flavicon
face
    Before you go for that HC11, check out the 17C756 that will be
    sampling soon.  It will "out motor" a HC11!

    Rgds, Brian.


______________________________ Reply Separator _________________________________
Subject: PIC as controller for sinewave inverter - magic sinewaves
Author:  Mike <@spam@erazmus@spam@spamspam_OUTWANTREE.COM.AU> at Internet_Exchange
Date:    2/3/97 8:10 PM


Hi gals and guys,

I'm looking (again) at feasability of using HC11 architecture as controller
for sine-wave inverters 48V DC in for 240V AC out 50Hz and 5000VA.

Now after being exposed to PICs - I'm considering using a PIC with built
in A to D...

Although I have most experience with 8051 architecture, it seems that the
HC11 with OTP would be a more viable solution in terms of usability
of programming model and level of integration - thats an option but, can
anyone care to suggest a suitable PIC for such a task ?

There has been some discussion in various hobby magazines about 'magic
sinewaves' in 384 bit sequences - anybody know about these or the
background maths etc - I was going to look at Taylor's series etc to
produce the HC11 table constants but there might be a more efficient way ?

I'm interested in any +ve/-ve comments/observations on this...

Rgds


Mike
spamBeGoneerazmusspamKILLspamwantree.com.au

There is no a'priori reason that the ultimate truth will be interesting
or even useful, those moments of frustration during philosophical debate
would be replaced by the sheer terror which accompanies true knowledge.

1997\02\04@113613 by Mike

flavicon
face
At 09:04 AM 4/02/97 -0700, you wrote:
>     Before you go for that HC11, check out the 17C756 that will be
>     sampling soon.  It will "out motor" a HC11!
>
>     Rgds, Brian.

Sounds OK, I checked it out on microchip's site, nice chip.

Might have a bit more horsepower than I need, can I get it for A$9 each
in tube lots and the assembler for free ?

Rgds

Mike

1997\02\05@205411 by sdattalo

face
flavicon
face
Mike wrote:
>
> There has been some discussion in various hobby magazines about 'magic
> sinewaves' in 384 bit sequences - anybody know about these or the
> background maths etc - I was going to look at Taylor's series etc to
> produce the HC11 table constants but there might be a more efficient way ?
>

I don't believe in magic. I know for a fact that this routine
efficiently generates sine waves with 8-bit resolution:

http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

And so does Eric Smith's:

http://www.brouhaha.com/~eric/pic/sine.html

And if you want to examine a few more ways to possible
generate sine waves then check out:

http://www.interstice.com/~sdattalo/technical/theory/sinewave.html



Scott

1997\02\09@131012 by Sten Dahlgren

flavicon
face
For all of you interested in PIC's and power inverter, check out there web
site
for the RD001 paper, "Uninterupptible Power Supply Reference Design".
---
Sten Dahlgren  CelsiusTech Systems   ! "I'd rather have 39 Hp under my arm
S-175 88 Jaerfaella      Sweden            ! than one under my backside"
.....sedaspam_OUTspamcelsiustech.se +46-8 58084430  ! join your nearest karting club now !!

1997\02\09@151012 by peter

flavicon
face
Sten Dahlgren wrote:
>
> For all of you interested in PIC's and power inverter, check out there web
> site
> for the RD001 paper, "Uninterupptible Power Supply Reference Design".
> ---
> Sten Dahlgren  CelsiusTech Systems   ! "I'd rather have 39 Hp under my arm
> S-175 88 Jaerfaella      Sweden            ! than one under my backside"
> TakeThisOuTseda.....spamTakeThisOuTcelsiustech.se +46-8 58084430  ! join your nearest karting club now !!

Which web site are you refering to ??
--
Peter Cousens
email: TakeThisOuTpeterKILLspamspamspamcousens.her.forthnet.gr
snailmail: Peter Cousens, karteros, Heraklion, Crete, 75100, Greece,
phone: + 3081 380534,    +3081 324450   voice/fax

After Bill Gates announced to the world that he was Microsoft,
his wife was asked to comment. She said that as his wife, she
had been the first to notice this problem

1997\02\10@000947 by Mike

flavicon
face
At 07:09 PM 9/02/97 +0100, you wrote:
>For all of you interested in PIC's and power inverter, check out there web
>site
>for the RD001 paper, "Uninterupptible Power Supply Reference Design".
>---
>Sten Dahlgren  CelsiusTech Systems   ! "I'd rather have 39 Hp under my arm
>S-175 88 Jaerfaella      Sweden            ! than one under my backside"
>.....sedaspamRemoveMEcelsiustech.se +46-8 58084430  ! join your nearest karting club now !!

Which web site are you referring to - here ?

Rgds

Mike

1997\02\11@121200 by Zack Cilliers

flavicon
face
Hi there!

Can some one send me some more information as how the sinewave can improve
on a squarewave.

thanks

----------
{Quote hidden}

way ?
{Quote hidden}

1997\02\12@180550 by sdattalo

face
flavicon
face
Zack Cilliers wrote:
>
> Hi there!
>
> Can some one send me some more information as how the sinewave can improve
> on a squarewave.
>
> thanks

Zack,

Are you asking how the sinewave can be generated from the square wave?
Well, if you aren't then I'm answering the wrong question...

A couple of weeks ago John Payson and I were discussing some details
on how it is possible to suppress the 2nd and 3rd harmonics in a
sampled square wave. This led me on an analytical rabbit chase that
turns out to be the inverse of the so called "magic sine wave".
Skipping over the details, let me just pull a formula out of
my magic hat. Suppose you have a very narrow duty cycle pulse train:

^
|      tau
|     <---->
|
|     +----+                        +----+
|     |    |                        |    |
-+-----+    +------------------------+    +--------->
                                                   t
  phi
<----->
      <-------------- T ------------>

In other words, if you have a pulse stream that has
a frequency of 1/T, pulse widthes of tau, and an
initial phase of phi, then one (of an infinite many)
series expansion is:

f(t) = d +

     inf
    ----
    \    sin(n*pi*d)      / n*2*pi        tau        \
 2* /    ----------- * cos| ------ *( t - --- - phi) |
    ----    n*pi          \   T            2         /
    n=1

where,
d = tau/T is the duty cycle
pi = 3.141592653...
t = time

For 50% duty cycles, you may recall that there are no
even harmonics present in the fourier series. So as one
simple check, you can substitute d=0.5 and see that the
sin(n*pi/2) kills the even harmonics in this parameterized
expansion.

The goal of the magic sinewaves is to suppress many if not
all of the harmonics beyond the fundamental. This can be
accomplished by chopping the period into many fine pieces;
in other words, let tau<<T. Mike made a reference to there
being 384 divisions. Now if you strategically place these
narrow pulses among the 384 possible slots, it's possible
to suppress higher harmonics.

The technique of finding the optimum placement is far
from trivial. However, here are few helpful observations.

The fundamental frequency is 1/T.

If the  number of subdivisions is N (i.e. tau = T/N) then
1) Harmonics that evenly divide N/2 can be totally suppressed.
2) If the n'th harmonic is suppressed then the N-n'th is
also suppressed.
3) To suppress the 2nd through the n'th harmonic at least
2^(n-1) pulses are needed.

As an example, if you wanted to suppress the 2'nd, 3'rd and
4'th harmonics then the number of needed subdivisions is
N = 2*3*4 = 24
Out of the 24 possible pulses, 2^(4-1) = 8 pulses are needed.
(And if I had my notes, I would tell you where these optimum
pulse positions are located). In addition to suppressing
these harmonics, the 20'th, 21'st and 22'nd are also
suppressed. The fifth harmonic is not completely suppressed.

There is also a 1/n factor that will attenuate those harmonics
that are not suppressed. However for small n, the sin(n*pi*d)/n*pi
is approximately n*pi*d/(n*pi) = d. So the 1/n factor only
becomes important for larger values of n.

There are many, many more details that I'm ignoring...


Scott

1997\02\14@131742 by sdattalo

face
flavicon
face
This is my second time to send this to the list. The first time
apparently didn't make it. (At least it was not in this month's
log.)

Zack Cilliers wrote:
>
> Hi there!
>
> Can some one send me some more information as how the sinewave can improve
> on a squarewave.

I believe the context of your question is WRT power inverters? In which
case the sine wave drive is lethal to the switching devices. The so
called "magic sine waves" is a glitzy synonym for pulse width
modulation.
(O.k. there's a little more to it than PWM, but the underlying theory is
identical.) And PWM is the proper technique for driving many these
devices.


A couple of weeks ago John Payson and I were discussing some details
on how it is possible to suppress the 2nd and 3rd harmonics in a
sampled square wave. This led me on an analytical rabbit chase that
turns out to be the inverse of the so called "magic sine wave".
Skipping over the details, let me just pull a formula out of
my magic hat. Suppose you have a very narrow duty cycle pulse train:

^
|      tau
|     <---->
|
|     +----+                        +----+
|     |    |                        |    |
-+-----+    +------------------------+    +--------->
                                                   t
  phi
<----->
      <-------------- T ------------>

In other words, if you have a pulse stream that has
a frequency of 1/T, pulse widthes of tau, and an
initial phase of phi, then one (of an infinite many)
series expansion is:

f(t) = d +

     inf
    ----
    \    sin(n*pi*d)      / n*2*pi        tau        \
 2* /    ----------- * cos| ------ *( t - --- - phi) |
    ----    n*pi          \   T            2         /
    n=1

where,
d = tau/T is the duty cycle
pi = 3.141592653...
t = time

For 50% duty cycles, you may recall that there are no
even harmonics present in the fourier series. So as one
simple check, you can substitute d=0.5 and see that the
sin(n*pi/2) kills the even harmonics in this parameterized
expansion.

The goal of the magic sinewaves is to suppress many
of the harmonics beyond the fundamental. This can be
accomplished by chopping the period into many fine pieces;
in other words, let tau<<T. Mike made a reference to there
being 384 divisions. Now if you strategically place these
narrow pulses among the 384 possible slots, it's possible
to suppress higher harmonics.

The technique of finding the optimum placement is far
from trivial. However, here are few helpful observations.

The fundamental frequency is 1/T.

If the  number of subdivisions is N (i.e. tau = T/N) then
1) Harmonics that evenly divide N/2 can be totally suppressed.
2) If the n'th harmonic is suppressed then the N-n'th is
also suppressed.
3) To suppress the 2nd through the n'th harmonic at least
2^(n-1) pulses are needed.
4) It is possible to suppress all of the even harmonics.
This is accomplished by an pulse train that is followed
by it inverse. For example, if you had a traing of pulses
like 011000 the even harmonics are suppressed by the
doubled chain: 011000100111.


To illustrate, suppose you wanted to suppress the 2'nd and
the 3'rd harmonics. The number of needed subdivisions is
N/2 = 2*3 = 6
or N = 12
Out of the 12 possible pulses, 2^(3-1) = 4 pulses are needed.
And their locations are:

 101101000000
(actually any cyclic rotation of this stream works).

In addition to suppressing the 2'nd and 3'rd harmonics, the
10'th and 11'th are also suppressed. The fourth harmonic is
not completely suppressed. If you wanted to suppress the
4'th or all of the even harmonics for that matter, then
the following pulse stream would do the trick:

 original
<---------->
101101000000010010111111
           <---------->
             inverted from the original

There is also a 1/n factor that will attenuate those harmonics
that are not suppressed. However for small n, the sin(n*pi*d)/n*pi
is approximately n*pi*d/(n*pi) = d. So the 1/n factor only
becomes important for larger values of n.

There are many, many more details that I'm ignoring...


Scott

1997\02\15@160058 by Sten Dahlgren

flavicon
face
----------
> From: Peter Cousens <TakeThisOuTpeterspamspamcousens.her.forthnet.gr>
> To: PICLISTEraseMEspamMITVMA.MIT.EDU
> Subject: Re: PIC as controller for sinewave inverter - magic sinewaves
> Date:  den 10 februari 1997 07:09
>
> Sten Dahlgren wrote:
> >
> > For all of you interested in PIC's and power inverter, check out there
web
> > site
> > for the RD001 paper, "Uninterupptible Power Supply Reference Design".
> > ---
> > Sten Dahlgren  CelsiusTech Systems   ! "I'd rather have 39 Hp under my
arm
> > S-175 88 Jaerfaella      Sweden            ! than one under my
backside"
> > RemoveMEsedaEraseMEspamspam_OUTcelsiustech.se +46-8 58084430  ! join your nearest karting club
now !!
>
> Which web site are you refering to ??

Sorry, I was a little bit faster than i should be. It is http://www.microchip.com

Note also that it is already in it's b version as i discovered thursday.

1997\02\15@191005 by Dmitry Kiryashov

flavicon
face
Scott Dattalo wrote:

[some tech details skipped]
{Quote hidden}

While i've read this i've thinking - "May be exist reverse technique ?"
For example we have an input digitized signal ( only logical "1" and "0"
sequence).
And we want to detect some fundamental frequencies in this stream while
harmonics
should not have influence on result of detection. Are there some way to
apply
that magic sinewaves technique reversly i.e. not for synthesis but for
detection ?
I think there are ability in use simultaneosly magic waves and
correlation techniques
to achieve cutting harmonics in each correlation sum (in DTMF detection
for example).
I hope that i have not speak some nonsense ;)

And second question - what happen in case when we take into account N =
odd value,
i.e. not 384 but for example 385 or 383 pieces ?

WBR Dmitry.

1997\02\17@145839 by sdattalo

face
flavicon
face
Dmitry Kiryashov wrote:
>
>
> While i've read this i've thinking - "May be exist reverse technique ?"
> For example we have an input digitized signal ( only logical "1" and "0"
> sequence).
> And we want to detect some fundamental frequencies in this stream while
> harmonics
> should not have influence on result of detection. Are there some way to
> apply
> that magic sinewaves technique reversly i.e. not for synthesis but for
> detection ?

Yes. But unfortunately there are some practical problems...

> And second question - what happen in case when we take into account N =
> odd value,
> i.e. not 384 but for example 385 or 383 pieces ?

Well for starters, it's not theoretically possible to suppress all of
the even harmonics if N is an odd value (recall N is the number of
subdivisions of the fundamental frequency; ie. if the fundamental
frequency is f=1/T, then the time resolution for pulse transitions
are limited to the time quanta T/N.) Pushing theory aside however,
it is possible to come fairly close to suppressing the even harmonics.
And with a little magic, it's possible to suppress a large subset
of the lower harmonics.

Think about how you would generate a pulse stream that could be
low-pass filtered to generate a sine wave. Intuitively, you might
expect to have some sort of frequency modulated square wave. When the
the frequency is "low" the filter has a large output and when the
frequency is "high" the filter has a small output. Your intuition
may further lead you to this equation:

g(t) = (1 + sign(A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t)) )/2

This dual tone signal (which for the context of our current
discussion has nothing to do with DTMF) consist of two harmonically
related sinusoids:

f2 = m*f1

f1 is the frequency of the fundamental waveform that we wish
to synthesize (e.g. DTMF generation) or detect (DTMF decoding).
f2 is a much high frequency that can be easily filtered with
our low pass filter.

The sign() function returns the sign of its arguement. Loosely
speaking, it's the mathematical function of a comparator. The
rest of the equation for g(t) shifts the DC offset so we have
a stream of 1's and 0's.

There's a simple way to see what this function is doing. Imagine
that the lower frequency sinusoid's amplitude, A1, is twice the higher
one. When the low frequency cosine is passing through zero, there
are many zero crossings in the higher frequency cosine. For every
zero crossing, there is a corresponding pulse transition. Now as
the lower frequency cosine approaches it's peak, the higher frequency
cosine at some point will no longer be able to cause the sum (of
the sinuoids) to change signs.

Here's another way to see what's happening. If the amplitudes A1
and A2 are equal then the sum can be expressed as a product:
 sum = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t)
     = A1*(cos(2*pi*f1*t) + cos(2*pi*f2*t))
     = 2 * A1 * cos(pi*(f1+f2)*t) * cos(pi*(f1-f2)*t))
Which is seen to be one cosine wave being modulated by another.


Now to address Dmitry's question. So far we've made no assumption
about the sampling rate. But it's sort of obvious that the faster
we can generate the pulse stream the easier it will be to filter
the high frequency components. If it's not obvious, then please
take my word for it.

I haven't investigated the case for there being an odd number of
samples per T1 (=1/f1). I can only speculate that it might induce
a subharmonic oscillation. There are two reasons. First, the phases
of the cosine waves could be such that every other cycle differs
by one extra pulse. The frequency of this extra pulse is 1/2 the
frequency of the fundamental (f1). Thus the introduction of the
subharmonic. Secondly, if you take the odd number of samples and
multiply it by two you get an even number of samples that is
twice as long. Using the same theory as above, it's then possible
to generate a sine wave of half the frequency of f1. And as we
all know from O.J., if it's remotely possible then we can assume
it as true.


One more point. Think about what happens when the relative amplitudes
of the cosines are varied. For example looking at just the extremes:
if A1>>A2 then g(t) is a low frequency square wave and the low pass
filter's output will have a large output.
if A1<<A2 then g(t) is a high frequency square wave and the low pass
filter's output will have a small output.
The actual output will be somewhere between these two.

One more point. Amplitude control of the synthesized sine wave can
be traded off for harmonic supression.

Scott


'Magic Sine waves'
1997\03\16@021208 by James and Iliana
flavicon
face
       Me again.
       I have a lead on a possible commercial application of Magic Sine waves a
s
I understand them. Does anyone know where I can get information on them ??
I realize that information of this type is not free.
       Correct me if I'm barking up the wrong tree. A company needs to vary the
speed of some AC motors. Toshiba says that thier controller will not work
in this situation. Long cable run and high voltage. They said the "
Harmonics " would not allow thier controller to work. If I understand Magic
Sine Waves, using them can eliminate most of the harmonics thus allowing
the control of the motors. The company is paying DEARLY for some
controllers now..
       Any info is greatly appreciated.

----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

1997\03\16@051156 by Mike

flavicon
face
>        I have a lead on a possible commercial application of Magic Sine
waves as
>I understand them. Does anyone know where I can get information on them ??
>I realize that information of this type is not free.
>        Correct me if I'm barking up the wrong tree. A company needs to
vary the
>speed of some AC motors. Toshiba says that thier controller will not work
>in this situation. Long cable run and high voltage. They said the "
>Harmonics " would not allow thier controller to work. If I understand Magic
>Sine Waves, using them can eliminate most of the harmonics thus allowing
>the control of the motors. The company is paying DEARLY for some
>controllers now..
>        Any info is greatly appreciated.



Have a look at the addenda, by the way I would be interested in how you
progress,
I was looking at magic sinewaves recently and also about 2 years ago. But in
both
cases other jobs came up :(

I think its a great idea but, needs a lot of work, in basic theory and
practice in
implementation etc.

Rgds

Mike

--------------------------- Addenda ----------------------------------

Don Lancaster has written about "magic sinewaves".  Don has a homepage at

http://www.tinaja.com/

Enter the Reference Library, then the Magic Sinewaves Shelf and find this blurb:

                              Don  Lancaster's
                           Magic Sinewave Library

         "Magic sinewaves" are repeating long sequences of ones and
         zeros.  Digital sinewaves with precisely controlled amplitudes
         and amazingly low distortions.

         Compared to traditional PWM, magic sinewaves can offer far
         higher efficiencies and lower distortions. With circuitry that is
         elegantly simple and microcontroller friendly.  For use in such
         applications as induction motor speed controls, electric autos,
         solar panels, power factor correction, inverters, home energy
         efficiency improvers, and specialized utility services.

         There are more magic sinewaves than there are particles in the
         universe. Only recently have specialized analysis tools become
         available. Don Lancaster, Synergetics, and several Synergetics
         Partners are in the forefront of this billion dollar opportunity.

         Extensive seminars, consulting, sourcecode, tutorials, and a new
         Partners program are now being offered.


These files are available for downloading:

Magic Sinewave Development Proposal.
Formal proposal outlining seminars, partners, and services.
A wide range of opportuinities and possibilities are listed,
along with full references.

Blatant Opportunist #35  MAGSINE.PDF (*)
Magic sinewaves are a brand new method of driving ac induction
motors, solar panels, inverters, or electric cars. Offer ing outstanding
simplicity and efficiency. Introductory Don Lancaster tutorial.

Blatant Opportunist #37  EMERGOP4.PDF (*)
Fourth annual release of emerging technical opportunities.
Push me pull you. The TeraHertz mystery band. PIC microcontollers.
Magic Sinewaves. Solitons. DNA computing. Binary chain codes.

Bionomial Goes Binary ONESWORD.HTML *
A PostScript utility to generate all possible binary words of length
"n" having "k" ones in them. Use for magic sinewaves and exploration
of the binomial theorm. Requires two way recordable com.

An analysis of Magic Sinewave Higher Harmonics.
Just where do those square corners come from on a low harmonic
waveform? Jim Fitzsimons analyzes the first 999 (!) harmonics
of five typical 384 bit non-delta magic sinewaves.

Demo sampler of 288-Bit Magic Sinewaves.
A detailed analysis pf a few of the 288-bit "delta Friendly"
magic sinewaves. There are 49 amplitudes in the complete
288 sequence, having distortions as low as 0.01 percent.

Tech Musings #101  MUSE101.PDF ( June 1996 )
Using Delta-Wye transforms, Professional audio resources,
Acrobat amber beta software, Building your own Tesla coil,
Three phase magic sinewaves, more.

Tech Musings #93  MUSE93.PDF ( October 1995 )*
More on magic sinewaves, stepper motor driver chips, yet
another patent horror story, mid range Mench computer, a
collection of PCMCIA plug-in card resources.

Tech Musings #90  MUSE90.PDF ( July 1995)*
Fourier Series analysis, alternatives to plated through holes,
classic computer resources, a $200 GPS receiver, Newtek's
new video toaster for Windows.

Hardware Hacker #87  HACK87.PDF  (April 1995 )*
AC motor drive fundamentals. New Basic Stamps from Parallax.
PIC Microcomputer resources. Additional details on forced zero
magic sinewaves. Dealing with "too good to be true" results.

Hardware Hacker #86  HACK86.PDF  (March 1995 )*
The DNA computer language. Some wavelet book resources.
Magic digital sinewave codes. Engineering economics review.
Hot new fringe FM RBDS tuner.

'Another Magic Sine Wave question'
1997\03\17@011513 by James and Iliana

flavicon
face
Hello All.
       Is there anyone that has used Magic Sine Waves in an application ?? I've
looked at all the data from Don's web site and it sounds like, as he would
call it, " Pseudo Science ". ( maybe because I don't know enough to tell
what is smoke or not ).
       Before I make a fool out of myself ( and spend money that I don't have )
could someone just confirm that they are not smoke and mirrors ??
       Thanks a bunch for your time.

----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

'Magic Sine waves'
1997\03\17@011514 by James and Iliana

flavicon
face
At 06:01 PM 3/16/97 +0800, you wrote:

>
>Have a look at the addenda, by the way I would be interested in how you
>progress,
>I was looking at magic sinewaves recently and also about 2 years ago. But in
>both
>cases other jobs came up :(
>
>I think its a great idea but, needs a lot of work, in basic theory and
>practice in
>implementation etc.
>
>Rgds
>
>Mike
>

Hi Mike,
       I read all the data on the Magic Sine Waves that I could find on his
site.. still confused. I understand the idea. Make your own sine waves
based upon digital signals that are not regular so you eliminate harmonics.
Is there some sort of formula available ?? Is that something that I would
have to pay for ?? I'll send Don some email and see just where he stands
and what is available.
       Thanks for the reply to my post.

----------------------
James and Iliana
Austin Texas
Automotive Technician
Electronics Hobbyist
Software Engineer
----------------------

1997\03\17@034240 by Mike

flavicon
face
At 12:10 AM 17/03/97 -0600, you wrote:
{Quote hidden}

Yes - his formula is written in postscript language.


Is that something that I would
>have to pay for ?? I'll send Don some email and see just where he stands
>and what is available.

Good luck - I tried about 3 times over last 6 months...

Rgds

Mike

Some say there is no magic but, all things begin with thought then it becomes
academic, then some poor slob works out a practical way to implement all that
theory, this is called Engineering - for most people another form of magic.
                                                                      Massen

'Another Magic Sine Wave question'
1997\03\17@053444 by Mike

flavicon
face
At 12:00 AM 17/03/97 -0600, you wrote:
>Hello All.
>        Is there anyone that has used Magic Sine Waves in an application ??

I think that was Don's intention - to raise the capital to produce fully
functioning units as part of a business plan - perhaps with the eventual  aim
of floating the company.


I've
>looked at all the data from Don's web site and it sounds like, as he would
>call it, " Pseudo Science ". ( maybe because I don't know enough to tell
>what is smoke or not ).

It seems very reasonable and real. I see that minor variations in a regular PWM
approach can give improved results:- the 'magic sinewaves' is just a logical
extension of this - well logical in the sense that it is more focused on
producing the bit stream  directly from some formula instead of via some
iterative method - which is likely to be very time consuming indeed !

>        Before I make a fool out of myself ( and spend money that I don't
have )
>could someone just confirm that they are not smoke and mirrors ??

I think is worth while pursuing - but then you would be a fool if you spent
money
you don't have, then that would be a debt you'd be lumbered with ;)

Anyway I think its a worthwhile gamble at least for basic research purposes.

>        Thanks a bunch for your time.

And you get the electrons free :)

Rgds

Mike

Some say there is no magic but, all things begin with thought then it becomes
academic, then some poor slob works out a practical way to implement all that
theory, this is called Engineering - for most people another form of magic.
                                                                      Massen

1997\03\17@112509 by sdattalo

face
flavicon
face
James and Iliana wrote:
>
>         Before I make a fool out of myself ( and spend money that I don't have
)
> could someone just confirm that they are not smoke and mirrors ??

 The "they" being Magic Sinewaves...

The only way you'll make a fool out of yourself is by claiming that
this stuff is Magic. It's not.

I've studied various pulse streams: 12,15,24,36 and was able to
demonstrate the harmonic suppression claimed by Lancaster. I was
unable to come up with a generic formula. However, I have made
several observations and have written a program in MATLAB to
calculate the harmonic content of a given pulse stream. I can
re-post the observations and send a copy of the MATLAB program
to those interested.

Scott

'Magic Sine waves'
1997\03\17@113520 by 71177.202

picon face
James and Iliana wrote:
>
>         Me again.
>         I have a lead on a possible commercial application of Magic Sine waves
as
> I understand them. Does anyone know where I can get information on them ??

Try Don Lancaster at http://www.tinaja.com.

1997\03\22@221442 by Michael S. Hagberg

flavicon
face
i recall someone asking about magic sine waves, and ran accross
an article in June 1995, Circuit Cellar. check it out.

michael


'Programmable Sinewave Generator'
1997\04\07@192538 by kotay
flavicon
face
I remember some discussion on this list a while back about sine
wave generators, so when I saw this info in Electronic Component
News I thought some list members would be interested:

ML2037
DC-500kHz 65536 steps
Frequency programmed via 3-wire SPI interface
Output gain digitally programmed via two external pins
Requires no external components
Manufactured by Micro Linear Corp.
408-433-5200
http://www.microlinear.com

Keith


'Magic Sinewaves'
1997\07\21@143505 by Miller, Steve
flavicon
face
Howdy,

Has anyone used Don Lancaster's magic sinewaves with a PIC?  These binary
strings are supposed to generate sinewaves with very little harmonics.   How
does this technique compare to using an eight bit port and a resistor ladder
arrangement?  (Obvious advantage of  the magic sinewave is that it only requires
one or two output pins.)  (  Link to magic sinewave is http://www.tinaja.com/  )

Another question :  How do I evaluate the harmonic content of a particular
scheme?  I have the student edition of MATLAB and MATHCAD.  (These are not the
current versions, as my student days was a while ago).  Does anyone have a
sample file on how to get MATLAB to calculate this?

Thanks.

------ Steve

1997\07\21@150410 by sdattalo

face
flavicon
face
Miller, Steve wrote:


> Another question :  How do I evaluate the harmonic content of a particular
> scheme?  I have the student edition of MATLAB and MATHCAD.  (These are not the
> current versions, as my student days was a while ago).  Does anyone have a
> sample file on how to get MATLAB to calculate this?

Steve,

Here is the MATLAB program:

% sqseries.m
%
% The purpose of this program is to draw the frequency
% components of a pulse train

% T. Scott Dattalo, 14FEB97

clear; clg;

T = 1;
N = 1000;                 %Number of samples
t = [1:N]/N * T;          %Time vector

%            0   4   8   c   0   4   8   c   0   4   8   c
bitstring = '00000001001101111110110010000000';
[m,P] = size(bitstring);  % Number of pulses in the period of T
bits = zeros(1:2*P);      % double the length
for m=1:P                 % First half is non-inverted
 bits(m) = abs(bitstring(m)) - abs('0');
end
for m=P+1:2*P             % The second half is inverted
 bits(m) = 1-(abs(bitstring(m-P)) - abs('0'));
end
P = 2*P;

phase = [0:(P-1)] .* bits * T/P;

harmonics = 50;
mag = zeros(1:harmonics);
ph  = zeros(1:harmonics);

tau = T/P;
d = tau/T;
sqwave = zeros(1:N);

for n=1:harmonics
 w = n*2*pi/T;
 for m=1:P
   if bits(m) ~= 0
     sqwave = sqwave + 2*sin(n*pi*d)/(n*pi)*cos(w*(t-tau/2-phase(m)));
     mag(n) = mag(n) + 2*sin(n*pi*d)/(n*pi)*cos(w*phase(m));
     ph(n) = ph(n) + cos(w*phase(m));
   end
 end
end

ti = sprintf('SQUARE WAVE');
title(ti)
subplot(211)
plot(t,sqwave)
subplot(212)
plot([1:(harmonics)], mag,'*')


This program will calculate the first 50 harmonics of a repeating
pulse stream. It does this by adding the harmonics of the individual
pulses that build the pulse stream. If you have an arbitrary pulse
stream:

^ v(t)
|      tau
|     <---->
|
A|     +----+                        +----+
|     |    |                        |    |
-+-----+    +------------------------+    +--------->
                                                   t
  phi
<----->
      <-------------- T ------------>


The harmonics of it can be found from:

         infinity
            ----  sin(n*pi*d)       /   2*pi   /     tau       \\
v(t) = d +  \    ------------- * cos|n* ---- * | t - --- - phi ||
            /___     n*pi           \     T    \      2        //
             n=1

If you want to really know the theory then check out the gory
details at:

http://www.interstice.com/~sdattalo/technical/theory/sqwave.html



Scott
--
"Life in two dimensions is a mass production scheme"
                                         Neil Peart


'Dual Sine Waves'
1997\10\31@042844 by Virtual
picon face
Hi, this question is concerning DTMF generation again.  I am not very
experienced with the PIC's and the code that is already out there just
confuses me.  Since a DTMF tone is just the two tones mixed, I would
like to know if its possible for me to make a small program that creates
a sine wave on 2 pins, and then just mix the two together.  I was unable
to find any info on the web about generating sine waves, and how i could
figure out what freq they would be at, also how I would make two at the
same time, one for the lower portion, and one for the upper portion,
each outputting to a seperate pin.  I realize this isn't the best way,
but I think it will help me to learn a little more, jumping to PWM
assembly code just has my mind going in circles  :)

p.s.  I use the 16C84 running off a color burst crystal  (about 3.579275
MHZ)

Thanks a lot
John


'DC level to 1KHz sine wave conversion.'
1998\02\12@124855 by GERRY COX
flavicon
face
My latest project involves a PIC16C73A , which amongst other things,  drives
a serial 16bit DAC. This gives me a control voltage  programmable from 0  to
10V.
I also need to generate a sinewave of nominally 1KHz. The p-p amplitude
must track the DAC voltage and be always 10 percent of its DC  voltage.
It has to be a reasonably clean and stable sinewave.
Input voltage range varies from   0.5 to  10V.
Sine wave output will vary 0 to 1V p-p for the above input range. Accuracy
better than 3%.
Sine wave Total Harmonic Distortion better than 5%
Sine wave frequency accuracy 1Khz +/- 100Hz
Output current 5mA max.
Power supply -  I have +15V, -15V and +5V available.

For example if I have a DC input of 3V the sinewave generator should output
300mV peak to peak at 1Khz.
this 300mV should be accurate to 309mV max or 291 mV minimum.

I am considering an MF10 switched capacitor filter with clock 128 times that
of the 1KHZ output but am looking for ideas

All ideas welcome. Must be reasonably low component count but parts cost is
not paramount for a change!

Regards,
Gerry Cox

1998\02\12@131007 by Peter van Hoof

flavicon
face
did you look into magic sinewaves?
http://www.tinaja.com/magsn01.html
seems pretty interesting to me

Peter

----------
> From: GERRY COX <@spam@gcoxRemoveMEspamEraseMEDEK.COM>
> To: EraseMEPICLISTspam@spam@MITVMA.MIT.EDU
> Subject: DC level  to 1KHz sine wave conversion.
> Date: Thursday, February 12, 1998 12:20 PM
>
> My latest project involves a PIC16C73A , which amongst other things,
drives
> a serial 16bit DAC. This gives me a control voltage  programmable from 0
to
> 10V.
> I also need to generate a sinewave of nominally 1KHz. The p-p amplitude
>  must track the DAC voltage and be always 10 percent of its DC  voltage.
> It has to be a reasonably clean and stable sinewave.
> Input voltage range varies from   0.5 to  10V.
> Sine wave output will vary 0 to 1V p-p for the above input range.
Accuracy
> better than 3%.
> Sine wave Total Harmonic Distortion better than 5%
> Sine wave frequency accuracy 1Khz +/- 100Hz
> Output current 5mA max.
> Power supply -  I have +15V, -15V and +5V available.
>
> For example if I have a DC input of 3V the sinewave generator should
output
> 300mV peak to peak at 1Khz.
> this 300mV should be accurate to 309mV max or 291 mV minimum.
>
> I am considering an MF10 switched capacitor filter with clock 128 times
that
> of the 1KHZ output but am looking for ideas
>
> All ideas welcome. Must be reasonably low component count but parts cost
is
> not paramount for a change!
>
> Regards,
> Gerry Cox

1998\02\12@132225 by John Payson

picon face
> My latest project involves a PIC16C73A , which amongst other things,  drives
> a serial 16bit DAC. This gives me a control voltage  programmable from 0  to
> 10V.
> I also need to generate a sinewave of nominally 1KHz. The p-p amplitude
>  must track the DAC voltage and be always 10 percent of its DC  voltage.

Do you need the control voltage for anything else, or are you just looking
to have a finely-adjusted sinewave amplitude?  If you're trying to produce
an amplitude-adjusted sine wave, one approach you might consider would be
to generate two 1KHz sine waves in different phases (the phase difference
will set the net amplitude).  I don't know exactly how much precision you
could hammer out of a PIC that way, but it should be possible to do pretty
well (I use that trick in my music box, btw).

Alternatively, since your sine wave frequency is fixed, you could probably
use a simple gating circuit to convert your DC signal into a square wave,
and then feed that through a 4 or 5 stage filter.  Since the frequency is
fixed, you could optimize the RC's so as to give the best possible 1-1.5KHz
cutoff and if you use an active feedback filter you could even add some "Q"
to make your sinewaves really gorgeous.

1998\02\12@135532 by peter

flavicon
face
GERRY COX wrote:
>
> My latest project involves a PIC16C73A , which amongst other things,  drives
> a serial 16bit DAC. This gives me a control voltage  programmable from 0  to
> 10V.
> I also need to generate a sinewave of nominally 1KHz. The p-p amplitude
>  must track the DAC voltage and be always 10 percent of its DC  voltage.
> It has to be a reasonably clean and stable sinewave.
> Input voltage range varies from   0.5 to  10V.
> Sine wave output will vary 0 to 1V p-p for the above input range. Accuracy
> better than 3%.
> Sine wave Total Harmonic Distortion better than 5%
> Sine wave frequency accuracy 1Khz +/- 100Hz

Use an LM13700 it's a dual transconductance amp
and tailor made for your app
both as the osc and the attenuator

--
Peter Cousens
email: @spam@peterspam_OUTspam.....cousens.her.forthnet.gr  phone: + 3081 324450, 380534
snailmail:  Folia, Agia Fotini, Karteros, Heraklion  Crete, Greece.

1998\02\12@142236 by Mike Keitz

picon face
On Thu, 12 Feb 1998 17:20:29 -0000 GERRY COX <spamBeGonegcoxEraseMEspamDEK.COM> writes:
>My latest project involves a PIC16C73A , which amongst other things,
>drives
>a serial 16bit DAC. This gives me a control voltage  programmable from
>0  to
>10V.
>I also need to generate a sinewave of nominally 1KHz. The p-p
>amplitude
> must track the DAC voltage and be always 10 percent of its DC
>voltage.
>It has to be a reasonably clean and stable sinewave.
>Input voltage range varies from   0.5 to  10V.
>Sine wave output will vary 0 to 1V p-p for the above input range.

It would go from 0.05 to 1V. if it were linearly controlled.

>Accuracy
>better than 3%.

Why are you using a 16-bit converter then?  A 3% requirement is less than
6 bits of accuracy.

The first thing that comes to mind is to use an 8-bit DAC chip in
multiply mode.  By driving a constant level sinewave into the reference
pin, the output will be a sine wave wiht level varying according to the
digital code input.  Unfortunately most of the DACs only multiply in
2-quadrants (positive voltages), so a DC bias needs to be applied to the
input, causing the DC level at the output to also vary according to the
input code.  Another DAC could be operated to ouptut only the DC level
expected at the output, then (assuming the 2 DACs are balanced) the two
subtracted to leave a sine wave centered around 0 volts.

Another possibility is an analog multiplier.  This is the obvious choice,
though multiplier chips are somewhat expensive (if you already have a
16-bit DAC, this may not be much of an issue).  And you have to come up
with a constant-amplitude sine wave from somewhere to begin with.

One thing that you didn't specify is the time to reach a new amplitude
setting after a change is demanded.  If this is rather slow (100s of ms),
then another realm of possibilities opens up, using feedback.  A
rectifier or amplitude detector would sample the output of the circuit,
and this would be compared to the desired level.  The error voltage would
control some other part of the circuit to set the amplitude.

If the long response time and otherwise poor dynamics are acceptable (the
level isn't changed very often, in other words), I would highly recommend
this method.  The use of feedback makes the amplitude accuracy dependent
only on the sampling detector, reference level source, and error
amplifier.  Variations in other parts of the circuit would automatically
cancel out.

>Sine wave Total Harmonic Distortion better than 5%
>Sine wave frequency accuracy 1Khz +/- 100Hz

Since the frequency only has to be within 10%, a self-oscillating circuit
should work.  Use a filter of relatively high "Q" with feedback from the
output back to the input to make it oscillate.  In the feedback path, put
an adjustable limiter (a diode clamp circuit).  I think it would work to
clamp only one polarity of the signal.  The input to the filter would be
almost a square wave but it would filter to a sine wave.  The clamping
level could be controlled directly (open loop) or through feedback
(closed loop, Automatic Level Control).

A slightly more or maybe less complicated variation on this would be to
generate a variable-level square wave and filter it to a sine wave.  As
with the oscillator circuit, the filter could be either an RC network or
a switched-capacitor filter like an MF10.

>Output current 5mA max.
>Power supply -  I have +15V, -15V and +5V available.

This makes it easy.  Standard op-amps will meet the current
specification.

>I am considering an MF10 switched capacitor filter with clock 128
>times that
>of the 1KHZ output but am looking for ideas

Yes, this is a good start.  It could serve as the 1 KHz sinewave
generator for the multiplier ideas, or filter or oscillate with a varying
square-wave input level.

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

1998\02\12@155810 by Roger Anderson

flavicon
face
I've done similar projects in two different ways.
{Quote hidden}

1998\02\13@082348 by paulb

flavicon
face
GERRY COX wrote:

> I also need to generate a sinewave of nominally 1KHz. The p-p
> amplitude must track the DAC voltage and be always 10 percent of its
> DC  voltage. It has to be a reasonably clean and stable sinewave.

 I'd be very tempted to just use an 8038CC function generator chip.  Or
anything that has subsequently rendered it obsolete.  I'm not sure of
the linearity or voltage range, but an XR2206 may do.

 Cheers,
       Paul B.

1998\02\13@124029 by Wayne Foletta

flavicon
face
Gerry:

Try one of Motorola's or Analog Devices analog multipliers like the
AD633.
For a oscillator and attenuator try National's LM13700.
Try a multipier DAC like Maxim MAX505 and others.
If you want a software solution see http://www.tinaja.com/magsn01.html
for what they call "magic sinewaves" - if you want more details on this
contact me. I was part of the IC design team that produced the first all
digital DTMF chip generators (Comdial Telephone Systems) Patents now
expired and the technology is "as old as the hills" so I can explain and
give details if there is interest.

- Wayne Foletta
BMI - Saratoga, CA

{Quote hidden}


'hel, chip business sell me something :)'
1998\04\06@080525 by sajjad.akhtar
flavicon
face
    Hi,
    I need to purchase some chips in the following categories.
    Anyone who would like to help me. right now i need 1-4 pairs (one from
    each category) for prototyping purpose.


    1______________ 51 compatible processor
       DS5000FP-16
       DS5000fp-8
    2______________ CLID
       ICS1660
       MT88E43
       MT8843
       MT88E41
       MT8841
       MC14457
    3______________ DTMF

       MT8888
       MT8880
       MT8870
       MT3170
       MT3270
       MT3370
    4______________ PWM
       MC33362
       MC33363

    if you know some one who can sell me (i will definitely pay) forward
    me the link or my this letter to him/her. I am in Pakistan and need
    components here but its no way possible then i have one friend in USA
    CO but he will come Pakistan in mid of May/April. But it will be
    appreciated if some one could send me directly.

    If there are more than one option in chip package or other
    specification (for one chip) then the low price will be more welcome.


    send me the response on my email account. ie. .....sajjad.akhterSTOPspamspam@spam@usa.net I
    will check my mail on Friday now.

    thanks in advance


    Sajjad Akhter

    CresSoft Lahore Pakistan


'Free Advertising For Your Business!'
1998\05\23@061948 by n/a
flavicon
face
***Our research indicates that the following material may be of interest to you.

(However, so that we may be courteous, please reply by email with the word "remo
ve" to be immediately removed from further mailings.  You must type "remove".)

Hi,

Just wanted to pass along some info about some new software I now call my "secre
t weapon".  It's truly amazing!  Listen to this...

Me and hundreds of others can now reach "millions of potential  customers, local
ly or worldwide" - absolutely FREE!  A lot of us are creating immediate "cash fl
ow explosions" -literally overnight.  And blowing our competition right out of t
he water!

You have to check this thing out.  To get some details, all you have to do is em
ail a request for more info to tutopiainfoEraseMEspam@spam@hermes1.net and you'll get some infor
mation Email'ed right back to you in a few minutes.  Simple.

Take care.  I'll talk with you later.

Bill :-)

1998\05\24@080124 by Franklin P. York

flavicon
face
Undetermined origin c/o LISTSERV administrator wrote:
>
> ***Our research indicates that the following material may be of interest to yo
u.
>
> (However, so that we may be courteous, please reply by email with the word "re
move" to be immediately removed from further mailings.  You must type "remove".)
>
> Hi,
>
> Just wanted to pass along some info about some new software I now call my "sec
ret weapon".  It's truly amazing!  Listen to this...
>
> Me and hundreds of others can now reach "millions of potential  customers, loc
ally or worldwide" - absolutely FREE!  A lot of us are creating immediate "cash
flow explosions" -literally overnight.  And blowing our competition right out of
the water!
>
> You have to check this thing out.  To get some details, all you have to do is
email a request for more info to RemoveMEtutopiainfospamspamBeGonehermes1.net and you'll get some inf
ormation Email'ed right back to you in a few minutes.  Simple.
>
> Take care.  I'll talk with you later.
>
> Bill :-)
REMOVE


'Sinewave generation'
1998\12\12@075836 by Darren Logan
picon face
Hi Pic'ers,

Anyone know how to generate a sinewave using PWM on say a PIC 12Cxx ?

I want to generate 100Hz (plus or minus 0.1Hz).

Any code will do, i.e. BASIC, C or assembly.

Thanks in advance.

Darren

1998\12\12@103045 by Chris Eddy

flavicon
face
Do you need to have a clean high accuracy sine wave?  You might try
building a simple op amp oscillator, and coupling the PWM signal in as a
sync signal.  Then you get the benefits of a clean wave with a clock
accuracy.  Simply low passing the PWM will surely mash the signal, by the
time you get all of the harmonics out, then you have to adjust it for
height afterwards.

Chris Eddy, PE
Pioneer Microsystems, Inc.

Darren Logan wrote:

{Quote hidden}

1998\12\12@103636 by Quentin

flavicon
face
Read AN 655, It will explain it to you. Best is to use a R-2R ladder with
4 to 8 pins, depending on your aplication. Basically what you do is to
create a lookup table with your sine steps (0 to 255 or 0 to 16)  in it.
Then your programs puts these values in sequence on your output pins. I
recently wrote a small test program that does a 4 bit sine for tone
generation and it worked great. Pity I lost it in a hard drive crash
otherwise I would have posted it to you.

Quentin

Darren Logan wrote:

{Quote hidden}

1998\12\12@191024 by Mike Keitz

picon face
On Sat, 12 Dec 1998 17:35:43 +0200 Quentin <spamBeGoneqscKILLspamspam@spam@ICON.CO.ZA> writes:
>Read AN 655, It will explain it to you. Best is to use a R-2R ladder
>with
>4 to 8 pins, depending on your aplication. Basically what you do is to
>create a lookup table with your sine steps (0 to 255 or 0 to 16)  in
>it.
>Then your programs puts these values in sequence on your output pins.

There are lots of ways to make sine waves, especially at 100 Hz.  A
resistor DAC works OK.  It is better to use a nonlinear resistor network
that is optimized for sine waves.  That trick dates back to very early
days of digital logic.  Five resistors in the ratio 1.5, 3.9, 4.7, 6.8,
and 20 makes a nice 16-sample approximate sine wave.  They are also
standard value resistors.  One end of each rresistor goes to a PIC pin
which is always an output, the other end of all 5 resistors goes to a
common node which is the sine output.  The digital sequence applied tot
he pins is pretty much what a shift register would make (early
implementations did of course use a shift register, but needed a few more
resistors.)

You end up with a "staircase" looking wave that still needs a little
analog filtering before you really can call it a sine.  Often just a
single capacitor to ground will be sufficient.

In the most recent generation of my CTCSS encoders (that is what the guy
who wants a 100 Hz sine wave needs it for, right?), I've used "magic
sine" techniques described by Don Lancaster (http://www.tinaja.com).  Only one
PIC pin is required, it is driven either on or tri-state for each sample
period.  During half of the sine wave, the pin drives high, during the
other half it drives low.  The sampling rate is quite high, hundreds of
samples per output cycle.  The sequence of whether to output a pulse for
each sample is stored in a table.  The table can represent as little as
1/4 of the full wave's samples if you re-use it properly for each
quadrant.  The data in the table is of course one bit for each sample.
The density of "1" bits increases and decreases in a sinusoidal manner.
Lancaster's site has many suitable sequences as well as methods to use to
derive new ones.

An R-C integrator will clean up the pulses to a decent sine wave.  Using
two integrators in series makes a really nice sine wave.  In order to
integrate properly, the integrator neds to be set up so the output
amplitude is much less than VDD (this causes the voltage across the
resistor to be relativley constant during each pulse).  An amplifier may
be needed if a level of more than 0.5Vpp or so is required.  But, the
same sine amplitude can be maintained over a wide range of frequencies
using the same filter if the output pulses are a constant width (i.e.
reduce the frequnecy by increasing a "dead" off-time after each pulse.
Then the energy coupled to the integrator per cycle is the same
regardless of the frequency).

The downside of the "magic sine" is that with 210 or more samples per
cycle it takes a lot more PIC time than a DAC based approach.  I haven't
tried anything with PWM.  I think software PWM would need even more CPU
than magic sine, but on a PIC with PWM hardware it could work well.

Someday I'll put all this on a web page.  For right now I'll just tease
you.


___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

'Sinewave generation - The way to do it with a PIC.'
1998\12\14@130528 by John Bellini

flavicon
face
Suppose you have a PWM available (hardware or software).  You can
generate a varing duty cycle PWM wave form that cycles from something
like 1% to 50%+ and then back down.  You filter this waveform with a
simple RC filter (2 parts) and you get a sine wave.  You can level shift
it if you need to.  You can use a constant ROM look up table, different
tables can give you different output voltage references.  Run the PWM on
an interrupt.  Change the interrupt time to change the frequency.

               {Original Message removed}


'Increase Your Business with Emails!'
1999\01\08@022428 by DR
flavicon
face
<HTML><BODY BGCOLOR="#80ff80"><FONT  COLOR="#800000" SIZE=3 PTSIZE=10><BR>
</FONT><FONT  COLOR="#000000" SIZE=3 PTSIZE=10><B>At the Click of a Button, I Ca
n Send Your Sales Letter<BR>
out to "Millions of Potential Customers"!<BR>
</P><P ALIGN=CENTER><BR>
</FONT><FONT  BACK="#ff0000" SIZE=6 PTSIZE=22>40% DISCOUNT <BR>
ONE WEEK<BR>
SPECIAL TRY IT SALE <BR>
</FONT><FONT  BACK="#FFFFFF" SIZE=3 PTSIZE=10><BR>
</FONT><FONT  SIZE=6 PTSIZE=22>Here's the Fastest Proven Way to </FONT><FONT  CO
LOR="#ff0000" SIZE=6 PTSIZE=22><BR>
Increase Your  Downline or Promote<BR>
Your Home or Online Business</FONT><FONT  COLOR="#000000" SIZE=6 PTSIZE=22> <BR>
<U>Within the Next 24 hours</U>!</FONT><FONT  SIZE=3 PTSIZE=10></B><BR>
</FONT><FONT  COLOR="#800000" SIZE=3 PTSIZE=10><BR>
</P><P ALIGN=LEFT>Dear Business Owner:     <BR>
<BR>
    Are you ready to learn how you can expand your downline or increase your bu
siness in the next week?<BR>
<BR>
<B>RSVP Financial Resources</B> Specializes in increasing your home business. We
mail for over 50 different MLM and Net Working programs. If you don't have the
successful ad WE DO!  We mail for individuals just like you. <BR>
<B><BR>
Global Prosperity, Millionaire Makers, The Ninth Wonder, Amway, Online, Web Winn
ers, The Ad Club, Pantagano, Free Computer, Free Car, Web page, Online Store, al
l the Telephone services and many Others.<BR>
</B><BR>
    Will show you how you can avoid the high cost and long wait of traditional
advertising.<BR>
    Are you interested in blasting your sales letter out to thousands of eager
prospects -- <BR>
<U>all within the next 24 hours</U>?<BR>
<BR>
    If so, I have some very, very exciting news for you!<BR>
<BR>
    Hi, my name is Jerry Greenspan.  I'm a successful Entrepreneur and Direct M
arketing <BR>
Expert. What I'm about to reveal to you can literally skyrocket your sales and p
rofits <BR>
like you never thought possible -- and extremely fast.<BR>
<BR>
</P><P ALIGN=CENTER><B>What I'm talking about is my "Same-Day E-Mail Blasting Se
rvice."</B><BR>
</P><P ALIGN=LEFT><BR>
    Simply put, I have the ability to send your sales letter out to millions of
potential<BR>
customers at the click of a button -- and all within a 24 hour period. This mea
ns you can <BR>
literally <U>explode your business and have a 100 prospects to call in the next
week.<BR>
</U><BR>
    Now look, I'm not talking about sending your offer out to just anyone. I'm
talking about<BR>
blasting your offer out to the freshest and most responsive leads in the indust
ry. My staff <BR>
extracts and buys leads from various secret sources on a daily basis. We clean,
manage and update our database continually. We don't sent to anybody who does no
t want it and we comply with all the recent new laws.<BR>
<BR>
</P><P ALIGN=CENTER>     <B>You Can Rest Assured That When You Order My Service,
Your Ad Will<BR>
Freshest and Most Responsive Leads on the Internet - Period.</B><BR>
</P><P ALIGN=LEFT></FONT><FONT  COLOR="#000000" SIZE=3 PTSIZE=10><BR>
    Remember, I have the ability to send your advertisement out to not just tho
usands, <BR>
but millions of eager prospects -- all within a 24-hour period.<BR>
</FONT><FONT  COLOR="#ff0000" SIZE=3 PTSIZE=10><B><I><BR>
</P><P ALIGN=CENTER>There is no Cheaper or Faster Way to Advertise Your MLM Oppo
rtunity, Your <BR>
Business or Your Product!<BR>
<BR>
THESE ARE 40% DISCOUNTED PRICES<BR>
<BR>
100,000 Only $149.00 (only $1.49 per thousand... WOW!!)</B><BR>
<BR>
<B>250,000 </B>Fresh and Eager Prospects for <B>Only $199.00</B>*<BR>
<BR>
<B>500,000 </B>Fresh and Eager Prospects for <B>Only $349.00*</B><BR>
<BR>
<B>1.0 Million</B> Fresh and Eager Prospects for Only <B>$599.00*<BR>

(only $0.59 per thousand... triple  WOW!!)</B><BR>
* Limit 2 Pages (One short page works the best)<BR>
<B><BR>
    </FONT><FONT  COLOR="#800000" SIZE=3 PTSIZE=10></B></I>
Email your order or questions to:
       </FONT><A HREF="interested200spam_OUTspam@spam@hotmail.com">spamBeGoneQuestions-or-order@spam@spamRSVPFR.com
</A><BR>
<I><BR>
</P><P ALIGN=LEFT>Your E-mail Marketing Friend,<BR>
<FONT  SIZE=4 PTSIZE=12><B>Jerry Greenspan</FONT><FONT  SIZE=3 PTSIZE=10></B></I
>, <BR>
President<BR>
RSVP Financial Resources<BR>(305) 945 9942<BR>
<BR>
    PS If you'd like, you can call me direct Toll Free at (305) 945-9942. I wil
l discuss your program with
and give you the benefit of our company who has mailed over 106 million emails
for others.<BR>
<BR>
</P><P ALIGN=CENTER><BR>
<BR>
</P><P ALIGN=LEFT>(For Office Use Only - Date: 11/24/98- ADA)<BR>
<BR>
</FONT><FONT  BACK="#ff0000" SIZE=3 PTSIZE=10><BR>
</P><P ALIGN=CENTER></FONT><FONT  COLOR="#800000" BACK="#FFFFFF" SIZE=4 PTSIZE=1
2><BR>
</P><P ALIGN=LEFT></FONT><FONT  COLOR="#000000" SIZE=3 PTSIZE=10><BR>
</P><P ALIGN=CENTER><BR>
<BR>
<BR>
<BR>
<BR>
</P><P ALIGN=LEFT><BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</FONT><FONT  COLOR="#0f0f0f" BACK="#fffffe" SIZE=3 PTSIZE=10><BR>
</FONT><FONT  COLOR="#000000" SIZE=3 PTSIZE=10><BR>
<BR>
<BR>
<BR>
<BR>
<BR>


'sine wave generation (again? :)'
1999\02\21@182057 by Gerhard Fiedler
picon face
i need to produce an approx. sine wave (i guess a few % THD is fine, i'm
not sure about this requirement), but with a rather precise frequency in
the range from 300Hz to 2500Hz, and with a resolution of 0.5%. i'd like to
be able to switch it on (ie. be in sync) within at max. 50ms.

i'm considering the following options:

- vco (like the exar2206 -- ? not sure about the number) with a pll and a
simple square from the pic to sync it. this is easiest in firmware, but
i've never used a pll and i'm not sure what difficulties i might have to
expect in terms of stability.

- vco fed by the pic with a pwm signal (i probably will have a hardware pwm
in the pic), and getting the vco output back to the pic into a control
loop, which outputs to the pwm into the vco.

- a resistor adder approach with maybe five points or so. at 5 points and
2500Hz, that's 20microsec per step; for a resolution of 0.5% i need a step
increment of 100ns, which i guess is not possible with a pic. but i
probably can "cheat" and use step lengths which might differ by 1, which
would give me the necessary overall resolution for the frequency at 20MHz
or maybe even 10MHz clock.

- just thought of a variant of the above: a programmable (digital)
oscillator and a shift register (with the resistors at the parallel
outputs). needs more points (since i don't have three output states as with
the pic) or some logic to create positive/negative outputs, but maybe is
easier. the oscillator would have to bring 4..40kHz with the 0.5% resolution.

the magic sine approach or output the (stepped) sine directly from the
pic's hardware pwm seem not to be viable because of the frequency resolution.

if somebody has any comments to/experiences with the above options, or
knows of a digitally controlled oscillator with something resembling a sine
at the output, that would be great.

thanks,
ge

1999\02\21@191051 by Scott Dattalo

face
flavicon
face
On Sun, 21 Feb 1999, Gerhard Fiedler wrote:

{Quote hidden}

Check out

http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

http://www.brouhaha.com/~eric/pic/sine.html

For mine and Eric Smith's pic sine generators. Eric's routine is faster,
mine has more frequency resolution (i.e. phase accumulators). The phase
accumulators allow you to create sine waves whose frequencies are not
limited to an integer multiple of PIC instruction cycles. I suspect that
this coupled with the hardware pwm will provide a quite decent sine wave
(with the appropriate low-pass filter).  If you want to move the solution
into a smaller part, then check out this non-interrupt driven,
single-cycle-resolution, 256 level, all software PWM routine:

http://www.interstice.com/~sdattalo/technical/software/pic/pwm256.txt

Scott

1999\02\22@044007 by Gerhard Fiedler

picon face
At 16:09 02/21/99 -0800, Scott Dattalo wrote:
>On Sun, 21 Feb 1999, Gerhard Fiedler wrote:
>> i need to produce an approx. sine wave (i guess a few % THD is fine, i'm
>> not sure about this requirement), but with a rather precise frequency in
>> the range from 300Hz to 2500Hz, and with a resolution of 0.5%. i'd like to
>> be able to switch it on (ie. be in sync) within at max. 50ms.
>
>Check out
>
>http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

thanks. i've seen that before when i did some research, but i didn't
understand what i would do with a sine function in this application, but
now i guess i got it :)

>(with the appropriate low-pass filter).  If you want to move the solution
>into a smaller part, then check out this non-interrupt driven,
>single-cycle-resolution, 256 level, all software PWM routine:

that's an intriguing idea: a reduced i2c slave and the sine generator in an
8pinner... but for now i guess i leave it in the bigger one as a software
module, with the hardware pwm.

thanks again,
ge

1999\02\22@162618 by Gerhard Fiedler

picon face
At 01:37 02/22/99 -0800, Gerhard Fiedler wrote:
>At 16:09 02/21/99 -0800, Scott Dattalo wrote:
>>On Sun, 21 Feb 1999, Gerhard Fiedler wrote:
>>> i need to produce an approx. sine wave (i guess a few % THD is fine, i'm
>>> not sure about this requirement), but with a rather precise frequency in
>>> the range from 300Hz to 2500Hz, and with a resolution of 0.5%. i'd like to
>>> be able to switch it on (ie. be in sync) within at max. 50ms.
>>
>>Check out
>>
>>http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html
>
>thanks. i've seen that before when i did some research, but i didn't
>understand what i would do with a sine function in this application, but
>now i guess i got it :)

just in case anybody made/is going to make the same mistake i made, here's
how to get a pretty good frequency resolution for a sine output. the
resistor-output approach (and also the magic sine waves) works (and my head
worked :) with fixed parts (angles) of a sine wave. therefore you have to
work with sample rates which are integer multiples of the desired
frequency. using an approach that outputs arbitrary voltages (as opposed to
fixed steps with the resistor ladder approach), you're not longer stuck
with integer multiples of the frequency, since the sample points don't have
to be at the same angles in each period.

so my solution looks like this (the terms in [] after a variable gives the
unit and scale for it, as an example for the scales of the different values):

20MHz pic w/ 8 bit hardware pwm: f_sample=40kHz, t_sample=25us (this gives
me at least 16 samples per period, for frequencies up to 2500Hz)

i calculate all times with a resolution of 0.5us, which gives me a
frequency resolution of 3Hz at 2500Hz (and 0.1Hz at 300Hz)

t_sine [0.5us] = 2*10^7 / f_sine [0.1Hz]

the actual time is calculated also in [0.5us] resolution and reduced into
the interval 0..t_sine:

t_(n) [0.5us] = t_(n-1) + t_sample
if ( t_(n) >= t_sine )
 t_(n) = t_(n) - t_sine

then i use this time and the frequency to calculate the angle of the next
sample for the sine function (which has to be scaled to fit the input range
of the used sine function, which here is 14 bit for 2*pi, ie. 16384):

phi [2*pi/16384] = ( t_(n) [0.5us] * (f_sine [0.1Hz] * scale) ) / (2^16)
 with scale = (0.5us * 0.1Hz * 16384) * 2^16 = 53.69

output = sin ( phi )

this output value gives me, appropriately scaled (eg. scott's sine function
returns -127..+127, so i'd have to add 128 to get an 8bit pwm range of
0..255), the pwm on-time for the next sample period. at 20MHz, there's 128
instruction cycles between samples, which seems to be enough, considering
that scott's function needs only 54 IIRC. the rest is a 16bit add, a 16bit
subtract, a 16x16bit multiplication and an 8bit add plus some "glue" -- not
too heavy.

ge

1999\02\22@214835 by Scott Dattalo

face
flavicon
face
On Mon, 22 Feb 1999, Gerhard Fiedler wrote:

{Quote hidden}

It took me a couple of passes to understand this, but you're (mostly)
describing a phase accumulator. The way I usually think about it is:

Imagine a counter that rolls over after 2^N counts. At evenly spaced time
intervals, add a constant (delta phi) to the counter. The rollover
frequency of the counter is (obviously) determined by the constant you add
at each of the time intervals. What's not so obvious is that you can use
fix point arithmetic to get rollover frequencies that are not an integer
number of cpu cycles. You don't get something for nothing though - in the
trade off you introduce some frequency jitter.

The equation for the frequency is:

   delta phi       1
f = --------- *   ------
    delta t       2^N

You know delta t - that's dictated by how fast some isocronous routine
increments the phase accumulator. Usually you want this as small as
possible since that gives better frequency resolution. You also know the
frequency, f (that's what you're trying to generate). So you can solve for
delta phi:

delta phi = f * delta t * 2^N

If you had a 20Mhz crystal and used the isochronous software pwm routine I
mentioned in the last post, then delta t = 51.2uS. For N=14 bits you get a
really simple equation (if I did the arithmetic correctly):

delta phi = 0.83886 * f

So to generate 2500Hz, delta phi would be 2097. This multiplication, btw
only needs to be performed once per frequency. So the 16-bit multiply you
mentioned doesn't need to be in the isochronous loop. Also, pre-computing
all of the constants removes the need for the addition and subtraction.

BTW
The sine wave routine executes in 65 cycles. However, there are two ways
to speed it up. One is to unroll a loop (it only loops four times). The
other is to completely rewrite the routine and take advantage of the fact
that the sine values are generated consecutively - this will save on
average one table-look-up per iteration.

Scott

1999\02\23@034143 by Gerhard Fiedler

picon face
At 18:48 02/22/99 -0800, Scott Dattalo wrote:
>you're (mostly) describing a phase accumulator.

if i had heard that term before, maybe i wouldn't have taken such a long
way around it! :)


>If you had a 20Mhz crystal and used the isochronous software pwm routine I
>mentioned in the last post, then delta t = 51.2uS. For N=14 bits you get a
>really simple equation (if I did the arithmetic correctly):
>
>delta phi = 0.83886 * f
>
>So to generate 2500Hz, delta phi would be 2097.

i still see one problem here. 51.2us=19.5kHz, that's less than 8 points per
period at 2500Hz. if i rewrite the pwm for a resolution of 128 (and double
the frequency), i guess the free cycles would be less than half, too, and
that's probably not enough. what i was trying to figure out is how to get
an interrupt out of the hardware pwm module (like when the counter is
reset), but i guess that's not possible. or only with feeding the pwm
output back to RB0 and make sure the pwm register never gets 0. any ideas
on that? i'd like to use the hardware pwm, because it gives me 4 times the
frequency.

thanks a lot,
ge


'programmable sinewave generator chip?'
1999\07\20@171502 by Madis Kaal
flavicon
face
I am thinking about building a digitally controlled sinewave generator
and after considering the obvious brute force, lots of components
approach and after that briefly considering CD player DAC chip I decided
that there must be an easier way. Is anyone here aware of a chip that
would
allow me to tell it a frequency of a sine wave to output, in 1Hz steps
would
be nice? It sould need no precision analog components.

1999\07\20@173153 by l.allen

picon face
> I am thinking about building a digitally controlled sinewave generator
> and after considering the obvious brute force, lots of components
> approach and after that briefly considering CD player DAC chip I decided
> that there must be an easier way. Is anyone here aware of a chip that
> would
> allow me to tell it a frequency of a sine wave to output, in 1Hz steps
> would
> be nice? It sould need no precision analog components.

You should use DDS
For up to 50kHz the MicroLinear   ML2036 is very easy to use.
Supply +/- 5v, one xtal and a PIC to talk to it over a simple 3 wire
interface... youre away and laughing.
Analog Devices make higher frequency DDS chips like AD9850.

There is a complete 40MHz generator published at
http://www.geocities.com/CapeCanaveral/LAb/9595/ddssg.html

Lance Allen
Uni of Auckland
New Zealand

1999\07\20@181147 by Dan Tye

flavicon
face
I recently had a similar problem finding an ic to output audio frequency
tones.  The solution I found was to use a device from MX-com part number
803A.  This device does single frequency output and also DTMF.  The
frequency output is programmable to output non standard tones.

+++++++++++++++++++++++++++++++++++++++
++      Dan Tye
++      Chief Engineer
++      Tel-Tron Technologies Corporation
++      220 Fentress Boulevard
++      Daytona Beach, FL 32114
++      Phone: 904-255-1921    Fax: 904-258-3782
+++++++++++++++++++++++++++++++++++++++


{Original Message removed}


'DTMF Tones? [Idea]How to produce sine wave'
1999\11\12@140821 by Nikolai Golovchenko
flavicon
face
part 0 3906 bytes

{Quote hidden}

I may be inventing the wheel... Anyway, there was an interesting idea in
Scenix application notes on how to generate sine waveform not using table or
multiply, just addition. Basically, they generate triangle waveform, then
integrate it and, vou la, something very similar to sine is produced.
Triangle waveform is easy to implement - its just addition and substraction.
So, the frequency of sine waveform is equal to the primary triangle
frequency.

BUT, a problem appears when triangle frequency doesn't exactly match
sampling frequency divided by an integer. Typical way to make triangle is
something like: add to the current value fixed step untill the wave reaches
maximum, then substract the step untill the wave reaches minimum, and again.
What if the triangle reaches its maximums and minimums BETWEEN sampling
points? In this case, an error will appear, and frequency is corrupted.

A simple solution is: when triangle waveform goes over maximum, substract
the number it went over from the maximum (see appendix); and same for
minimum. As a result, the frequency is jitter free.

The drawback is that the resulting sine amplitude is varying slightly
depending on the step chosen.

For DTMF it must be okay. 16bit resolution for step, accumulators of
triangle and sine will be enough. For output, only 8 most significant bits
can be taken.

Is this the same as phase accumulators?
_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: spamBeGonegolovchenkospam_OUTspamRemoveMEmail.ru


P.S.
Tracy, may I ask you what "dot lo" means?

:-)


Attachment converted: wonderland:solution.gif (GIFf/JVWR) (0000F660)

1999\11\12@162527 by Tracy Smith

picon face
--- Nikolai Golovchenko <.....golovchenkospamRemoveMEMAIL.RU> wrote:

> I may be inventing the wheel... Anyway, there was an
> interesting idea in
> Scenix application notes on how to generate sine
> waveform not using table or
> multiply, just addition. Basically, they generate

It's fun to reinvent the wheel (except when it's on
your nickel).

> triangle waveform, then
> integrate it and, vou la, something very similar to
> sine is produced.

Are you sure this is not the Goertzel algorithm? Scott
has a page that discusses this algorithm.

Also, here's a dtmf generator that uses Goertzel
http://www.ti.com/sc/docs/psheets/abstract/apps/spra066.htm

http://www.interstice.com/~sdattalo/technical/theory/sinewave.html

But again, I think Eric Smith's solution is the best.

> Is this the same as phase accumulators?

No. Phase accumulators are really, really cool. I just
don't know how to adequately explain them. A quick
alta vista search produced:

http://www.g4dvj.demon.co.uk/dds.htm

> P.S.
> Tracy, may I ask you what "dot lo" means?
>
> :-)

I let that cat out of the bag when I'm ready. :)

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\12@181518 by Paul B Webster

flavicon
face
Nikolai Golovchenko wrote:

> Is this the same as phase accumulators?

 I beg to differ from Tracy.  I think it is.  Phase accumulators are
based on the principle of - as the name suggests - adding up little
pieces of the cycle and "rolling over" when the sum of these amounts to
or in fact exceeds, a full cycle.

 That appears to be exactly what is suggested here; you would be using
a phase accumulator to control the up/ down ramp of the wave, then
filtering it further in analogue circuitry.  It begs the question though
of using a full-blown phase accumulator/ DDS with (a number of stages
of) integration.

 Once you go the DDS path, you are in a position to vary the slope of
the waveform during the cycle, by using even a simple resistive DAC,
(or perhaps PWM) which *greatly* eases the requirements on your
integration/ low-pass filtering.

 I would think that even a 3-bit (six resistor) ADC would considerably
improve performance, and perhaps allow output of both tones via the one
channel (though Dave Van Horn's "twist" would still be a difficulty).
--
 Cheers,
       Paul B.  (away from home for a day or so!).

1999\11\12@181743 by Harold M Hallikainen

picon face
On Fri, 12 Nov 1999 13:24:37 -0800 Tracy Smith <dot_lospam@spam@YAHOO.COM> writes:
>--- Nikolai Golovchenko <EraseMEgolovchenkoRemoveMEspamSTOPspamMAIL.RU> wrote:
>
>> I may be inventing the wheel... Anyway, there was an
>> interesting idea in
>> Scenix application notes on how to generate sine
>> waveform not using table or
>> multiply, just addition. Basically, they generate
>
>It's fun to reinvent the wheel (except when it's on
>your nickel).
>
>> triangle waveform, then
>> integrate it and, vou la, something very similar to
>> sine is produced.
>

       Of course, a triangle wave is just a square wave run through an
integrator (which is sorta like a 0 Hz low pass filter with a 6 dB/octave
or 20 dB/decade roll-off).  I think an additional stage of LPF is cheaper
than doing a D/A of a triangle wave, then filtering it.
       I think phase accumulation and DDS is really neat, though I
haven't used it yet in anything.  By having different tables before the
D/A, you can do arbitrary waveform generation.  The anti-alias filter
needs to be somewhere above the maximum output frequency and below the
Nyquist frequency (50% of sample rate).  With a perfect filter, you'd get
a perfect sine wave out of the thing (assuming you are doing sine wave
synthesis).  You can vary the frequency and the output level remains the
same.  Anything that uses filters to remove harmonics (instead of alias
components) will have the output level vary as the frequency is varied
unless you have the filter track the output frequency (kind of a pain).
       One thing I'd like to try some time is to have a look up table
that simulates a linear mix of several sinusoidal signals (stuff around 1
MHz), then drive the D/A.  I wonder how much intermod there'd be...

Harold



Harold Hallikainen
RemoveMEharoldKILLspamspamTakeThisOuThallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm

___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.

1999\11\12@194116 by Tracy Smith

picon face
--- S Webster <spamBeGones.websterspam@spam@STUDENT.UNSW.EDU.AU> wrote:
A.K.A. Paul

> Nikolai Golovchenko wrote:
>
> > Is this the same as phase accumulators?
>
>   I beg to differ from Tracy.  I think it is.  Phase
> accumulators are
> based on the principle of - as the name suggests -
> adding up little
> pieces of the cycle and "rolling over" when the sum
> of these amounts to
> or in fact exceeds, a full cycle.

True, but that's not what Nikolai described (I
thought). OTOH, I'm hardly the Phase Accumulator
expert. My understanding of the phase accumulator is:

You start off with a single cycle of something you
wish to generate. This may be a square wave, sine
wave, or a hyperbolic paraboloid wave (what in the
hell is that?). The phase accumulator simply
determines which portion of the cycle you wish to
access.

In its simplest form, the single cycle of the wave
form is in an array and the phase accumulator is the
index. The array is accessed at a constant rate,
however the index is advanced according to the
frequency of the wave form. Here's a simple C example:

#define TABLE_SIZE  256

char wave_table[TABLE_SIZE];

float phase,delta_phase;

void phase_accumulator(void)
{
 int i;

 while(1) {

   phase += delta_phase;

   if(phase > TABLE_SIZE)
     phase -= TABLE_SIZE

   i = phase;

   output(wave_table[i]);

   routine_that_updates_delta_phase(&delta_phase);
 }

}

void main(void)
{

 delta_phase = ....
 init_wave_table(wave_table);

}


I'd definite do this in assembly instead of C (but
that's another thread). In each application, there are
always ways to optimize this approach. For example,
for square waves you don't need a table at all nor do
you need floating point arithmetic for the phase
accumulator.  Fixed point arithmetic works fine and
the most significant bit of the phase accumulator is
the output. For most pics, you're forced to optimize
because 256 element arrays (in ram aren't possible).
256 element arrays in code are possible, but are
always a pain in the ass (because of page boundaries).



Who knows, perhaps it's only semantic and S. and I are
on the same page. But like I said, I'm not the
expert...

>   I would think that even a 3-bit (six resistor) ADC
> would considerably
> improve performance, and perhaps allow output of
> both tones via the one
> channel (though Dave Van Horn's "twist" would still
> be a difficulty).

Borrowing a little from the best of both worlds is
often the best solution.

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\13@122130 by Nikolai Golovchenko

flavicon
face
-----Original Message-----
From: Tracy Smith <RemoveMEdot_lospam_OUTspamYAHOO.COM>
To: PICLISTspamspamMITVMA.MIT.EDU <spam_OUTPICLISTspam_OUTspamspam_OUTMITVMA.MIT.EDU>
Date: Friday, November 12, 1999 11:26 PM
Subject: Re: DTMF Tones? [Idea]How to produce sine wave


{Quote hidden}

Sure it is not. The Goertzel algorithm calculates sine value by a recursive
formula, which uses two previous values. Moreover, there is a multiply to do
and Scott mentions round off errors accumulation. The method I suggest uses
only one previous sample, no multiply, no frequency error, no ...  :-)
Should Scott Dattalo add yet another, 11th method?

>
>Also, here's a dtmf generator that uses Goertzel
>http://www.ti.com/sc/docs/psheets/abstract/apps/spra066.htm
>


Are you kidding? This is a decoder algorithm.

{Quote hidden}

Thanks for the link. Explanation is perfect.
I think that my method resembles phase accumulator and table method except
there is no table. The table is generated on the run and this is triangle.
In my case error of triangle generation is lower, because there is no
restriction to use only table values. Finally, this reduced error makes the
sine wave frequency more stable. Certainly, the phase accumulator method is
more straight-forward and simple, at the cost of frequency jitter. In case
of DTMF this is mainly the frequency what matters, because DTMF frequencies
are very close.

{Quote hidden}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-----Original Message-----
From: Harold M Hallikainen <RemoveMEharoldhallikainenKILLspamspam@spam@JUNO.COM>
To: PICLISTspamBeGonespam.....MITVMA.MIT.EDU <KILLspamPICLISTspam.....MITVMA.MIT.EDU>
Date: Saturday, November 13, 1999 1:17 AM
Subject: Re: DTMF Tones? [Idea]How to produce sine wave

>        Of course, a triangle wave is just a square wave run through an
>integrator (which is sorta like a 0 Hz low pass filter with a 6 dB/octave
>or 20 dB/decade roll-off).  I think an additional stage of LPF is cheaper
>than doing a D/A of a triangle wave, then filtering it.

Thanks Harold, I wonder why it didn't come to my head... In this particular
case, triangle of fixed frequency seems easier to produce than square.



_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: spam_OUTgolovchenkospamKILLspammail.ru

1999\11\14@110103 by Tracy Smith

picon face
> >Are you sure this is not the Goertzel algorithm?
> Scott
> >has a page that discusses this algorithm.
>
>
> Sure it is not. The Goertzel algorithm calculates
> sine value by a recursive

Yeah, I misunderstood what you were describing. Sorry


> >
> >Also, here's a dtmf generator that uses Goertzel
>
>www.ti.com/sc/docs/psheets/abstract/apps/spra066.htm
> >
>
>
> Are you kidding? This is a decoder algorithm.

No, I'm not kidding, just wrong.

> >http://www.g4dvj.demon.co.uk/dds.htm
> >
>
>
> Thanks for the link. Explanation is perfect.

1 out of 3 pieces of information distributed on the
pic list is decent. :)

{Quote hidden}

True, butt, if you incorporate the proper
interpolation along with your look up table, then the
jitter effects are mitigated. Without any
interpolation, the sinewave output from the look-up
table is a stair-stepped waveform. The higher the
update frequency, the smaller the steps and the closer
to a sine wave approximation. This 'stair-stepped'
wave form however is a form of interpolation;
specifically zero-order interpolation. You may have
heard of a "zero-order hold" in your studies on
signals and systems (and perhaps z-transforms).
According to the 'theory', as long as you satisfy the
Nyquist sampling criterion, you can exactly reproduce
the synthesized wave form. But I couldn't look at you
with a straight face and say it's possible. The caveat
is that a perfect low-pass filter must be constructed.
DTMF competition is much too cheap for us to insist on
perfect analog filters.

So the next step is first order interpolation. For our
application, this is linear interpolation between
consecutive samples in the table. (For sampling
theory, there are some subtle but important
differences on the interpretation of a first-order
hold.) Which is to say, if you need a sample that is
not (exactly) at one of the sample points in your
table, then you approximate it by using linear
interpolation. For example, suppose you had a table
with 10 samples: f(i) is the function defined for i
=0..9 . Now suppose you need f(2.25)? Well, using
linear interpolation you'd approximate this:

f(2.25) - f(2)    f(3)  - f(2)
-------------- = -------------
 2.25  -   2       3   -   2

f(2.25) ~= f(2) + 0.25*(f(3) -f(2))

>From a frequency or spectral point of view, linear
interpolation's effect on higher harmonics are
approximately the square of the harmonics introduced
by zero-order interpolation (sinc vs. sinc^2). And
since the magnitude of the higher harmonics is less
than one, this is a good thing (e.g. 1/9 is much
smaller than 1/3). The direct implication is that the
stringent low-pass filter constraints associated with
the stair stepped waveform can be relaxed.

>From an intuitive view, you can see how first-order
interpolation improves the table values. For example,
if you had 64 samples of sine wave over one cycle,
then the deviation between linear interpolation and
the 'true value' of the sine wave is quite small. In
fact, an error bound may be placed on it.
Specifically, as I alluded to in another thread, you
can use the Cauchy Remainder Theorem for
interpolation. In essence, this theorem states that
the error is bounded by the n'th derivative of the
function your approximating, where n is the order of
the interpolation (1 for linear). So in the above
example,

The error in approximating:

f(2.25) ~= f(2) + 0.25*(f(3) -f(2))

error <= abs(f'(3) - f'(2))

Now there are additional caveats, like you still have
to satisfy Nyquist.

.lo

ps. Please forgive any mistakes, this is all from memory...

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\15@021719 by Nikolai Golovchenko

flavicon
face
-----Original Message-----
From: Tracy Smith <RemoveMEdot_loRemoveMEspamEraseMEYAHOO.COM>
To: KILLspamPICLISTspamspamBeGoneMITVMA.MIT.EDU <PICLISTspamspamMITVMA.MIT.EDU>
Date: Sunday, November 14, 1999 6:01 PM
Subject: Re: DTMF Tones? [Idea]How to produce sine wave


>1 out of 3 pieces of information distributed on the
>pic list is decent. :)

I would say 1 out of 10. ;)


{Quote hidden}

This means a biggg table. Interesting, what size of table will be sufficient
to minimize jitter enough for DTMF application.

{Quote hidden}

Let me compare two methods of sine generation for DTMF application:
1)Triangle generation with subsequent integration.
2)Phase accumalator&table with linear interpolation;

The first method doesn't have table, instead, triangle waveform is generated
using addition of a fixed step to the previous sample. No need to use
interpolation means faster execution time. To produce sine waveform
integration is used - some degradation in the waveform, which is acceptable
in DTMF. As a result, the first method generates efficiently jitter free,
sine waveform signal.

The second method has table, therefore it requires more ROM; needs linear
interpolation - more computing time because of multiplication. Result is the
same.


What do you think?

_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: RemoveMEgolovchenkospamBeGonespamRemoveMEmail.ru

1999\11\15@024911 by Dave VanHorn

flavicon
face
> What do you think?


You want the part number of that chip again?  :)
Three pins, clocked serial byte for what digit to say, and one pin as /xmit.
One external component, a 3.585 mhx xtal or resonator.

:o)

1999\11\15@101948 by Tracy Smith

picon face
--- Dave VanHorn <KILLspamdvanhornspamBeGonespamCEDAR.NET> wrote:
> > What do you think?
>
>
> You want the part number of that chip again?  :)
> Three pins, clocked serial byte for what digit to
> say, and one pin as /xmit.
> One external component, a 3.585 mhx xtal or
> resonator.
>
> :o)

Wouldn't it be better to run the 12C508 off the
internal oscillator instead. :)

.lo


=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\15@105408 by Tracy Smith

picon face
--- Nikolai Golovchenko <@spam@golovchenkoSTOPspamspam@spam@MAIL.RU> wrote:
> -----Original Message-----

> >True, butt, if you incorporate the proper
> >interpolation along with your look up table, then
> the
> >jitter effects are mitigated. Without any
> >interpolation, the sinewave output from the look-up
> >table is a stair-stepped waveform. The higher the
> >update frequency, the smaller the steps and the
> closer
> >to a sine wave approximation. This 'stair-stepped'
>
>
> This means a biggg table. Interesting, what size of
> table will be sufficient
> to minimize jitter enough for DTMF application.

Actually, the table is not biggg. That's the beauty of
linear interpolation. See below.


{Quote hidden}

Actually "some degradation" may not be acceptable. A
symmetrical triangle wave has odd harmonics whose
strengthes vary inversely to the square of the
harmonic number (e.g. the third harmonic is 1/9'th the
strength of the fundamental). A low pass filter would
be of no use since to generate 440Hz, you'd need to
block 1320Hz which would also block a few of the
higher frequency DTMF tones as well. Ideally, you want
to have to only block some very high frequency
carrier. For example, if you were using PWM with a
20kHz carrier to generate DTMF then you'd need to
block the 20kHz and pass (a maximum of) ~1600Hz. A
relatively simple 2'nd order low pass filter with
perhaps a cascaded 2'nd order notch (or band-stop)
would be sufficient.

>
> The second method has table, therefore it requires
> more ROM; needs linear
> interpolation - more computing time because of
> multiplication. Result is the
> same.
>
>
> What do you think?

I just re-visited Scott's sine wave page:

http://www.interstice.com/~sdattalo/technical/software/pic/picsine.html

His table contains only 16 entries and (according to
the comments) can generate a new sample every 65
instruction cycles. I see a way to knock 10 cycles
off. So to generate the two tones you'd need about 110
cycles plus an additional overhead of perhaps 50 more
cycles. This'll give you a new sample at about a 30kHz
rate (for a 20Mhz pic). But you'd still need a way to
convert this to analog. So perhaps you'd could back
the generation frequency to 20kHz (or ~256 cycles) and
use an 8-bit pwm.

---------

Perhaps it's not obvious, but the triangle-to-sine
algorithm may also be viewed as a kind of a digital
filter, or more specifically the impulse response of a
digital filter. Consequently, you may wish to consider
other simple algorithms. (e.g. a 4'th order FIR filter
with binary coefficients or perhaps a 3'rd order IIR.)

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\16@012723 by Nikolai Golovchenko

flavicon
face
-----Original Message-----
From: Tracy Smith <dot_lospamBeGonespamspamBeGoneYAHOO.COM>
To: spamBeGonePICLISTspamMITVMA.MIT.EDU <spam_OUTPICLISTSTOPspamspamMITVMA.MIT.EDU>
Date: Monday, November 15, 1999 5:54 PM
Subject: Re: DTMF Tones? [Idea]How to produce sine wave


>Actually, the table is not biggg. That's the beauty of
>linear interpolation. See below.


Sorry, I wasn't clear at this. I meant that interpolation may be omitted if
the table is big enough to reduce jitter for DTMF frequencies. The question
is how big.


>Actually "some degradation" may not be acceptable. A
>symmetrical triangle wave has odd harmonics whose
>strengthes vary inversely to the square of the
>harmonic number (e.g. the third harmonic is 1/9'th the
>strength of the fundamental). A low pass filter would
>be of no use since to generate 440Hz, you'd need to


You forget the integration. It acts like LP filter (6 dB/octave) and is made
digitally. Already, third harmonic magnitude A3 = 1/9 A1 (-19 dB, assuming 0
dB for the fundametal harmonic), and fifth A5 = 1/25 A1 (-28 dB). When
integration is applied, higher harmonics will be further attenuated by 9.5
dB for the third one and by 14 dB for the fifth. Totally, the relative level
of third harmonic is -28 dB and the fifth is -42 dB. As far as I know,
required signal to noise ratio in this kind of systems is 20 dB. So
integration solves the problem, isn't it?

{Quote hidden}

An LP filter should be used, of course, at the output stage of D/A or PWM.
It's pass band should include all DTMF frequencies.

{Quote hidden}

I dont have time right now to look at this routine, have to go to school. It
seems that this small table will require additional effort on calculation of
mid points to get more accurate frequency.

>Perhaps it's not obvious, but the triangle-to-sine
>algorithm may also be viewed as a kind of a digital
>filter, or more specifically the impulse response of a
>digital filter. Consequently, you may wish to consider


Yeah, this is a first order FIR filter with unitary coefficients.

>other simple algorithms. (e.g. a 4'th order FIR filter
>with binary coefficients or perhaps a 3'rd order IIR.)


Simple? :) Second order FIR may be. But 3'rd order IIR - no, thanks. First
order IIR is enough to generate sine waveform. It requires cumbersome
multiplication.

Bye for now.

_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: RemoveMEgolovchenkospamspammail.ru

1999\11\16@183333 by Tracy Smith

picon face
At the risk of boring everyone with our on-line
dialog,

> >Actually, the table is not biggg. That's the beauty
> of
> >linear interpolation. See below.
>
>
> Sorry, I wasn't clear at this. I meant that
> interpolation may be omitted if
> the table is big enough to reduce jitter for DTMF
> frequencies. The question
> is how big.

Again, Cauchy Remainder Theorem for interpolation may
be used. In this instance however, it's zero order
interpolation (i.e. NO interpolation). IIRC, the error
will be proportional to the differences in consecutive
entries in the table (I don't know if or what the
proportionality constant is). I think intuitively this
makes sense. If the index into the table is a
fraction, you'll have to round to the nearest integer.
Consequently, the ideal sample which lies somewhere
between the two that are in the table will be off. And
assuming you're satisfying Nyquist, the error will be
bounded by the samples that are available.

> You forget the integration.

Could you perhaps drag up the details showing how this
algorithm really works?


> I dont have time right now to look at this routine,
> have to go to school. It
> seems that this small table will require additional
> effort on calculation of
> mid points to get more accurate frequency.

Compared to Eric's table, you're right. His takes
about 15 cycles; a savings of about 40 cycles. OTOH,
it has 64 entries in the table. I'd probably choose
Eric's sine over Scott's for DTMF (especially since
Eric already wrote the damn DTMF dialer). 64 table
entries is not that many. Further more since the
sample output rate is potentially 3 or 4 times faster
you could ease the filter requirements even more
(again, this depends on how you actually go from a to
d...)

{Quote hidden}

The simplest 3'rd order IIR I know is Simpson's
3/8'ths rule. It's not quite as good as the 1/3 rule,
but it's much better than the rectangular rule for
numeric integration. The only caveat is that even
though it is an integration formula, it's transfer
function in fact amplifies high frequencies.

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\17@152453 by Nikolai Golovchenko

flavicon
face
part 0 3051 bytes content-type:application/octet-stream;
>Could you perhaps drag up the details showing how this
>algorithm really works?


The algorithm is really simple. You can find the original version in Scenix
Application Note #11 (http://www.scenix.com). The original version is hard to use
for any frequency because of fixed triangle slope and amplitude. So I
changed the algorithm a little to adjust for DTMF frequencies generation.

First you initialize accumulators. There are two - one is a triangle
accumulator and another is a sine accumulator. Then,  each new sample is
calculated by a common routine. Note, that these accumulators contain
current value of sine/triangle, not phase.

Sine waveform is generated by adding to the last sine value the last value
of triangle. This may be regarded as integration or first-order FIR
filtering of triangle signal. As a result, the fundamental harmonic of
triangle is attenuated significantly less then other harmonics, and you have
almost clean sine wave. The sine wave frequency is equal to that of
triangle. Triangle waveform is primary in this case and generated by adding
pre-calculated fixed step to the triangle accumulator. When the accumulator
reaches top limit (also pre-calculated for the given frequency) the step's
sign is changed. A little nuance here. If the triangle peak lies somewhere
between current and last sample then a correction required to keep the
triangle value correct. After triangle reaches bottom limit, the step's sign
changes again.

Actually, I wrote the sine waveform generation routine for PIC. It takes 64
instructions, 8 RAM bytes, 24 cycles best case, and 41 cycles worst case.
This is 14 cycles savings from your supposed 55. The routine takes input 2
bytes for limit and 2 bytes for step, other 4 bytes are for 16 bit
accumulators.

For comparison I also simulated the routine of Scott Dattalo in MATLAB at 20
kHz sampling rate for all DTMF frequencies. Results are very good. There is
no frequency jitter at all and the frequency error is very small. Sorry for
wrong
suggestions.

The phase steps are:
f, Hz      Phase step
697        571
770        631
852        698
941        771
1209       990
1336       1094
1477       1210
1633       1338

phaseaccstep = round(16384 * f / f0), where f=needed freq. and f0=sampling
freq.

If I had to do DTMF dialer I would choose the phase accumulators method and
Scott Dattalo's routine, because it can provide close approximation to sine
wave, small program size, frequency can be changed smoothly, without phase
jerk.

I suppose other applications may exist where higher speed of my method is
very important.

Thanks for productive dialog. I hope this will help somebody else.


Best regards.
_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: TakeThisOuTgolovchenkospamspamRemoveMEmail.ru



Content-Type: application/octet-stream;
       name="sin.asm"
Content-Disposition: attachment;
       filename="sin.asm"

Attachment converted: wonderland:sin.asm (????/----) (0000F8FC)

'[OT]Re: DTMF Tones? [Idea]How to produce sine wave'
1999\11\17@162538 by Jim Hartmann

flavicon
face
Very cool!  But its not a true sine wave, its a parabolic wave if that's a
real term.  One segment of a triangle wave is a line. The algorithm is an
integrator, and the integral of a line like y = x is y = (x^2)/2+c, a
parabola (let c be your DC offset).  Maybe someone else can tell us what
the error magnitude amounts to comparing the "parabolic wave" to a sine?

Jim Hartmann

'DTMF Tones? [Idea]How to produce sine wave'
1999\11\17@162744 by Dave VanHorn

flavicon
face
> For comparison I also simulated the routine of Scott Dattalo in MATLAB at
20
> kHz sampling rate for all DTMF frequencies. Results are very good. There
is
> no frequency jitter at all and the frequency error is very small. Sorry
for
> wrong suggestions.


So how do you establish twist?

1999\11\17@191816 by Tracy Smith

picon face
--- Nikolai Golovchenko <KILLspamgolovchenkospamspamspam_OUTMAIL.RU> wrote:
{Quote hidden}

Without taking the time to read scenix's appnote, I'll
take your word at face value - (I have no reason not
to since you're obviously a logical thinker), and add
just one more comment. If instead of generating
triangle waves you wish to generate trapezoidal waves,
then it possible to exactly suppress all of the even
harmonics AND the third harmonic. I'll leave it as an
excercise for the student, but my theoretical analysis
proves that if the trapezoid has a rise and fall time
that is one third of the period then there'll be no
third harmonic.

I'm not sure if the scenix app is conducive to
generating trapezoids, but it's certainly worth an
effort to investigate. I'm not sure what the harmonics
of the integrated triangle wave look like either.
Perhaps


.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\17@193450 by Tracy Smith

picon face
--- Dave VanHorn <dvanhornRemoveMEspamCEDAR.NET> wrote:
> > For comparison I also simulated the routine of
> Scott Dattalo in MATLAB at
> 20
> > kHz sampling rate for all DTMF frequencies.
> Results are very good. There
> is
> > no frequency jitter at all and the frequency error
> is very small. Sorry
> for
> > wrong suggestions.
>
>
> So how do you establish twist?
>

How much twist is needed? 3dB? 6dB?

I think the best way to approach this is to write:

dtmf = A*sin1 + B*sin2

The twist will be 20*log(B/A), right? Determine how
many dB are needed and how much error can be tolerated
and then find two 'easy to multiply' integers for A
and B. 6dB is easy, because B=2 and A=1 would satisfy
the equation. To maximize the output amplitude (and
consequently minimize truncation errors) you'd want to
weight one term with 1/3 and the other with 2/3 for a
6dB twist. So you'd have one multiplication by 2 and
one division by 3. I think division by 3 has beaten to
blithering pulp.

.lo

=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

'[OT]Re: DTMF Tones? [Idea]How to produce sine wave'
1999\11\18@105937 by Tracy Smith

picon face
--- Jim Hartmann <EraseMEJim_hartmannSTOPspamspamRemoveMESILENTKNIGHT.COM>
wrote:
> Very cool!  But its not a true sine wave, its a
> parabolic wave if that's a
> real term.  One segment of a triangle wave is a
> line. The algorithm is an
> integrator, and the integral of a line like y = x is
> y = (x^2)/2+c, a
> parabola (let c be your DC offset).  Maybe someone
> else can tell us what
> the error magnitude amounts to comparing the
> "parabolic wave" to a sine?

I was wondering who'd drag this [OT] first.

I did a quick back-of-the-notebook calculation and
discovered what should've been intuitive. If you're
familiar with time to frequency transformations like
Fourier or Laplace then you'll see why I say this.

Let's look at the way we've been discussing how to
approximate sine waves and their corresponding
harmonics. First we started with square waves. We know
that the harmonic strengths fall off inversely to the
harmonic number (and for symmetrical square waves,
there are no even harmonics). This inverse relation
ship, 1/s or 1/(jw), is a direct result of taking the
transformation of a step function. The additional
factors such as defining the harmonic locations are
determined by the periodicity of the wave form.

When we went to triangle waves, we noted that the
harmonic strengths diminished as the square of the
harmonic number, 1/s^2 of 1/(jw)^2 . Again, this is a
direct result of taking the transform of a line.

Continuing with this line of reason, we should
(intuitively) suspect that a wave created with
parabolas would have harmonics strengths diminishing
with the cube of the harmonic number, 1/s^3 or
1/(jw)^3. Guess what?

I suppose one could continue with this reasoning to
suppress the harmonics even more. But (especially on
the pic) you'll reach a point of diminishing returns.
This whole subject btw, falls into the category of
polynomial approximation. So far we've been using
really simple polynomials. In fact to tie in with an
earlier observation, so far these polynomials are like
FIR filters. If one wanted to create the analogue
(perhaps an inappropriate adjective) IIR filter, then
perhaps rational Pade' approximations would be of some
use.

.lo
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

1999\11\18@190711 by Sean Breheny

face picon face
Along the lines of this thread: Can someone please tell me the difference
between FIR and IIR filters? I am familiar with impulse response for
continuous time systems, and with transfer functions,but I have not yet
covered IIR versus FIR in class, nor have I read any explanation of it yet,
so I am curious. Is it just that the impulse response is time-limited?

Thanks,

Sean

|
| Sean Breheny
| Amateur Radio Callsign: KA3YXM
| Electrical Engineering Student
\--------------=----------------
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
spam_OUTshb7RemoveMEspamEraseMEcornell.edu ICQ #: 3329174

1999\11\19@043235 by Nikolai Golovchenko

flavicon
face
-----Original Message-----
From: Sean Breheny <TakeThisOuTshb7RemoveMEspam@spam@CORNELL.EDU>
To: EraseMEPICLISTRemoveMEspamMITVMA.MIT.EDU <spamPICLIST.....spamspamMITVMA.MIT.EDU>
Date: Friday, November 19, 1999 2:07 AM
Subject: Re: [OT]Re: DTMF Tones? [Idea]How to produce sine wave


>Along the lines of this thread: Can someone please tell me the difference
>between FIR and IIR filters? I am familiar with impulse response for
>continuous time systems, and with transfer functions,but I have not yet
>covered IIR versus FIR in class nor have I read any explanation of it yet,
>so I am curious. Is it just that the impulse response is time-limited?


FIR filters use only input signal samples to compute the next output. The
difference equation for FIR filter is:
y(n) = b0 * x(n) + b1 * x(n - 1) + b2 * x(n - 2) + ...,
where y(n) - n'th sample of output
x(n) - n'th sample of input

IIR filters use also output signals samples. That is,
y(n) = b0 * x(n) + b1 * x(n - 1) + b2 * x(n - 2) + ...
- a1 * y(n - 1) - a2 * y(n - 2) - ...,

You can see from the FIR formula that its impulse response is indeed
time-limited, because its output is based on a number of input samples and
if input becomes zero then output will go zero sooner or later. The length
of FIR filter buffer defines the frequency and magnitude resolution that the
filter can provide. For example, a low pass filter with pass band edge
frequency of 100 Hz (0dB) and stop frequency 150 Hz (-60 dB) at 44100 Hz
sampling requires about 1400 buffer size. FIR filters can have linear phase
on frequency dependence.

IIR filter output depends on both input and output samples. IIR filters
resemble analog filters in this respect and often synthesized on an analog
model. IIR filters generally require less memory size, but harder to
implement. They have problems with stability, coeficients resolution. Good
idea is break the whole filter into second order sections. Response of a
practical IIR filter may be finite because of limited coeficients length.
Sometimes, the response is made infinite intentionally to generate for
example sine waves.


If you want more information on digital filters check out Texas Instruments
and Analog Devices web sites. They should have lots of information on this
topic.
_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: golovchenkospam_OUTspam@spam@mail.ru

1999\11\19@091501 by Barry King

flavicon
face
Nikolai,

Thanks for that information, it was the best short-and-sweet
explanation of IIR anf FIR filters I ever heard.

I think too many people get lost in the theoretical mathematics which
derive the IIR and FIR behaviors from the similar continuous time
filters.  Many university courses approach this from continuous time
circuits, then Fourier series, then Fourier transforms, then sampling,
then Z transforms, then digital filters.  By that time many are
confused!

But you can also explain "backwards" by learning about sampling,
then talk of averaging samples, (FIR, equal co-efficients, right?!)
Then talk of weighted averages (FIR, unequal coefficients), and so
on.  Then go on to feedback and IIR techniques.  This makes the
practical digital techniques clear.  Of course, understanding the
design of a complex (or excellent) digital filter makes us get back to
Z transforms some day.  But it makes more sense to me when I
remember to start at sampled data and averaging!

------------
Barry King, Engineering Manager
NRG Systems "Measuring the Wind's Energy"
http://www.nrgsystems.com
Phone: 802-482-2255
FAX:   802-482-2272

1999\11\20@130120 by Nikolai Golovchenko

flavicon
face
Hello Barry.

Absolutely true. Digital filters took my imagination long before the Control
Theory course and I started to learn how they work "backwards", as you say,
from sampling, ADC. DAC, etc. So I can say now it is really easier to study
digital signal processing from simple examples like averaging, integration,
differentiation... Unfortunately, I hadn't a chance yet to work with DSPs,
so I am limited to simulation only. MATLAB is a terrific tool for this.

By the way, I'm glad that you liked my very short explanation, because
sometimes I'm too short to be understood :o)
_

Nikolai Golovchenko, Electrical Engineering Student
National Mining University of Ukraine http://www.nmuu.dp.ua
Dnepropetrovsk, Ukraine
E-mail: .....golovchenkospamspam.....mail.ru


'Generating a Sine wave with a PIC'
1999\12\27@082039 by aipi Wijnbergen
picon face
Hi All,

>From time to time, people here on the list need to generate a sine wave
with a PIC, here is a solution with an active filter that would convert a
PWM output into a sine wave. Not a general purpose solution, but, good for
some applications, see:

http://www.burr-brown.com/WebObjects/BurrBrown/download/ABs/AB-058.pdf

I hope that it help some of you, Chaipi

1999\12\27@172201 by Mark Willis

flavicon
face
I forget if anyone mentioned "Magic Sinewaves",
http://www.tinaja.com/magsn01.html?

 Mark

Chaipi Wijnbergen wrote:
{Quote hidden}

--
I re-ship for small US & overseas businesses, world-wide.
(For private individuals at cost; ask.)


'Lookup Tables: Sine Converter'
2000\02\01@165822 by Thomas McGahee
flavicon
face
Very often a lookup table or set of lookup tables is the simplest
solution. By using a little creativity you can greatly reduce the
size lookup table needed.

Let's say you want to find the Sine of x. First off,
the sine of x only has to be calculated or stored for the first
90 degrees. In this quadrant the value ranges from 0 to 1. In the
second quadrant (90 to 180) the value ranges from 1 to 0. In this
second quadrant you can get the equivalent 1st quadrant value
by using 180-x. For example, 180-110=70, so sin(110)=sin(70).
In the 3rd quadrant (180 to 270) the value ranges from 0 to -1.
In the 3rd quadrant sin(x)=-sin(x-180). In the 4th quadrant
(270 to 360) the value ranges from -1 to 0. In the 4th quadrant
Sin(x)=-sin(360-x).

The implication of this is that you can use a single table that
covers from 0 to 90 degrees. You test the incoming x value and
branch to one of four routines, based on the quadrant to which
x belongs. Each subroutine would then convert x to the proper
value, look up the value in the table, and set a posneg indicator
that will tell us whether the last value converted is considered
a positive or negative value. (The returned value is in positive
format, and the posneg flag tells us whether it is really positive
or negative).

The lookup table can have the answer stored in either binary or
packed decimal format. Which form you use depends on what you
are going to do with the answer. If you are going to display the
answer on an LCD, then use packed decimal format. If you are
going to perform further math on the value, then binary might
be best. If the math perfomed is something simple like multiply
the value by some constant, then you can even store the table
values so that you have the value multiplied by the constant
already in the table.

In packed decimal format you use the upper 4 bits to store one
digit, and the lower 4 bits to store another digit. Two bytes
will thus get you 4 decimal digits. You can thus store values
from .0000 to .9999

You could get 6 digit accuracy if you use 3 bytes of storage per
value. Let's assume you want 6 digits of accuracy and a resolution
of .5 degrees. There are 90 degrees times 2 to give us .5 degree
resolution, times 3 bytes of storage. 90x2x3=540 bytes of storage.

A lookup table is limited to a maximum size of 256. This is due to the
fact that the addressing mechanism is limited to a one byte value.
The way you can get around this limitation is to use three jump
tables each having a length of 180. Let's call these tablehigh,
tablemiddle, and tablelow. You would load the tables with the
required data:

                                   SINE
Angle In Degrees | Offset Address | VALUE | High | Middle | Low
----------------------------------------------------------------
 0.0            | 0              |.000000| 00   | 00     | 00
 0.5            | 1              |.008727| 00   | 87     | 27
 1.0            | 2              |.017452| 01   | 74     | 52
 1.5            | 3              |.026177| 02   | 61     | 77
etcetera        | etcetera       | etc.  | etc. | etc.   | etc.
etcetera        | etcetera       | etc.  | etc. | etc.   | etc.
89.5            | 179            |.999962| 99   | 99     | 62
90.0            | 180            |.999999| 99   | 99     | 99
----------------------------------------------------------------

So let's say you feed the value 179 degrees in to the Sine Converter.
First the Sine Converter would determine that 179 is in the second
quadrant because it is between 90 and 180 degrees. The SecondQuadrant
converter would set the posneg flag to "1" to indicate a positive
polarity for the answer. Then 180-179=1. We multiply this by 2
to convert the equivalent angle into an Offset Address of 2.

The SecondQuadrant routine now jumps to the TableDecode routine.
The Offset Address now points to the proper table element.
We call a subroutine that looks at posneg and outputs either
a + or a - symbol to indicate polarity. It also prints the decimal
point (preceded by a "0" if desired). We access tablehigh
and get back 0x01. We call a subroutine that sends "01" to
the LCD. We access tablemiddle and get back 0x74. We call a
subroutine that sends "74" to the LCD. We access tablelow and
get back 0x52. We call a subroutine that sends "52" to the LCD.

The above assumes you want the sine value displayed. If you instead
want the sine value so it can be used with more math processing,
then store the value in binary. Here is a simple method for generating
the binary equivalents of numbers such as .017452:

Bigger than or equal to 1/2?      No .0
Bigger than or equal to 1/4?      No .00
Bigger than or equal to 1/8?      No .000
Bigger than or equal to 1/16?     No .0000
Bigger than or equal to 1/32?     No .00000
Bigger than or equal to 1/64?    Yes .000001
.017452-.015625=.001827
Bigger than or equal to 1/128?    No .0000010
Bigger than or equal to 1/256?    No .00000100 (just finished high byte)
Bigger than or equal to 1/512?    No .00000100 0 (we just began middle)
Bigger than or equal to 1/1024?  Yes .00000100 01
.001827-.0009765625=.0008504375
Bigger than or equal to 1/2048?  Yes .00000100 011
.0008504375-.00048828125=.00036215625
Bigger than or equal to 1/4096?  Yes .00000100 0111
.00036215625-.000244140625=.000118015625
Bigger than or equal to 1/8192?   No .00000100 01110
Continue this process until you have all 24 bits converted.

Yes, you are right, this is a regular bun-buster of a thing to have to
do for 180 values (to get 0 to 90 degrees in .5 degree increments).
Only a fool would attempt to build such a table manually. Instead,
write a simple program on your PC in BASIC, or C, or FOXPRO,
or whatever language you like. Then use the program to compile
the table values for you. Hint: the output is a "0" for No, and
a "1" for Yes. When the answer is Yes you subtract and now use
the result as your value to compare against.

I use FOXPRO to do all this nitty gritty boring stuff, and I
have it actually produce three ASCII files that make up the 3 tables of
RETLW instructions (High, Middle, and Low). I Then append these
files into my assembler at the proper places. Each line contains
something like this:
  RETLW 00110101b       where the "b" means that the number is in binary.

Well, I would write some more, but I have some other things to get to
right now. I hope that someone out there finds this useful. Is there
any great desire out there for a series of tutorials on topics like
binary addition, subtraction, division, multiplication, etc.? I could
probably also write some stuff on interrupt routines and various other
topics that are oriented towards the PIC way of doing things.

I am willing to write some tutorial type stuff if it is useful to some
and not obnoxious to those who are already experts.

I should warn you though that I am more inclined to write about
the HOW and WHY aspects and leave a complete and full program
listing to the user. It is not just a matter of time, but my mindset
as an educator. I am willing to teach and explain and show someone
how to go about something. I usually won't hand my students
a complete program to accomplish the task, because that is what
I want *them* to learn how to do. My objective is to educate, not
to be a source of finished product so that the student has nothing
to do. I believe we learn by doing more than any other way.


Fr. Tom McGahee




{Original Message removed}

2000\02\04@165913 by andy howard

flavicon
face
From: "Thomas McGahee" <tom_mcgaheeKILLspamspamEraseMESIGMAIS.COM>
Subject: Lookup Tables: Sine Converter


> Very often a lookup table or set of lookup tables is the simplest
> solution. By using a little creativity you can greatly reduce the
> size lookup table needed.

<Interesting and pleasantly discursive discussion snipped>

> I am willing to write some tutorial type stuff if it is useful to some
> and not obnoxious to those who are already experts.

Do please.  Although familiar with the nuts'n'bolts of PICs and able to
knock up code to do all the basics, when I see some of the elegant
and/or concise code examples posted here I'm all to aware that there's a
big gap in my meagre engineer's coding skills when it comes to
programming philosophies, strategy etc.  The science of programming as
it were, rather than the engineering.


{Quote hidden}

2000\02\04@172533 by andy howard

flavicon
face
Original Message From: "Thomas McGahee" <EraseMEtom_mcgahee@spam@spam@spam@SIGMAIS.COM>
Subject: Lookup Tables: Sine Converter

> Very often a lookup table or set of lookup tables is the simplest
> solution. By using a little creativity you can greatly reduce the
> size lookup table needed.

<Interesting and pleasantly discursive discussion snipped>

> I am willing to write some tutorial type stuff if it is useful to some
> and not obnoxious to those who are already experts.

Do please!  Though familiar with the nuts'n'bolts of PICs and able to
knock up code to do all the basics, when I see some of the elegant
and/or concise code examples posted by some people here I'm all too
aware that there's a big gap in my meagre, self-taught engineer's coding
knowlege when it comes to programming philosophies, strategy etc.


> I should warn you though that I am more inclined to write about
> the HOW and WHY aspects and leave a complete and full program
> listing to the user. It is not just a matter of time, but my mindset
> as an educator.

The science of programming as it were, rather than the engineering.
And maybe a touch of art too... Something many of the PIC books I've
seen find too little space for, IMHO.


> I am willing to teach and explain and show someone
> how to go about something. I usually won't hand my students
> a complete program to accomplish the task, because that is what
> I want *them* to learn how to do. My objective is to educate, not
> to be a source of finished product so that the student has nothing
> to do. I believe we learn by doing more than any other way.


They'll make an excellent learning resource as a website or ebook too.







.

'Pic A/D sampling a biased sine wave'
2000\02\18@064824 by Lorick

flavicon
face
I need to (hopefully) use the 16F876 to sample a sine wave that rides on a
1.75v reference line, swinging from 0v to 3.5v but before I even attempt
this, I'm thinking it won't work because if an average value of the sine
wave is what's taken over time, then wouldn't I always get a reading
somewhere near that 1.75v reference line?

Assuming a maximum swing signal, if a peak is measured in one instance in
time at 3.5v, and then a trough is measured the next time at 0v, and then
the middle of the signal is measured at 1.75v, the average of the 3 samples
is 1.75v.

What would be a proper method to sample a biased "ac" signal?  Considering
that the maximum voltage is 3.5v, I have ruled out the idea of rectifying
the signal or something unless I can use a semiconductor junction that
doesn't drop very much of that valuable signal level.  I also considered
looking into peak detectors.  I don't know off hand what they really do but
if they can be used to sort of sample and hold the most positive peaks of
this sine wave, I could sample from that and then just compensate in
software for the bias level to get a peak reading from the reference 1.75v.

What other options are there?

2000\02\18@073722 by Ken Webster

flavicon
face
Lorick wrote:
{Quote hidden}

Depending on how fast and/or noisy the signal is and what response time you
need, you may be able to sample with the A/D and take the max and min of
your samples over a given interval.  Then (max - min) would give your
peak-to-peak voltage.  Just be sure that you are sampling at a rate or phase
that catches the peaks (sample much faster than the signal or phase-lock to
it so that you can align your samples with the peaks).

If you do phase-lock to the signal, you could take the average of the
samples aligned with the peaks minus the average of the samples aligned with
the troughs and thus reject noise much better (than taking max and min).
Phase lock can be accomplished by also sampling at the zero crossings and
using the difference between the two zero crossing points (rising edge and
falling edge) as an error control signal for the loop.  I used this
technique to lock to the 60kHz WWVB carrier for a direct-sampling WWVB
receiver I designed a few years ago based on a 16C73.  It worked like a
charm and could measure the carrier amplitude with a lot more precision than
one might expect given an 8-bit A/D (the signal can bias the noise and
produce a clearly measureable difference in the average even when the signal
itself is smaller than one LSB worth of voltage on the A/D input).  To get a
high degree of precision with a noisy signal you will also need to apply a
time-domain windowing function (like the windowing functions used for FFTs
and serving exactly the same purpose).  The only practical windowing
function to use with fast signals on a PIC (because it can be done with a
coupple of running sums and thus avoid time-consuming multiplications) is
the triangle window.  But that's probably more than you needed to know ...

Anyway, there are lots of ways to measure the amplitude of a sinusoid with a
PIC.  The most appropriate method depends on how fast your signal is, how
fast you want to measure its amplitude, how noisy it is, how much frequency
modulation it has, how much precision you need, how much code (or hardware)
you are willing to devote to the task, etc.

Cheers,

Ken

2000\02\18@083001 by Robert A. LaBudde

flavicon
face
<x-flowed>At 06:47 AM 2/18/00 -0500, Lorick wrote:
>I need to (hopefully) use the 16F876 to sample a sine wave that rides on a
>1.75v reference line, swinging from 0v to 3.5v but before I even attempt
>this, I'm thinking it won't work because if an average value of the sine
>wave is what's taken over time, then wouldn't I always get a reading
>somewhere near that 1.75v reference line?

It's not clear what you are doing here. Is this supposed to be a simple RMS
measurement, or you need details of the sine wave?

In the latter case, you seem to be assuming the mean value (DC component)
of the signal is 1.75 V precisely. Are you sure about this? If so, what's
the problem?

If you simply want to determine the average DC level, that's easy: just use
a low-pass digital filter. Even a simple moving-average will work fine.
What are the performance requirements?

If you need a 'rectified' signal, do it in software: record and analyze
samples separately for above and below 1.75 V. To rectify, difference from
1.75 V and flip the sign.

If you're worried about clipping at 0 V, add a 'bias' with an op-amp summer
before sampling.

================================================================
Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: @spam@ralspamspamKILLspamlcfltd.com
Least Cost Formulations, Ltd.                   URL: http://lcfltd.com/
824 Timberlake Drive                            Tel: 757-467-0954
Virginia Beach, VA 23464-3239                   Fax: 757-467-2947

"Vere scire est per causae scire"
================================================================

</x-flowed>

2000\02\18@083616 by Rich Leggitt

picon face
Hi Lorick, are you trying to measure the voltage? Assuming you can sample
at many times the actual frequency (like 30), then something like this
might work:

int peak, trough;                       // averages are here

// call for each sample taken
void process(int sample)
{
 static int prior, rising;             // stuff to remember

 if (sample > prior)                   // voltage is rising
 {
   if (!rising)                        // was it before?
   {
     rising = 1;                       // no, note it is now
     trough += (prior-trough)/k;       // prior sample is trough
   }
 }
 else                                  // else, voltage is falling
 if (rising)                           // was it before?
 {
   rising = 0;                         // no, note it is now
   peak += (prior-peak)/k;             // prior sample is peak
 }

 prior = sample;                       // remember prior sample
}

Hope this looks all pretty on your screen like it does on mine -- tabs
suck.

The 'peak += (sample-peak)/k' thing is the magic, it works exactly like an
RC filter. k is adjusted for your sample rate and jitter, noise floor,
etc., I'd start with 16 (rrf rrf rrf rrf, somebody let the dog out).

Anyway, peak voltage is (peak-trough)/2, don't trust no stinkin' DC bias
or the A/D either.

No doubt there's a better way, and hopefully someone will post it here so
I can swipe it.

-- Rich

On Fri, 18 Feb 2000, Lorick wrote:

{Quote hidden}

2000\02\18@093921 by Lorick

flavicon
face
> It's not clear what you are doing here. Is this supposed to be a simple
RMS
> measurement, or you need details of the sine wave?
>
> In the latter case, you seem to be assuming the mean value (DC component)
> of the signal is 1.75 V precisely. Are you sure about this? If so, what's
> the problem?

I'm not actually sure if I would be looking to make measurements of the
peaks or if an rms reading would be fine, but what I meant by 1.75v average
is that since that is the bias level, if I accidently took successive
readings at the peaks and troughs instead of just at all the peaks, the
overall average would look like 1.75v which would be wrong, it would be the
"0" level of the signal...
I am assuming that what I am after is a way to measure the peaks but here is
the whole description if it will help.
The signal I am working with is from an electret condenser microphone that
will be picking up a definite 1KHz audio signal from some test oscillator
circuit and speaker.  I am interested in detecting the volume level of the
sound source so that I can tell how far away it is based on how strong the
signal is.  The mic output will be signal conditioned to swing from 0 to
3.5v (working from single supply op amps) and I will be reading this volume
level with the a/d and I was trying to fiure out how the a/d would perceive
the audio.  If it reads a level of 2v, how would it know if this is a
maximum of the current waveform, or if it's the normalized zero crossing
point, thus it should be interpreted as zero instead of two in terms of
amplitude.
The pic is being run at 4MHz so far but that's just arbitrary, so I am
assuming this means I can sample WAY above the 1KHz signal frequency.  Now I
need to know exactly what it is I should be looking for to get the "volume"
level of the signal...

2000\02\18@094355 by Michael Rigby-Jones

flavicon
face
part 0 2603 bytes
<P><FONT SIZE=2 FACE="Arial">I need to (hopefully) use the 16F876 to sample a sine wave that rides on a</FONT>
<BR><FONT SIZE=2 FACE="Arial">1.75v reference line, swinging from 0v to 3.5v but before I even attempt</FONT>
<BR><FONT SIZE=2 FACE="Arial">this, I'm thinking it won't work because if an average value of the sine</FONT>
<BR><FONT SIZE=2 FACE="Arial">wave is what's taken over time, then wouldn't I always get a reading</FONT>
<BR><FONT SIZE=2 FACE="Arial">somewhere near that 1.75v reference line?</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Assuming a maximum swing signal, if a peak is measured in one instance in</FONT>
<BR><FONT SIZE=2 FACE="Arial">time at 3.5v, and then a trough is measured the next time at 0v, and then</FONT>
<BR><FONT SIZE=2 FACE="Arial">the middle of the signal is measured at 1.75v, the average of the 3 samples</FONT>
<BR><FONT SIZE=2 FACE="Arial">is 1.75v.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">What would be a proper method to sample a biased &quot;ac&quot; signal?&nbsp; Considering</FONT>
<BR><FONT SIZE=2 FACE="Arial">that the maximum voltage is 3.5v, I have ruled out the idea of rectifying</FONT>
<BR><FONT SIZE=2 FACE="Arial">the signal or something unless I can use a semiconductor junction that</FONT>
<BR><FONT SIZE=2 FACE="Arial">doesn't drop very much of that valuable signal level.</FONT>
</P>
</UL>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">To rectify signal under these conditions you use something called a &quot;precision rectifier&quot;.&nbsp; This scheme uses an op-amp with a diode in the feedback path, so the 0.7 volt odd voltage drop is canceled.&nbsp; You can even get precision rectifiers with True RMS detection built in, e.g<U> <A HREF="http://www2.national.com/ms/LB/LB-25.pdf" TARGET="_blank">http://www2.national.com/ms/LB/LB-25.pdf</A></U></FONT></P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Hope this helps</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Mike</FONT>
</P>

</BODY>
</HTML>
</x-html>

2000\02\18@102431 by Wagner Lipnharski

picon face
,,, so if you don't need to measure the absolute millivolts of the
senoidal signal captured by the mic, what counts for you is which signal
(circuit + speaker) made the max signal...

In this situation I would install a simple 1N4148 diode integrating the
signal over a cap + resistor and that's all.

Wagner

2000\02\18@114949 by Martin McCormick

flavicon
face
       You might get a pair of resistors of equal value between VCC
and Common to bias the A/D at its exact midpoint.  The path between
the biased sine wave signal and this junction between the A/D
converter and the resistors would be made with a DC blocking capacitor
so the DC bias on the audio would no longer matter.

       The resistors should be low enough in value such that the
sample-and-hold of the A/D converter will not load the circuit.  The
blocking cap will need to be large enough that its reactence is not a
factor in the frequency range to be used.

       The output of the A/D converter would read either 0x7F or 0x80
so your 0 crossing would be one or the other of those two values.  As
long as it doesn't drift much with temperature, you should be able to
resolve a sine wave 127 counts in one direction and 128 counts in the
other.

Martin McCormick

2000\02\18@122618 by Harold M Hallikainen

picon face
       What are you trying to accomplish, and what is your sample rate? If the
sample rate is at least twice the frequency of the sine wave, you can get
enough data to accurately reproduce the sine wave. As you point out, the
average will indeed by 1.75V. Averaging is the same as running the
incoming signal thru a low pass filter. If you want the RMS (which will
include the RMS of the DC), square the samples as they come in,
accumulate a sum of squares (I accumulate a 16 bit sum of 256 8 bit
samples), divide by the number of samples (that's why I use 256! It's
easy!), then take the square root using one of the recently posted
algorithms. That'll get you RMS.  If you want peak to peak, set up a RAM
location for minimum and maximum, then sample thru the cycle looking for
min and max. Subtract and there's the peak to peak.
       So... again, it comes down to what are you looking for (wasn't that a
line from "Third Rock from the Sun" where theyre spying on a neighbor and
one of them says "I wonder what he's looking for?").

Harold


On Fri, 18 Feb 2000 06:47:48 -0500 Lorick <spamBeGonelorickKILLspamspamTakeThisOuTAIR.ON.CA> writes:
{Quote hidden}

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

2000\02\18@123641 by Robert A. LaBudde

flavicon
face
<x-flowed>At 09:40 AM 2/18/00 -0500, Lorick wrote:
>The signal I am working with is from an electret condenser microphone that
>will be picking up a definite 1KHz audio signal from some test oscillator
>circuit and speaker.  I am interested in detecting the volume level of the
>sound source so that I can tell how far away it is based on how strong the
>signal is.  The mic output will be signal conditioned to swing from 0 to
>3.5v (working from single supply op amps) and I will be reading this volume
>level with the a/d and I was trying to fiure out how the a/d would perceive
>the audio.  If it reads a level of 2v, how would it know if this is a
>maximum of the current waveform, or if it's the normalized zero crossing
>point, thus it should be interpreted as zero instead of two in terms of
>amplitude.

If you are only interested in the power at a single frequency (1 kHz), you
can solve your problem with a hardware active bandpass filter @ 1 kHz, or a
software digital bandpass filter centered at the same frequency.

If you aren't sure about an exact frequency, a simple rectifier and
integrator (either passive or active) will provide a smoothed input to the
PIC. You can also do it in software by absolute value + moving average.


================================================================
Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: EraseMEral.....spamKILLspamlcfltd.com
Least Cost Formulations, Ltd.                   URL: http://lcfltd.com/
824 Timberlake Drive                            Tel: 757-467-0954
Virginia Beach, VA 23464-3239                   Fax: 757-467-2947

"Vere scire est per causae scire"
================================================================

</x-flowed>

2000\02\18@183045 by Ken Webster

flavicon
face
Lorick wrote:
>The signal I am working with is from an electret condenser microphone that
>will be picking up a definite 1KHz audio signal from some test oscillator
>circuit and speaker.  I am interested in detecting the volume level of the
>sound source so that I can tell how far away it is based on how strong the
>signal is.  The mic output will be signal conditioned to swing from 0 to
(snip)
>assuming this means I can sample WAY above the 1KHz signal frequency.  Now
I
>need to know exactly what it is I should be looking for to get the "volume"
>level of the signal...

The most precise measurement you could achieve in this case would be using a
software PLL (digital signal processing).  The signal from the microphone
will probably have a lot of background noise.  A software PLL combined with
an integrator to average the peaks and troughs of the signal (multiplied by
a time-domain windowing function) over a selected interval will give you the
same results as analysing a single band (the 1kHz band in this case) of a
discrete (fast) Fourier transform (FFT) performed using the same windowing
function and sampling rate.

In other words, this technique will give you an amplitude measurement of an
extremely narrow band (bandwidth depends on how long an interval you
integrate over) centered on your 1kHz signal.  Any noise that is not
precisely at 1kHz will be ignored.  It is not the simplest technique but it
can be implemented on a PIC with plenty of room and processing time to spare
(I used this technique on a PIC16C73 to measure a 60kHz signal -- 1kHz
should be a piece of cake!  I would be hapy to give you tips, pointers, and
sample code if you are interested).  The results are definitely worth the
effort if you want a precise measurement.

Cheers,

Ken

2000\02\19@155523 by paulb

flavicon
face
Lorick wrote:

> I need to (hopefully) use the 16F876 to sample a sine wave that rides
> on a 1.75v reference line, swinging from 0v to 3.5v but before I even
> attempt this, I'm thinking it won't work because if an average value
> of the sine wave is what's taken over time, then wouldn't I always get
> a reading somewhere near that 1.75v reference line?

 Yes.  The *average* value of any pure AC signal is zero, as it spends
equal areas under the signal curve in either direction.  So if you feed
your signal into a low-pass filter, you will get the same voltage with
and without signal.

 Although you say the reference line is 1.75V, it would probably be as
well to implement an averaging algorithm to determine exactly what this
is as read by the ADC.

 You probably want the standard FIR (Finite Impulse Response) filter
function of adding the current sample to a 16- bit value and subtracting
the "current average" which is 1/256 of the current tally.  Of course,
1/256 of the current tally is merely the high byte of the tally plus the
high bit of the low byte added (or in this case, both are being
subtracted from the tally itself) for rounding correction.

 Now that you know what the "zero level" is, you would prefer to sum
the squares of the instantaneous deviation from this level to measure
your signal level as a MS (Mean Squares - it's a waste of time to take
the square root again as the MS value is a perfectly good indicator).

 This however is messy as it involves multiplications and at least 24-
bit accumulation, presuming you again use a FIR filter to smooth it.
Instead, just sum the modulo of the deviation from the average (do the
subtract, test the result and negate if presently negative) using the
same averaging procedure.

 For a 1 kHz frequency, sample at approximately 16 k samples per second
to get 16 points per cycle and all the mathematics should be easy on a 4
MHz crystal PIC.

 This method still measures signal plus noise.  If you want to filter
out the signal at a (one only) precise frequency of 1 kHz, then you need
a different technique.
--
 Cheers,
       Paul B.

2000\02\20@133303 by Ken Webster

flavicon
face
>I would be interested in more information on this technique and some pic
>code to implement it.  Does this technique
>allow an input signal of wide bandwidth and then discriminate for the
center
>frequency of choice or does it assume
> a pre filtered limited bandwidth?


It allows a wide bandwidth.  Like any technique that samples a signal it is
susceptable to aliasing.  It is thus best to low-pass-filter the input so
that it does not excede the Nyquist frequency (one-half of the sample rate).

If you have some processing time to spare I would recommend sampling at a
high rate (20-40 ksps).  This way, a cheap RC lowpass filter can be used
outside of the PIC and still provide plenty of attenuation at the Nyquist
frequency.  If you sample slower you may want to consider using an active
filter with a steeper cutoff or perhaps an LC bandpass filter.

The code I have is written to deal with a 60kHz signal.  I would do a few
things differently for a 1kHz signal.  For a 1kHz signal I would recommend
the following:

1). Use CCP2 with TMR1 to generate the "special event" trigger that starts
an A/D conversion (every 50 microseconds to sample at 20kHz, 25 microseconds
for 40kHz).  Write an ISR to receive the A/D value and process it.  Here's a
chunk of code from my WWVB receiver that sets up the timer and A/D
interrupt:

    movlw  1
    movwf  t1con    ;timer1 internal clk, no prescale
    movlw  149
    movwf  ccpr2l   ;150 clk cycles (tosc/4)
    clrf  ccpr2h    ; = 37.5us with 16MHz osc
    movlw  0x0b
    movwf  ccp2con   ;enable ccp2 as comparator
;CCP2 generates the special event trigger which
;clears timer1 and starts an A/D conversion

    bsf  status,rp0
    movlw  2
    movwf  adcon1   ;RA0..3 analog inputs, Ref = Vdd
    bsf  pie1,adie  ;enable A/D peripheral interrupt
    bcf  status,rp0

    movlw  0x81
    movwf  adcon0   ;a/d clk = fosc/32, select ch 0
    bcf  pir1,adif  ;clr A/D int flag
    bsf  intcon,peie  ;enable peripheral interrupt
    bsf  intcon,gie  ;enable interrupts


2). Lowpass filter the A/D signal at a cutoff frequency just above 1kHz.
The filter should produce enough attenuation at 3kHz to reduce aliasing to
acceptable levels (the first harmonic that will be aliased to 1kHz is at
3kHz).  A really simple lowpass filter stage (doing something similar to an
analog RC filter) can be achieved by the following:

out = out + ((in - out) / n)

Since the processing time per stage is so low (if n is a power of 2 and can
be accomplished by a simple right-shift), several such stages can be
cascaded to achieve the desired cutoff slope.  I'm not sure what the formula
is to relate n to a cutoff frequency -- I usually just write a C program to
calculate the results and then experiment with n (choosing powers of 2 or
other easily calculatable values) until I get the results I want.

3). Resample the lowpass-filtered signal at 4ksps (i.e. pick out every 5th
value if your original sample rate was 20ksps or every 10th value if your
original sample rate was 40ksps).

4). Add the resampled values sequentially into 4 different accumulators.
The accumulators will correspond (if you use a PLL) to the rising zero
crossing, the positive peak, the falling zero crossing, and the negative
peak of the 1kHz signal.  If you don't use a PLL, you can get a complex
(phasor representation) signal measurement as follows:

r = (ACC2 - ACC4) / n
j = (ACC1 - ACC3) / n

Where n is the number of samples in the accumulators.  The measured
amplitude is simply sqrt(r*r + j*j).

Every so often (how long depends on how much frequency selectivity you need
and how often you need to get an amplitude measurement), you take the
results as shown above and then zero the accumulators.


You may find that this alone produces adequate results (no PLL and a simple
rectangular windowing function).  The longer you add samples into the
accumulators before using the average and zeroing the accumulators, the more
selective the frequency response will be.  If you average samples for too
long (long enough for the phase of the 1kHz signal to drift a substantial
amount relative to the sampling phase) then you will need to use a PLL to
precisely match the frequency of the signal.

A PLL can be implemented by adding or subtracting clock cycles from the A/D
sampling timer (by adjusting CCP2) so that each set of samples that go into
ACC1 and ACC3 are as close to the zero-crossing as possible.  If these
samples were exactly on the zero-crossing then S1-S3 would be zero (where S1
is the sample that gets added into ACC1 and S3 is the sample that gets added
into ACC3).  If the sampling points were late then S1-S3 would be positive.
If the sampling points were early then S1-S3 would be negative.  Thus, S1-S3
can be used as an error measurement to steer the phase of the A/D sampling.
If you are interested in doing this I could provide an example (but it is
pretty long and difficult to explain).

For really good noise rejection you may want to use a PLL along with a
windowing function to improve the frequency selectivity.  For more
information about windowing functions, see the following:

www.spd.eee.strath.ac.uk/~interact/moved/dft/window.html
www.engr.sjsu.edu/~knapp/HCIROD3D/3D_phys/Fou_note.htm
http://www.cooper.edu/~donahu/auFilter/auFilter.html

A triangle (Bartlett) window can be calculated using a coupple of running
sums and taking the difference for the ramp up and just using a running sum
for the ramp down.  At the slow 4ksps rate, other windowing functions
requiring multiplications are also possible.

I hope this helps and isn't overly confusing.

Cheers,

Ken


'Magic Sinewaves demystified'
2000\03\05@114431 by Scott Dattalo
face
flavicon
face
Well, at least partially...

It finally dawned on me yesterday how magic sine waves can be sythesized.
What's frustrating, is that the answer is so simple that it's obvious; so
obvious that it's been overlooked in the discussions we had off and on for
the last couple of years (at least by me). Lancaster is probably a
chuckling lurker :).

There are probably a few ways to go about it, but this is the one I tried.
Imagine how you'd go about synthesizing a sine wave if you had an A/D
converter. The most common way is to produce `N' samples for one sine wave
cycle and repeatedly write these to an A/D converter. The sine wave
frequency is determined by the rate at which the samples are written to
the A/D converter.

Now imagine replacing the A/D converter with a PWM generator that has the
same resolution. So for example, if you had a 12-bit A/D converter the PWM
generator would be capable of producing 4095 (2^12 - 1) different duty
cycles. Theoretically, the low-pass filtered output of the A/D converter
and the PWM are the same. Practically however, it's difficult to design a
filter that would have the proper cut-off characteristics. So to ease the
filter requirements, the PWM synthesized sine wave is usually made to be a
much higher frequency than the frequency at which samples are written to
the A/D converter.

Now when we, or at least I, begin to think about `magic sine waves' the
idea that the pwm frequency can be reduced is forgotten. Furthermore, we
constrain ourselves to the low-resolution 8 or 10 bit pwm generators that
are available in the various pic's. What the magic sine wave algorithm
does, AFAICT, is find a suitable time discretization for a high
resolution PWM synthesized sine wave.

So, there are two parts to the synthesis. Part 1 invovles finding the high
resolution PWM representation of the sine wave. Part 2 involves finding an
optimum way to make time discrete. The first part is easy and the attached
octave (or matlab) program will do this. The second part can be determined
using brute force search techniques. I don't have an elegant solution
though, but hopefully some others have some insight.


Scott

PS, this octave program is meant to be tool and otherwise not too useful
(in other words, I don't bother to explain hardly anything...)

% `magic'sine wave synthesis
%   The purpose of this program is to find an optimum pulse stream
% that when low pass filtered will produce a sine wave. The optimization
% criterion is to minimize the harmonics for a given number of pulses.


% by  T. Scott Dattalo 04MAR00
clear;
clg;
pulses = 32;

T = 1;              % Period
f = 1/T;            % fundamental frequency

tp = T/pulses;      % Time window for each pulse

t = [0:(pulses-1)]/pulses;
sine_samples = sin(2*pi*f * t);

ts = zeros(1,4*(pulses-1));
p = ts;

% create a pwm sine wave with edges based on floating point
% numbers:

for i=1:pulses

 ts(4*i) = t(i);
 ts(4*i+1) = t(i);
 ts(4*i+2) = t(i) + (1 + sine_samples(i))/2 * tp + 1000*eps;
 ts(4*i+3) = ts(4*i+2);
 p(4*i+0) = 0;
 p(4*i+1) = 1;
 p(4*i+2) = 1;
 p(4*i+3) = 0;

end

% Now calculate the harmonic content
harmonics = 20*pulses;
mag = zeros(1:harmonics);
ph  = zeros(1:harmonics);
phase = [0:(pulses-1)] * T/(pulses);
N = 1000;                 %Number of samples
sqwave = zeros(1:N);
u = [1:N]/N * T;          %Time vector

for n=1:harmonics
 w = n*2*pi/T;

 m=2;
 for m=1:(pulses)
   tau = (1 + sine_samples(m))/2*tp;
   d = tau/T;
   sqwave = sqwave + 2*sin(n*pi*d)/(n*pi)*cos(w*(u-tau/2-phase(m)));
   mag(n) = mag(n) + 2*sin(n*pi*d)/(n*pi)*cos(w*phase(m));
   ph(n) = ph(n) + cos(w*phase(m));
 end

end

sqwave = sqwave + 0.5 + 2;
dc = sum(sine_samples);
mag(2) = 0;
ti = sprintf('PWM Synthesis');
title(ti)
subplot(111)
%plot(t,sine_samples)
%subplot(212)
% plot the harmonics:
plot([0:harmonics-1]/pulses,abs(mag))
% uncomment to plot the square wave train re-synthesized from its
% harmonics
%plot(ts,p,u,sqwave)

2000\03\06@072604 by Andrew Kunz

flavicon
face
Scott,

You mean D/A converter, not A/D, right?  Otherwise, I'm confused.

Andy

2000\03\06@083018 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, Andrew Kunz wrote:

> You mean D/A converter, not A/D, right?  Otherwise, I'm confused.

D/A of course - sorry.


The octave (matlab) code posted yesterday had a bug in the harmonic
calculation. That's been fixed. In addition, I wrote another similar
octave program that will analyze an ascii string of 0's and 1's. Like the
other program, it plots the square wave that has been reconstructed from
its harmonics and it plots the magnitudes of the first few harmonics.
Here's a screen shot of a 12-bit string, "010110100000", produced by the
program:

http://www.dattalo.com/ms1.gif

and the programs:

http://www.dattalo.com/ms.m
http://www.dattalo.com/ms2.m


Scott

'[OT] Contracting business'
2000\03\06@095436 by Juimiin Hong

flavicon
face
Hi,

Recently the idea of becoming a contractor has crossed my mind.  For all
the contractors out there, how did you start your business?  Where did you
find your customers?

Thanks,
Juimiin

'Magic Sinewaves demystified'
2000\03\06@115039 by Grif\ w. keith griffith

flavicon
face
<x-flowed>At 10:44 AM 3/5/00 -0600, you wrote..
>It finally dawned on me yesterday how magic sine waves can be sythesized.

Major math snip:::

Scott:  doesn't your code produce an analog output?  I was of the opinion
the whole reason for the Magic part of the synthesis was using saturated
switching at a much higher freq than the final output and stuffing it thru
a low pass filter, getting a somewhat usable, higher power sine wave
output?  Or did I just learn something this early in the week???  ( that
would be good,,, then I wouldn't have to work as hard the rest of the week!)


'Grif'   N7IVS

</x-flowed>

'[OT] Contracting business'
2000\03\06@115301 by Chris Eddy

flavicon
face
#1:  Don't quit your day job until your side work is so heavy you can barely
keep up.

#2:  You really should be geared towards business.. dealing with late bills,
people skills, negotiating, etc... things that most engineers are not.

#3:  Your first year or two will be thin on income.  REAL thin.  Unless you
have high quality business lined up already.

#4:  Don't EVER quit on a project.  Word travels fast in our high tech
community.  Eat the loss if you must.

Juimiin Hong wrote:

> Hi,
>
> Recently the idea of becoming a contractor has crossed my mind.  For all
> the contractors out there, how did you start your business?  Where did you
> find your customers?
>
> Thanks,
> Juimiin

'Magic Sinewaves demystified'
2000\03\06@120514 by jamesnewton

face picon face
What language are these programs written in?

I am flagging these emails for follow up in a week or so (I'm crunched at
the moment) but I'm interested in a general purpose magic sinwave routine
code generator for the PIC.

---
James Newton spamjamesnewtonspamgeocities.com 1-619-652-0593
http://techref.massmind.org NEW! FINALLY A REAL NAME!
Members can add private/public comments/pages ($0 TANSTAAFL web hosting)


{Original Message removed}

'[OT] Contracting business'
2000\03\06@124743 by Andrew Kunz

flavicon
face
>#3:  Your first year or two will be thin on income.  REAL thin.  Unless you
have high quality business lined up already.

Sometimes other years, too.  Been there, done that.

Chris' other advice is good.

Personally, I found that if I ever want to go out on my own again, I will have a
SALES FORCE who can do the initial contact for me.  FWIW, my local FAI guy has
been really good about this.  But only because I've brought several $10K+
customers (repeaters, not one-time-buys) to him.  And be LOYAL to the guy,
whoever it is.

Never say anything bad about other customers to anybody (even your wife), no
matter what jerks they are.  We all get to act that way from time to time; be as
forgetful of their inadequacies as you'd like them to be of yours.

NEVER EVER EVER tell them a lie.  "It's almost ready." etc.

Andy

'Magic Sinewaves demystified'
2000\03\06@132106 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, "Grif" w. keith griffith wrote:

> At 10:44 AM 3/5/00 -0600, you wrote..
> >It finally dawned on me yesterday how magic sine waves can be sythesized.
>
> Major math snip:::
>
> Scott:  doesn't your code produce an analog output?  I was of the opinion
> the whole reason for the Magic part of the synthesis was using saturated
> switching at a much higher freq than the final output and stuffing it thru
> a low pass filter, getting a somewhat usable, higher power sine wave
> output?  Or did I just learn something this early in the week???  ( that
> would be good,,, then I wouldn't have to work as hard the rest of the week!)


True, the ultimate objective is to produce an analog output. However, the
goal with the so called 'magic sinewaves' is to find the MINIMUM number of
switch transitions. The resulting bit stream is filtered such that a sine
wave is produced. The reason for minimizing the transitions is because
some switches, particularly those associated with high power applications
like in AC inverters, require a significant amount of energy to switch or
cannot be efficiently switched at high frequencies. As an example, you may
have a sine wave synthesis circuit where you want to drive the gate of a
MOSFET directly from a pic I/O pin. Pic's have fairly beefy outputs,
however they're very weak when compared to real MOSFET drivers. But given
enough time, the PIC I/O can switch a MOSFET (assuming of course that Voh
is above Vgs threshold - i.e. logic level Vgs MOSFETs may be required). If
you attempted to drive the MOSFET at too high of frequency with this pic
I/O pin, then chances are that it will never switch!

In addition, if you can use harmonic cancellation, then the constraints on
the analog filter may be relaxed. PWM generated waveforms relax the filter
constraints by maximizing the switching frequency. If the PWM carrier is
100 times the sinewave you're trying to generate, then you're analog
filter is much easier to design. There aren't any harmonics (to an
approximation) between the sine wave frequency you're generating and the
carrier frequency of the PWM.

Magic sine waves explicitly remove these harmonics by strategically
placing the pulses (or edges). The pulses, when viewed individually,
contain harmonics at the fundamental (of the sine wave being generated)
and at all integer multiples above. But when the pulses are taken
together, the 2nd, 3rd and so on harmonics are cancelled. The number of
harmonics cancelled depends on the quantization of time for the edges. For
example, in the previous post, I had a graph of a 12-bit pulse stream
010110100000. The second and third harmonics were exactly cancelled, but
there is a 4th and 5th harmonic present. Doubling the number of pulses to
24 allows a pulse stream to be created that will cancel the 4th harmonic.
In general, if you have a pulse stream containing n! pulses, then it's
possible to exactly cancel the first n harmonics. However, n! grows rather
quickly. It's simply not practical to attempt to cancel the first 10
harmonics (after the fundamental) by creating a pulse stream containing
10! or 3,628,800 pulses.

Consequently, if you wish to cancel the first 10 harmonics but with a
pulse stream containing only a 1000 pulses, you're not going to achieve
your goal. However, you may discover a particular stream that exactly
cancels the 2nd, 3rd, and 4th, and attenuates the 5th through 10th
harmonics by 20dB. From that you may design an appropriate analog filter.

AFAIK, there is no way to apriori determine the appropriate length of the
pulse stream to achieve some required harmonic profile. I think
Lancaster's contribution to this technology is to discover certain lengths
that perform well - or at least better than pulses streams that are
slightly shorter or longer. What I'm playing around with is a way you can
study the characteristics of one stream versus another.

Scott

'[OT] Contracting business'
2000\03\06@140948 by mike

flavicon
face
>
>#4:  Don't EVER quit on a project.  Word travels fast in our high tech
>community.  Eat the loss if you must.
To expand on this.... Don't take on a job unless you KNOW you can do a
good job of it, and if there are potential problems areas, make sure
the customer knows this right from the start.
In general, deal with people the way you'd like to be dealt with. If
you do a good job you will get repeat business.

'Magic Sinewaves demystified'
2000\03\06@163855 by Wagner Lipnharski

picon face
Considering the sine wave PWM generated, I wonder about the totally
unpredictable harmonics from the combination of several different pulse
width along the stream.  Square waves are terrible to deal to avoid
harmonics, except when you know exactly the fundamental fo's and the
harmonics composition, otherwise, as a sine wave generator with variable
frequency, it is a real pain. The most comprehensible approach to avoid
them is using PWM cycles in the order of several MHz with prime numbers
as the base for level control, so they will not repeat or cause
alliasing.

Of course, a high "Q" active filter would be the best solution to avoid
harmonics, but again, or the fo is fixed or the active filter is
programmable too, what increase the cost. In this case, the D/A solution
(16 bits at least) turns to be much more economically attractive.

There is another technique that I call "Rolling Triangles" (nothing to
do with Rolling Stones...:), that is;  A triangle face is flat, as flat
is a digital signal, or a linear ramp generated by a constant current
circuit.  Rolling a Triangle, means that your program would set the
triangle face angle according to the sine value, or signal rotational
angle, and this is done by controlling charging current.  Suppose you
slice a 90¡ angle in 90 triangles, equally distributed in rotation, 1¡
per triangle, you would have the first quadrant of your sine-wave.  To
reduce the abrupt angle change between one triangle and another, several
other small triangles are inserted at the transition, you can think as
interpolation.

I use to say that the biggest mistake people do when looking at a sine
wave, is thinking about sine(x) functions, because it is related to a
flat point of view of who is laid on the floor. According to the wheel
point of view, it is just a plain and pure rotation, so the triangle
explanation makes effect. The interaction of those triangles with a
common panel (the floor, and the witness eyesight) we are able to see
only a bi-plane sinewave, when other polarization in different
dimensions are not allowed, as the magnetic and electric fields
modulating a base electrical signal. It wouldn't be nice to be able to
see this multidimensional sine wave interacting with several other
signals?

I first used the expression "Rolling Triangles" when produced a 3 phase
60Hz sine-wave, based on programmable constant current generators, and
high speed processors integrating more than 50 thousands small triangles
per cycle.  I was never able to do it with PWM, even with oscillators
close to MHz.

Later on I found out that changing the 60¡ angle of each triangle
vertice and connect thousands in a net style, it was possible to draw
and plot practically *any* 3 dimensional electrical surface
representation.

Isn't interesting how many different ways you can do the same thing?  I
use to say that there are several ways to skin a cat, you can really be
a winner if you end up with very few scratches...

Wagner.

Scott Dattalo wrote:

[some snip below]
{Quote hidden}

2000\03\06@165758 by David VanHorn

flavicon
face
<x-flowed>At 04:37 PM 3/6/00 -0500, you wrote:
>Considering the sine wave PWM generated, I wonder about the totally
>unpredictable harmonics from the combination of several different pulse
>width along the stream.  Square waves are terrible to deal to avoid
>harmonics, except when you know exactly the fundamental fo's and the
>harmonics composition, otherwise, as a sine wave generator with variable
>frequency, it is a real pain. The most comprehensible approach to avoid
>them is using PWM cycles in the order of several MHz with prime numbers
>as the base for level control, so they will not repeat or cause
>alliasing.


If you used a boxcar integrator, clocked at 2X, then you could get rid of
all the evens anyway.
I'm still looking for a way to nuke the odds.
(I know it's all odds in your app)

</x-flowed>

2000\03\06@172323 by David VanHorn

flavicon
face
<x-flowed>Actually, I am looking for a generalized technique that will let me strip
odd harmonics.
I have an application that's using the boxcar as I described, both to
indicate distortion level, and to subtract said distortion from a signal,
but the odd harmonics have me stumped.

I use one boxcar to take the signal, but of course it also passes the 2H,
3H, 4H... right on up, though past the 4th it's pretty well damped since
it's an eight cap boxcar :)  The second grabs the 2h and 4h components
perfectly, but I have no simple answer for 3h and 5h. (Maybe I only need
3h, but you get the idea.)

</x-flowed>

2000\03\06@203311 by Scott Dattalo

face
flavicon
face
On Mon, 6 Mar 2000, David VanHorn wrote:

> Actually, I am looking for a generalized technique that will let me strip
> odd harmonics.
> I have an application that's using the boxcar as I described, both to
> indicate distortion level, and to subtract said distortion from a signal,
> but the odd harmonics have me stumped.
>
> I use one boxcar to take the signal, but of course it also passes the 2H,
> 3H, 4H... right on up, though past the 4th it's pretty well damped since
> it's an eight cap boxcar :)  The second grabs the 2h and 4h components
> perfectly, but I have no simple answer for 3h and 5h. (Maybe I only need
> 3h, but you get the idea.)

If you had a square wave with a 50% duty cycle, there are no even
harmonics. Furthermore, the relative magnitude of the harmonics are
inversely proportional to their harmonic numbers. If you vary the duty
cycle to say 33%, you'll have no 3rd,6th, 9th harmonic, but some of the
evens will pop up. I don't think there's a way to arbitrarily kill the odd
harmonics. But you can do (at least) two things: vary the pulse width of
individual pulses and vary the number of pulses. The plot:

http://www.dattalo.com/ms1.gif

cancels the 2nd and 3rd harmonics. You could say that it consists of three
pulses; one twice as wide as the other. (But the program generating it had
4 bits for those 3 pulses...).

I don't have time right now to explain, but as I mentioned earlier, it's
possible to exactly cancel the first N harmonics. However, the number of
'time slots' or quantized positions at which the pulse edges may occur is
of the order of N! (factorial). There is technique that involves examining
the phases of the harmonics of the individual pulses. I found that pulses
can be collected into groups that totally cancel one another at a given
harmonic number. The smallest group I experimented with is just a pair.
For example, for the second harmonic, the pulses are grouped in pairs. One
pulse is 180 degrees out of phase with the other. The pairs for the second
harmonic are two pulses separated by one pulse. For the third harmonic,
the pulses are separated by two pulses.

2nd harmonic suppressed:
010100000000
000010100000

3rd harmonic suppressed:
010010000000
000100100000

Total pulse stream:
010110100000

So the objective is to discover the pairs that cancel at a given harmonic
and then to find a set of pulses that will have complete coverage for each
harmonic. I've done this for 24 pulses, but beyond that it gets pretty
hairy...

Scott

'Software RMS measurement of sine waves again'
2000\03\06@205841 by Lorick

flavicon
face
Weeks ago I was looking at ways to determine the RMS value of a sampled
waveform with the 16F876 and several suggestions were to take 256
measurements (for easy division later) and accumulate the sum of squares,
divide by number of samples, and square root to get the RMS value of the
readings.

Now I would like to know why this works....what is the mathematical
relationship between squaring the readings and obtaining the RMS in the end?

I know it's almost stupid to ask since we're talking about Root Mean Square
to begin with....but I  am indeed missing the in between steps in the
story...

2000\03\06@213005 by Jeff Davis

flavicon
face
On Mon, 6 Mar 2000, Lorick wrote:

> Now I would like to know why this works....what is the mathematical
> relationship between squaring the readings and obtaining the RMS in the end?
>
> I know it's almost stupid to ask since we're talking about Root Mean Square
> to begin with....but I  am indeed missing the in between steps in the
> story...

What squaring the values does is effectively eliminates the sign of the
number (+/-). If you were to simply take the average of all measurements
of a sine wave you would get zero. An RMS value is the average magnitude
of each reading without taking into account the sign of the reading.

Jeff

2000\03\06@221825 by Jeffrey D Spears

flavicon
face
Think about what you are trying to get: The Root of the Mean of
all the Squares -> Root Mean Square -> RMS by definition!



On Mon, 6 Mar 2000, Lorick wrote:

{Quote hidden}

Jeffrey D. Spears
University of Michigan
College of Engineering

``Double-E, can't spell gEEk without it!''
                       -Captain Gerald M. Bloomfield II, USMC
                        (my brother)

'Magic Sinewaves demystified'
2000\03\07@025109 by David VanHorn

flavicon
face
>
>
> If you had a square wave with a 50% duty cycle, there are no even
> harmonics. Furthermore, the relative magnitude of the harmonics are
> inversely proportional to their harmonic numbers. If you vary the duty
> cycle to say 33%, you'll have no 3rd,6th, 9th harmonic, but some of the
> evens will pop up. I don't think there's a way to arbitrarily kill the odd
> harmonics. But you can do (at least) two things: vary the pulse width of
> individual pulses and vary the number of pulses. The plot:


No, it's a problem of receiving a waveform that's synchronus to what I'm
doing,
but the waveshape is essentially random.
It may have any population of harmonics, but I'm only interested in the
fundamental, and whatever processing I do to it has to preserve the phase over
frequency. It can introduce an absolute shift, as long as it's constant.
(hence
the boxcar filter),

2000\03\07@062440 by Nikolai Golovchenko

flavicon
face
Hi Scott,

I never heard of "magic sinewaves" before, so I can be wrong. Anyway,
if I understand correctly, there are two goals in generating the pulse
sequence:
1) Minimize switching
2) Attenuate higher harmonics

I can't understand why you choose PWM to achieve this!

Okay, PWM has small number of transitions - two per PWM period.

Now harmonics. They appear as a result of PWM conversion and can be
thought of as quantization error. To reduce the quantization effect
the PWM resolution (and therefore frequency) must be increased.

The problem is: If you want to reduce errors(or harmonics), you have
to increase PWM frequency. On the other hand, increased PWM frequency
increases the number of transitions per unit of time. So these two
goals conflict with each other, don't they?

I can see another approach. A scheme to minimize quantization errors,
also known as "Scenix PWM".
               --------------
0..1 -----      | 1     +--- |
-----|+  |---o--|       |    |--o-------------
  --|+  |   |  | 0 ----+    |  |
  | -----   |  |       1    |  |
  |         |  --------------  |
  |         |   Quantizer      |
  |         |                  |
  |         -------  -----------
  |               |  |
  |             --------
  |             | +  - |
  |             |      |
  |    -------  --------
  |    |  -1 |      |
  -----| Z   |-------
       -------

Switching is determined by sampling frequency. Choose what you need or
can afford. In any case, the system is trying to eliminate
quantization error at every sample (unlike PWM), which leads to a
higher attenuation of harmonics at the same clock frequency. The
benefit is that you don't have to worry about pulse position, it's
done automatically. The noise is minimal at fundamental harmonic
frequency and increases with frequency. Probably there is a better
feedback variant (noise shaping filter) but this is the simplest and
the only one I know <G>.

Nikolai


On Monday, March 06, 2000 Scott Dattalo wrote:
{Quote hidden}

2000\03\07@093711 by Scott Dattalo

face
flavicon
face
On Tue, 7 Mar 2000, Nikolai Golovchenko wrote:

> Hi Scott,
>
> I never heard of "magic sinewaves" before, so I can be wrong. Anyway,
> if I understand correctly, there are two goals in generating the pulse
> sequence:
> 1) Minimize switching
> 2) Attenuate higher harmonics
>
> I can't understand why you choose PWM to achieve this!
>
> Okay, PWM has small number of transitions - two per PWM period.

Recall though that if you're generating a sinewave using PWM that there
are many PWM cycles for one period of the sinewave. In fact, the more the
better. The reason is because it becomes easier for an analog filter to
remove the PWM carrier frequency while passing the sinewave.

Now in some applications you want to minimize the number of transitions
because the switching losses are a significant factor. If you were to
limit yourself to say only two transitions per cycle, i.e. a square wave,
to generate or synthesize a sinewave then an analog filter would have a
whole lot of work to do. If you made the duty cycle 50% then the even
harmonics are suppressed and your analog filter would need to attenuate
the odds. But the third harmonic is so close to the fundamental that it's
difficult to effectively filter it without detrimentally affecting the
fundamental.

So the next step may be to say, well, I'm going to try two pulses per sine
wave cycle. If you study this case, you'll discover that it's possible to
suppress either the 2nd or the 3rd but not both (at least that's my
observation). So then you say, well, how about three pulses? It turns out
that this can be done: http://www.dattalo.com/ms1.gif. But the 4th and 5th
harmonics are fairly significant - almost as big as the fundamental. Now
to suppress the 4th and the 5th and so on harmonics requires more and more
pulses.


{Quote hidden}

<they hardly were the ones to first invent this...>

{Quote hidden}

But it is interesting to look at from this perspective (as opposed to
looking at an algorithm).

Scott

'[OT] Contracting business'
2000\03\07@100113 by Lawrence Lile

flavicon
face
Andy,

I have long thought that the tech-head engineer would need a smooth talking
salesman as a partner to make it a go.   Apparently, you solve this by
making good allies of people in the selling business anyway.  (smart.)

An Mchip rep or FAE would be a really good ally to have!

I've been working on ally relationships with a couple of other
manufacturer's reps - baiscally "If you need in-depth tech support and
programming for my parts, see this guy"  It helps if the supplier has some
kind of certification program similar to Mchip's "Certified PIC Geek" or
whatever they call it program.

How else does one go about drumming up business?  Advertise in the
classifieds next to the used bicycles?<G> Scmoooze with the bigwigs at the
Chamber of Commerce dinners?   Post a web page under "Inventors and
Crackpots - Get your Invention built here"?

-- Lawrence "one foot in the independant consulting business" Lile



{Original Message removed}

'Software RMS measurement of sine waves again'
2000\03\07@114813 by Harold M Hallikainen

picon face
On Mon, 6 Mar 2000 22:29:23 -0400 Jeff Davis <davisjrSTOPspamspamIS2.DAL.CA> writes:
{Quote hidden}

       This would be true IF we took the square root prior to taking the mean
(squared, took square root, accumulated sum, divided by number of
samples) since the square root of the square is one way of defining the
absolute value.
       However, in RMS, we first square the sample, then accumulate a sum, then
divide by the number of samples, THEN take the square root (hence Root
Mean Square). The reason for the squaring is because RMS is related to
the POWER of the waveform, and power has a squared term (either I^2*R or
V^2/R). So, RMS is a method of weighting so the higer amplitude signals
have more significance than they would with a straight averaging.


Harold



FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

'Magic Sinewaves demystified'
2000\03\07@141828 by Scott Dattalo

face
flavicon
face
On Tue, 7 Mar 2000, David VanHorn wrote:

> No, it's a problem of receiving a waveform that's synchronus to what I'm
> doing,
> but the waveshape is essentially random.
> It may have any population of harmonics, but I'm only interested in the
> fundamental, and whatever processing I do to it has to preserve the phase over
> frequency. It can introduce an absolute shift, as long as it's constant.
> (hence
> the boxcar filter),

?

What's your application? I don't understand the concept of 'constant phase
over frequency', when there's only one frequency involved. If there's a
frequency band then it does make some sense (but I tend to think in terms
of group delays [and bessel filters]). Are you building a tone decoder?
What's the bandwidth and center Frequency? Or are you building a PLL?

Scott

2000\03\07@154817 by Dan Michaels

flavicon
face
Scott wrote:
>
>Recall though that if you're generating a sinewave using PWM that there
>are many PWM cycles for one period of the sinewave. In fact, the more the
>better. The reason is because it becomes easier for an analog filter to
>remove the PWM carrier frequency while passing the sinewave.
>

Speaking of sinewaves generated via PWM, I once had the brilliant
idea I could use the PWM generated by a PIC73, along with some data
stored in EEPROM, to add cheapo voice output to an embedded system.
It was gonna be called the "Tiny Talker" [or maybe Tiny Skwauker].

You would probably have to limit the highest voice frequencies to
1-2 Khz or so, but it would probably sound as good as early skwauky
devices, and would cost you next to nothing to add to the embedded
system.

The fundamental frequency of 7-bit PWM on a 20Mhz PIC is 156 Khz.
That would give you 78 samples on a 2 Khz sinewave. Stick on a nice
1 Khz low-pass filter, and the PWM fundamental would be down about
44 dB.  [I think - the first thing you forget is all that EE math].

Think this could work?

Toodle Pip - (is that how it goes?)
- Dan Michaels
Oricom Technologies
http://www.sni.net/~oricom
==========================

2000\03\07@162730 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>What's your application? I don't understand the concept of 'constant phase
>over frequency', when there's only one frequency involved. If there's a
>frequency band then it does make some sense (but I tend to think in terms
>of group delays [and bessel filters]). Are you building a tone decoder?

Nope.  I'm switching an array of antennas, creating a phase shift on the RF
carrier, which is demodulated, and used to give a vector to the
transmitter. The problem is that the recovered waveform is rather
non-sinusoidal, so it has noise, plus odd products of the fundamental.

>What's the bandwidth and center Frequency? Or are you building a PLL?

It almost hasn't got one. The center frequency is entirely programmable,
and will shift during operation.
The current boxcar is equivalent to a filter with a center frequency
settable anywhere from 200hZ to 8kHz, with a bandwidth of about 1/2 Hz. The
boxcar passes higher harmonics fairly well, so I have a second boxcar
running at twice the speed, which causes the fundamental to drop out. This
output is inverted and summed with the first boxcar, giving me an output
that only has the fundamental, and odd harmonics.

Due to using boxcars, I can even make radical shifts in switching frequency
during operation, since the phase response of the boxcars is linear (they
are clocked right along with the antenna switching)

Say 10 "spins" at 200 hz, followed by 10 at 8000, and then 10 at 2000, or
set the switching speed per "revolution" according to a PN generator's
output, so that there is no way to modulate the transmitted carrier so as
to disturb my aquisition of the signal.


-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMWeBYFlGDz1l6VWEQJRHQCeMNf79D+BPSAherGgrdl6r1kLr/EAn1EK
kVLcsp/wAgdm+UI8KLRg5BVB
=o3+H
-----END PGP SIGNATURE-----

2000\03\07@163330 by Andrew Kunz

flavicon
face
Who you doing phased array for?  akunzSTOPspamspamKILLspamtdipower.com

Andy

'Magic Sinewaves demystified [OT]'
2000\03\07@170318 by Sean Breheny

face picon face
I knew the black helicopters and the aliens had to have SOMEONE from the
PICLIST working for them  ;-)

Sean

At 04:31 PM 3/7/00 -0500, you wrote:
>Who you doing phased array for?  @spam@akunz.....spamspamtdipower.com
>
>Andy
>
|
| Sean Breheny
| Amateur Radio Callsign: KA3YXM
| Electrical Engineering Student
\--------------=----------------
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
spamshb7.....spam.....cornell.edu ICQ #: 3329174

2000\03\07@171610 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 05:04 PM 3/7/00 -0500, Sean Breheny wrote:
>I knew the black helicopters and the aliens had to have SOMEONE from the
>PICLIST working for them  ;-)

You're not as far off as you might imagine, though it's not a black project
either.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMWpg4FlGDz1l6VWEQLQ0wCgoSeW26lPqeKKySBFixo04D+jrs8AoLUb
k2ZAJCh1+FSj5Ilsv//CwI0Q
=PHIY
-----END PGP SIGNATURE-----

2000\03\07@192806 by Grif\ w. keith griffith

flavicon
face
<x-flowed>Well,,, if he ain't a black box type,,, that'd make him an alien?
Do engineers count as aliens?  How about hams?

At 05:14 PM 3/7/00 -0800, you wrote:
{Quote hidden}

'Grif'   N7IVS

</x-flowed>

2000\03\07@194926 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 04:31 PM 3/7/00 -0800, \"Grif\" w. keith griffith wrote:
>Well,,, if he ain't a black box type,,, that'd make him an alien?
>Do engineers count as aliens?  How about hams?


I'm both.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMXNVYFlGDz1l6VWEQJAbQCgvozdC3bmCw6i+fENeFqe1l1NbOwAoKO6
6XcmFdu/pyK/mhQwWv7Zb4S7
=meB2
-----END PGP SIGNATURE-----

'[OT] Contracting business'
2000\03\08@022233 by Glen Torr

picon face
Howdy All,

This is a subject close to my situation at the moment, about 2.5 years ago I
took a part time job at a local University doing general electronics design
/ maintenance to fund my private development work. Since then I have taken
an additional half time contract for 6 months with the same employer.

The worry is that I can earn far more for general electronic work in a wage
environment than while contracting for hourly work in which I am working at
a considerabley higher and more focussed level.

I have to face the possibility that there is not a living to be made in
contract PIC programming... at least in Australia ( and I suspect most of
the rest of the world) at the present time.

In Aus at the moment, where I live, ycan earn considerabley more driving a
bus than developing PIC products.  I am not angry about this but it is hard
to understand why it is so.

Glen Torr

TorrTech (for the momentt)

'Magic Sinewaves demystified'
2000\03\08@034822 by Graeme Zimmer

flavicon
face
Hi Dave,

> Nope.  I'm switching an array of antennas, creating a phase shift on the
RF
> carrier, which is demodulated, and used to give a vector to the
> transmitter. The problem is that the recovered waveform is rather
> non-sinusoidal, so it has noise, plus odd products of the fundamental.

An excellent application for a PIC! A Doppler Direction Finder....

I trust that you have seen the original "DopplerScant" article from about 15
years ago?
(was it QST or HR?).

It was the first time that I saw mention of a Commutating Filter......
Strangely they seem to be rarely used today...

I would have a copy here somewhere if you want....

............... Zim

2000\03\08@063005 by paulb

flavicon
face
David VanHorn wrote:

> Due to using boxcars, I can even make radical shifts in switching
> frequency during operation, since the phase response of the boxcars is
> linear (they are clocked right along with the antenna switching)

 These are in fact digital implementations, are they not?

> Say 10 "spins" at 200 hz, followed by 10 at 8000, and then 10 at 2000,
> or set the switching speed per "revolution" according to a PN
> generator's output, so that there is no way to modulate the
> transmitted carrier so as to disturb my aquisition of the signal.

 Somehow, compensating for the phase shift in the IF and detector has
always worried me about that proposal.  How do you propose to do that?
--
 Cheers,
       Paul B.

'Magic Sinewaves demystified [OT]'
2000\03\08@070621 by Andrew Kunz

flavicon
face
My mother was a German alien until she naturalized.  Now she's an American.  I'm
a Native American - I was borneded here.

Andy

2000\03\08@130428 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>An excellent application for a PIC! A Doppler Direction Finder....

Well... Actually it's not exactly a pic.. It's an AVR project (8 MHz
AVR8535), but this part of the project is certainly applicable to both worlds.
(he said, edging twoard the door)

>I trust that you have seen the original "DopplerScant" article from about 15
>years ago? (was it QST or HR?).

Ancient history. It was a masterpice in it's time, but not anymore.

>It was the first time that I saw mention of a Commutating Filter......

That's what they called it, AofE calls it a boxcar integrator, which I
think is more descriptive.

It works like this:  I use one timer's int to step the antennas (eight of
them, could be four, could be more)
On switching from antenna X to antenna X+1, there is some phase shift
imposed on the carrier.
Although this is a step function, the receiver integrates it to some
degree, resulting in something between a pulse, and a level shift on the
audio output (a purist would tap the discriminator, I have a 10.7 MHz IF
input)
Over one scan cycle, you get a number of phase shifts, which are exactly in
sync with the antenna switching.
The boxcar integrator connects eight capacitors to the signal line, through
a high resistance, each for 1/8 of the scan cycle.
If you do this a lot, then the integrator averages up a waveform that
represents the phase shifts, which in a perfect world, would be a sine
wave. Unfortunately, there are reflections from odd angles, so you end up
with something rather less than a sine.

My device runs a second boxcar twice as fast, which averages up all the
even hamonic content of the waveform, which I level detect, and compare to
the level of the fundamental plus evens, (two ADC channels) which tells me
how "clean" the waveform is.  I then invert the even hamonic waveform, and
add it to the main, which gets rid of the evens pretty nicely.
Unfortunately, the third and to some degree the fifth, sail right on through.

After that is done, the signal is fed to an MF-6 filter, which is clocked
synchronusly with the antennas, and this filter effectively converts the
remaining waveform into a sine. At this point, I detect the level again,
and the zero crossings for phase information.

The original "dopplescant" and all it's clones run somewhere between 200
and 400 scans/sec, and do almost nothing to "clean up" the signal, relying
mostly on "eyeball integration".

I can vary my scan rate, even during aquisition, since all the filters are
clocked from the scan rate.
My low end is 200 Hz, for practical reasons, and high is 7812 Hz, because
of the divisor limitations of the timer I'm using to divide the 8 MHz proc
clock. 4 MHz is as fast as I can get to, and by the time I divide that down
for the MF-6 and the antenna steppers, we end up at 7812 scans/second.

The "dopplescant" simply lights the appropriate LED when it has a signal,
and lets you worry about everything else.
The other microprocessor units out there, average the data incorrectly, by
simply averaging the most recent sample with the average of the previous
samples. IOW:   90,90,90,.....90,90,90,270 = 180  in that system.
Obviously wrong, but that's what they do, and the nature of the system is
that you do get "wild" bearings fairly often, when a reflection is
momentarily stronger than the true signal path.

On each sample int (zero crossing ^ of the recovered sine), I take the 8
bit sample data, correct for an absolute offset, and current vehicle
heading (vampired from compass data or GPS if compass is not available),
and store it in an array of 16 samples.  If the harmonic content is too
high, or the amplitude too low, then the sample is skipped. Then the sample
is converted from radial form to polar form, which makes the rest easier.
(trust me)

Every 16th sample, I run vector calculus on the lot, to properly average
the bearing, though at this level it's simpler, since the radius is all
"1". The result is stored in another array of 16.

Each time that array fills, I run the vector calc again, this time with
vector and radius to worry about, and derive a "raw" bearing (though it's
hardly raw) and a supersample, which is stored in another array of 16.

That process is repeated again, allowing me to produce a good output on 16
scans, and superb output if the carrier stays present for 16^4 scans. (8
seconds at 7812 Hz)

For both the "raw" and the cooked samples, I convert back to radial, which
now gives me both a vector and a radius, and the radius indicates the
quality of the bearing.  Without running the math on it (approximate)
90,90,90,90,90,90,90,90,90,270 = something like 94 degrees, with a radius
of 0.9 or something similar.
You see the difference?
If the samples were really ratty, then you might have samples all over the
map, and I would still derive a bearing, but the radius would be a lot
closer to zero, indicating that I'm not very sure of my bearing.  The
radius information is used by the PC application to indicate confidence.

Each sample output is tagged with the current GPS location and heading
information, and put in my outbound sample buffer.

In the background, I am serving as half of a stat mux, taking data from
four serial ports, and two internal "virtual" ports, and creating variable
length packets to be sent out another serial port at 38400 baud, to a PC
application, which tears this stream apart, and sees all the data as
separate inputs again (important for laptops, which generally have only one
serial port!)

On the downstream side, I grab the data from the pc, parse the packets, and
output each channel's data to it's respective port, real or virtual. I also
manage handshaking on each port, signalling the host app through a command
channel, which ports can accept additional data. I also handle the cases
where packets were sent before I said "enough" by putting them in the
"holding bin" until the port frees up. (Command channel packets are not
queued, they are jammed into the flow as soon as the current packet
completes, since they are time sensitive)

In my spare time, I vampire the GPS and compass NMEA inputs for the
information I need, and apply that as corrections to the sampling, so that
you can take an accurate bearing while driving in a circle for example.

One final weakness of the original "dopplescant" was that you could
transmit a tone that was exactly at the antenna switching speed, and
confuse it pretty easily. Finding the exact tone was a little difficult,
but that's the only hard part.  My unit normally operates at the 7800 Hz
rate (for fast aquisition) but if it has trouble getting a bearing, it will
start hopping scan rates, according to the output of a PN generator
(internal background task) so the effect is similar to spread spectrum, in
that your jamming signal is spread, but my antenna scanning is always in
sync, so your jamming dissapears.

The display unit talks to the main board by SPI link, (low speed) and has
another AVR processor that presents the "raw" and "cooked" data on a ring
of bi-color LEDs, (tricky multiplexing, I'm using two lead leds) and a
bargraph, and sends me the state of three buttons that I use to configure
and control the system.

The PC application takes my datastream, and puts it on a moving map, with
you at the center, plots each bearing from the point where it was taken.
It also talks to other systems, through an RF data link, and plots their
reported bearings on the map, from wherever they were taken, and indicates
their current position, course, and speed as well.

So, if you decide to get on the ham bands without a licence, or make a
nuisance of yourself, you better be able to outrun me, because every time
you transmit, I'm going to know EXACTLY where you are, moving or not. It
only takes me about 2mS to grab a bearing that's better than any other
doppler unit on the market (more precise) and the longer the signal, the
more accurate I get.

The end market for this thing is serious hams like me, and certain
governmental bodies that have similar interests.
There is also a market for tracking tornadoes, as they emit significant RF
noise. I have already shown that I can accurately DF broadband noise
sources with this rig.

The really fun part is the vector math, which involves a square root
calculation for every 16 incoming samples, as part of an ISR. (The sqrt is
eleven lines of code)

Now, if you'll all don the blindfolds, and stand against the wall please? :)

But, I'm still looking for a reasonable way to remove the odd harmonics,
like the 2x boxcar does the evens.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMa/94FlGDz1l6VWEQIb9ACg5qcujxeGyHdjHgxzK2it1X/R98sAn3fu
6lHZvFzJ7n6C9HVey7u55rtN
=D59g
-----END PGP SIGNATURE-----

2000\03\08@131052 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  Somehow, compensating for the phase shift in the IF and detector has
>always worried me about that proposal.  How do you propose to do that?
>--
>  Cheers,
>        Paul B.


It's a constant offset. Just tune in a known transmitter (NWS on 162.5-ish)
and enter the true bearing, or point the vehicle at the transmitter, and
tell it to calibrate. It sweeps up the possible sample rates, and enters an
offset value for each scan rate, so even the group delay in the audio
circuits is taken care of.

I do accept audio input as from a speaker jack, but I prefer, and have the
circuitry for, a 10.7 MHz IF input, into my own demod, so as to eliminate
most of the variables.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMbBn4FlGDz1l6VWEQJoTQCdEgBqz4NGeIi7OQXTld0nRnHcwXEAn3aJ
pzJFMRwFmdv8w3+ExEwJgLsg
=b828
-----END PGP SIGNATURE-----

'[OT] Contracting business'
2000\03\08@144911 by l.allen

picon face
>
> In Aus at the moment, where I live, ycan earn considerabley more driving a
> bus than developing PIC products.  I am not angry about this but it is hard
> to understand why it is so.
>
> Glen Torr
>
> TorrTech (for the momentt)

Its no better in New Zealand.
Basically what I can see is that the electronics industry
sees technically minded folk as cheap labour, geeks that
do it for the love of it, easy meat.
The only trouble is these same employers, business
people etc are bleating they cant get enough skilled
people to run their businesses and need cheap foreign
migrants to fulfil the shortfall.
You want a decent income ... become an accountant or
make and sell your product direct to the consumer.

_____________________________

Lance Allen
Technical Officer
Uni of Auckland
Psych Dept
New Zealand

http://www.psych.auckland.ac.nz

_____________________________

'Magic Sinewaves demystified'
2000\03\08@155737 by paulb

flavicon
face
David VanHorn wrote:

> It's a constant offset. Just tune in a known transmitter (NWS on
> 162.5-ish) and enter the true bearing, or point the vehicle at the
> transmitter, and tell it to calibrate.  It sweeps up the possible
> sample rates, and enters an offset value for each scan rate, so even
> the group delay in the audio circuits is taken care of.

 The delay between altering scan rate and beginning to take readings
was my concern.  It would matter if you were truly using a spread
spectrum approach but as it seems you are just swapping frequencies and
allowing a substantial number of "sweeps" at each, this apparently is
diluted out.
--
 Cheers,
       Paul B.

2000\03\08@161445 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  The delay between altering scan rate and beginning to take readings
>was my concern.  It would matter if you were truly using a spread
>spectrum approach but as it seems you are just swapping frequencies and
>allowing a substantial number of "sweeps" at each, this apparently is
>diluted out.

I have a holdoff for the MF-6 to stabilize at the new clock, so it ignores
scans for a short while after each hop.

If I didn't have the MF-6 in there, then each sweep could be at a different
rate, but yes, the group delay of the receiver would become important, and
somewhat difficult to calibrate to. Maybe not, I haven't tried that.
I was thinking about an SS approach earlier (months) but didn't think it
would be that useful, and it prevents me from using the MF-6, which
definitely helps clean things up.
(Nice chip that!)

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMbsXoFlGDz1l6VWEQI3IwCeK7UoWEAXld9WKoGG0nV9N8x9WGwAoKOh
CUQjMS7aOr+qbE3Mqb9rrmSs
=qutQ
-----END PGP SIGNATURE-----

2000\03\08@171142 by paulb

flavicon
face
David VanHorn wrote:

> using the MF-6, which definitely helps clean things up.

 I thought the MF-6 was simply a switched-capacitor "boxcar" filter
like you are already using for the primary filter?  How does it reject
harmonics?
--
 Cheers,
       Paul B.

2000\03\08@231550 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>  I thought the MF-6 was simply a switched-capacitor "boxcar" filter
>like you are already using for the primary filter?  How does it reject
>harmonics?

I'm not really sure of the internals, but it's outputting a nice clean sine.
It's clocked a lot faster, 50x (actually 64X in my application) rather than
8x.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMdPOoFlGDz1l6VWEQKu+ACgoCT3QnOKQJ6aO861Wr8C7HSQioUAoIov
MBxW3BWFo5RKXa6m7LaT3jOb
=EwMY
-----END PGP SIGNATURE-----

2000\03\09@084059 by Graeme Zimmer

flavicon
face
Hi,

>   I thought the MF-6 was simply a switched-capacitor "boxcar" filter
> like you are already using for the primary filter?  How does it reject
> harmonics?

Switched capacitor filters are analogous to conventional multi oppamp
filters such as Biquad or State Variable.

They merely use the switched capacitor as a (sort of) digitally variable
resistor.

They don't respond to harmonics.

The Commutating Filter is a completely different beast, which DOES respond
to harmonics.

Personally, I think that Box Car Integrator is the wrong term for
these.......

cheers ............. Zim

2000\03\09@091810 by paulb

flavicon
face
Graeme Zimmer wrote:

> Switched capacitor filters are analogous to conventional multi oppamp
> filters such as Biquad or State Variable.

 Ah yes!  Now I recall.  A bit vague of me.

 I recall when a local magazine published a telephone modem using
switched capacitor filters, quite a while ago.  Had a bit of a bad
reputation which I take to indicate the difficulty of taming such a
beast implemented in discrete components with switching frequencies
floating about...

 In a single IC; a much better proposition.
--
 Cheers,
       Paul B.

2000\03\09@120729 by David VanHorn

flavicon
face
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>The Commutating Filter is a completely different beast, which DOES respond
>to harmonics.
>
>Personally, I think that Box Car Integrator is the wrong term for
>these.......


Well, that's what AofE calls them..

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOMf/KoFlGDz1l6VWEQJ24QCg0GIZrNL8ieoqAhQqq/f5w+RnbVQAoJFV
m4YhhFRcFjtzvK5/+zszxQ28
=sfEX
-----END PGP SIGNATURE-----


'[PIC]: Sine table'
2000\08\18@131753 by Andrew Kunz
flavicon
face
Anybody have a quick program to build a 128-point (or so) sine table?

Thanks.

Andy

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@132624 by Simon Nield

flavicon
face
Try using Excel or some other spread sheet to give you n values for the first pi/2, export is as a
text file and then paste in some retlws ?
add a couple of lines of code to invert and add 1 to the result when neccessary and Bob's your
mother's brother.

Simon

p.s. it's the weekend. phew!

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@132851 by M. Adam Davis

flavicon
face
Yeah, Excel.  Would you like:
128 points of a (full/half/quarter) wave
Full scale (0 and 255 are peak, 128 is mid)
Any other needs?

I can do this now.

-Adam

Andrew Kunz wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@133144 by Andrew Kunz

flavicon
face
Thanks.  I don't know what I was (not) thinking.

I got it done on my PC with MSVC.

THanks anyway.

Andy

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@133754 by Andrew Kunz

flavicon
face
part 1 334 bytes content-type:text/plain; charset=us-ascii


So nobody needs to ask the same dumb question as I just did...

Note that this program gives me 8-bit values to output to a parallel DAC (with
appropriate filtering), and that it takes advantage of the fact that the table
is symmetrical top to bottom but also on either side of the maxima.

Andy


(See attached file: sinetbl.c)



part 2 413 bytes content-type:application/octet-stream; (decode)

part 3 144 bytes
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@174649 by pandersn

flavicon
face
Hi Andy:

It's is interesting in that we all do it: bring sophisticated tools to
simple problems. It is hard to do  but we need to try to remember to set
back and think of simple solutions to problems. Saw some of the responses.
Liked the "use the spread sheet."

This tread reminded me of a book on design: The Design of Everyday Things.
Can't remember of author. He said he wrote the book because he was tired of
working with products - of all kinds - without a simple interface - one
that you can "look at and deduce proper operation" - for example the design
of the pattern of burners on a stove and the associated design of the panel
of switches. My GE at home is a loser! Ha.

Have a good weekend.

Phil Anderson.





On Friday, August 18, 2000 12:30 PM, Andrew Kunz [SMTP:akunz.....spamTDIPOWER.COM]
wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\18@220338 by Dan Michaels

flavicon
face
Phil Anderson wrote:
........
>This tread reminded me of a book on design: The Design of Everyday Things.
>Can't remember of author. He said he wrote the book because he was tired of
>working with products - of all kinds - without a simple interface - one
>that you can "look at and deduce proper operation" - for example the design
>of the pattern of burners on a stove and the associated design of the panel
>of switches. My GE at home is a loser! Ha.
>

author = Donald A. Norman - too bad the guys who designed the
insipid flashing 12:00 on the VCR machine never read the book.
And note - after 10 years, I still don't know how to set the
digital clock on my [used] car radio.

- danM

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\19@061459 by Alan B. Pearce

face picon face
>export is as a
>text file and then paste in some retlws ?

you could probably have a column of Retlw in excel so it gets included in the
export. It is some time since I tried to do a CSV export from excel, so cannot
remember if you can tell it to use spaces instead of commas.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2000\08\20@190127 by Tony Nixon

flavicon
picon face
Simon Nield wrote:
>
> Try using Excel or some other spread sheet to give you n values for the first pi/2, export is as a
> text file and then paste in some retlws ?
> add a couple of lines of code to invert and add 1 to the result when neccessary and Bob's your
> mother's brother.
>
> Simon
>
> p.s. it's the weekend. phew!
>
> --
> http://www.piclist.com hint: PICList Posts must start with ONE topic:
> [PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

Use the DT table maker.

Copy the column of data to the clipboard, paste into DT, press a button
and presto, a table of RETLW or DT type instructions is created ready
for saving or pasting directly into code.

http://www.picnpoke.com/demo/dtimg.html

--
Best regards

Tony

ICmicro's
http://www.picnpoke.com
KILLspamsalesspam_OUTspampicnpoke.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\21@072647 by Andrew Kunz

flavicon
face
So who uses assembly any more?  I do almost everything in C.

Andy









"Alan B. Pearce" <spam_OUTA.B.PearcespamTakeThisOuTRL.AC.UK> on 08/19/2000 06:13:26 AM

Please respond to pic microcontroller discussion list <.....PICLIST.....spamRemoveMEMITVMA.MIT.EDU>








To:      spam_OUTPICLISTTakeThisOuTspamEraseMEMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: [PIC]: Sine table








>export is as a
>text file and then paste in some retlws ?

you could probably have a column of Retlw in excel so it gets included in the
export. It is some time since I tried to do a CSV export from excel, so cannot
remember if you can tell it to use spaces instead of commas.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspamBeGonespamKILLspammitvma.mit.edu>

2000\08\21@073725 by Frank Adlam

flavicon
face
Well said Andy!

-----Original Message-----
From: Andrew Kunz [RemoveMEakunzspamBeGonespamspamTDIPOWER.COM]
Sent: Monday, August 21, 2000 1:26 PM
To: @spam@PICLISTspamspamMITVMA.MIT.EDU
Subject: Re: [PIC]: Sine table


So who uses assembly any more?  I do almost everything in C.

Andy









"Alan B. Pearce" <TakeThisOuTA.B.PearceKILLspamspam@spam@RL.AC.UK> on 08/19/2000 06:13:26 AM

Please respond to pic microcontroller discussion list
<.....PICLISTRemoveMEspamMITVMA.MIT.EDU>








To:      KILLspamPICLISTspamTakeThisOuTMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: [PIC]: Sine table








>export is as a
>text file and then paste in some retlws ?

you could probably have a column of Retlw in excel so it gets included in
the
export. It is some time since I tried to do a CSV export from excel, so
cannot
remember if you can tell it to use spaces instead of commas.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamspamSTOPspammitvma.mit.edu>

2000\08\21@091059 by Bob Ammerman

picon face
At the risk of starting a flame war...

Real (wo)men code in assembly (or if they are extra tough, binary) :-)


Just kidding of course. Both asm and "C" have their place. For typical
applications "C" is fine, but when you are trying to get the most possible
function out of the least possible hardware, you can't beat asm. (see my sig
line to figure out where I prefer to be).

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2000\08\21@092724 by Alan B. Pearce

face picon face
>At the risk of starting a flame war...

>Real (wo)men code in assembly (or if they are extra tough, binary) :-)


>Just kidding of course. Both asm and "C" have their place. For typical
>applications "C" is fine, but when you are trying to get the most possible
>function out of the least possible hardware, you can't beat asm. (see my sig
>line to figure out where I prefer to be).

I used to work on a machine where the assembler was known as REAL. It stood for
RElocatable Assembly Language. Anyone else here who used to work on QANTEL
systems???

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestEraseMEspammitvma.mit.edu>

2000\08\21@094138 by Scott Dattalo

face
flavicon
face
On Mon, 21 Aug 2000, Bob Ammerman wrote:

> At the risk of starting a flame war...
>
> Real (wo)men code in assembly (or if they are extra tough, binary) :-)
>
>
> Just kidding of course. Both asm and "C" have their place. For typical
> applications "C" is fine, but when you are trying to get the most possible
> function out of the least possible hardware, you can't beat asm. (see my sig
> line to figure out where I prefer to be).

True. If you need a slow sine, then fine. If you need a fast one then Eric's
6-cycle one can not be beat by any C-compiler (except those that support in-line
assembly).

Scott

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamRemoveMEmitvma.mit.edu>

2000\08\21@095218 by Andrew Kunz

flavicon
face
>Just kidding of course. Both asm and "C" have their place. For typical
>applications "C" is fine, but when you are trying to get the most possible
>function out of the least possible hardware, you can't beat asm. (see my sig
>line to figure out where I prefer to be).

I agree 100%.

"The right tool for the job."

Andy

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestEraseMEspammitvma.mit.edu>

2000\08\21@095629 by Andrew Kunz

flavicon
face
I need to generate a 48-63 Hz sine as part of a PLL for a power system (sync the
output to the line, slightly out of phase due to the power-generation lag time).
I have LOTS of time to make it do it's thing.

Andy









Scott Dattalo <spamscottspam_OUTspam@spam@DATTALO.COM> on 08/21/2000 09:42:11 AM

Please respond to pic microcontroller discussion list <spamPICLIST@spam@spamSTOPspamMITVMA.MIT.EDU>








To:      spamBeGonePICLISTspamBeGonespam@spam@MITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: [PIC]: Sine table








On Mon, 21 Aug 2000, Bob Ammerman wrote:

> At the risk of starting a flame war...
>
> Real (wo)men code in assembly (or if they are extra tough, binary) :-)
>
>
> Just kidding of course. Both asm and "C" have their place. For typical
> applications "C" is fine, but when you are trying to get the most possible
> function out of the least possible hardware, you can't beat asm. (see my sig
> line to figure out where I prefer to be).

True. If you need a slow sine, then fine. If you need a fast one then Eric's
6-cycle one can not be beat by any C-compiler (except those that support in-line
assembly).

Scott

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestRemoveMEspamRemoveMEmitvma.mit.edu

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestKILLspamspamspammitvma.mit.edu>

2000\08\21@101853 by Scott Dattalo

face
flavicon
face
On Mon, 21 Aug 2000, Andrew Kunz wrote:

> I need to generate a 48-63 Hz sine as part of a PLL for a power system (sync the
> output to the line, slightly out of phase due to the power-generation lag time).
> I have LOTS of time to make it do it's thing.

That's the kind of thing I wrote this for:

http://www.dattalo.com/technical/software/pic/picsine.html

The phase accumulators can be directly fed from a PLL.

Scott

ps. Beware, it's overly commented :).

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-request@spam@spammitvma.mit.edu>

2000\08\21@102932 by Andrew Kunz

flavicon
face
Thanks, Scott.

That'll be interesting reading.  I'm working the PLL from the angle of changing
time between steps rather than amplitude in order to keep phase locked (my only
input is a zero-crossing detector).  I also have to generate multiple waves,
since I'm generating "real" power not just a 110V household socket.

Andy











Scott Dattalo <TakeThisOuTscottspam_OUTspamDATTALO.COM> on 08/21/2000 10:20:51 AM

Please respond to pic microcontroller discussion list <KILLspamPICLIST.....spamTakeThisOuTMITVMA.MIT.EDU>








To:      TakeThisOuTPICLISTEraseMEspamRemoveMEMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: [PIC]: Sine table








On Mon, 21 Aug 2000, Andrew Kunz wrote:

> I need to generate a 48-63 Hz sine as part of a PLL for a power system (sync
the
> output to the line, slightly out of phase due to the power-generation lag
time).
> I have LOTS of time to make it do it's thing.

That's the kind of thing I wrote this for:

http://www.dattalo.com/technical/software/pic/picsine.html

The phase accumulators can be directly fed from a PLL.

Scott

ps. Beware, it's overly commented :).

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestRemoveMEspam.....mitvma.mit.edu

--
http://www.piclist.com hint: To leave the PICList
spampiclist-unsubscribe-requestKILLspamspamKILLspammitvma.mit.edu>

2000\08\21@103342 by Dan Michaels

flavicon
face
At 07:26 AM 08/21/2000 -0400, you wrote:
>So who uses assembly any more?  I do almost everything in C.
>
>Andy
>

Can you get **reliable** deterministic timing in C?

--
http://www.piclist.com hint: To leave the PICList
spampiclist-unsubscribe-requestspam_OUTspammitvma.mit.edu>

2000\08\21@103531 by Andrew Kunz

flavicon
face
Yes.

Andy








Dan Michaels <STOPspamoricomspam_OUTspamspamBeGoneLYNX.SNI.NET> on 08/21/2000 10:32:40 AM

Please respond to pic microcontroller discussion list <spam_OUTPICLISTspamspamBeGoneMITVMA.MIT.EDU>








To:      EraseMEPICLISTspamKILLspamMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: [PIC]: Sine table








At 07:26 AM 08/21/2000 -0400, you wrote:
>So who uses assembly any more?  I do almost everything in C.
>
>Andy
>

Can you get **reliable** deterministic timing in C?

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestRemoveMEspammitvma.mit.edu

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu>

2000\08\21@104140 by Dan Michaels

flavicon
face
And it's *obvious* to the programmer what it is?



At 10:35 AM 08/21/2000 -0400, you wrote:
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestspamspam.....mitvma.mit.edu>

2000\08\21@104557 by Andrew Kunz

flavicon
face
Sorry, forgot to add a wink ;-)

I use interrupts for long-period stuff (like the period between steps for my
sine generation).  When I need short items, I pad with NOPs and delay loops
(inline assembly works great).

Essentially the same way as with assembly code, just easier to comprehend.

Andy

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-request.....spam@spam@mitvma.mit.edu>

2000\08\21@104603 by Dan Michaels

flavicon
face
Let me re-issue:

And it's *obvious* to the programmer what it is?

How can you tell *exactly* how many cycles a routine takes
without looking at the assembly code?


At 10:35 AM 08/21/2000 -0400, you wrote:
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-request@spam@spam@spam@mitvma.mit.edu>

2000\08\21@110104 by Scott Dattalo

face
flavicon
face
On Mon, 21 Aug 2000, Andrew Kunz wrote:

> Thanks, Scott.
>
> That'll be interesting reading.  I'm working the PLL from the angle of changing
> time between steps rather than amplitude in order to keep phase locked (my only
> input is a zero-crossing detector).  I also have to generate multiple waves,
> since I'm generating "real" power not just a 110V household socket.

Perhaps, however I don't discuss the PLL part of it at all. I'm not sure how
your system is implemented. On one design I had to phase lock to a ~50-60 power
sine wave too. I found that zero-crossing information was unreliable. The reason
was that this was part of a power quality instrument and (almost) by definition
the "sine wave" is suspect. The jitter in zero crossing could be very large. So
instead, I wrote a single frequency 'DFT'. In other words, I did something like
this:

Assume f = f0

for one cycle's worth (delta t = 1/f)  of sine wave samples compute the
quadrature components:

sine_power = sum of (sine samples * sin(t*i))
cosine_power = sum of (sine samples * cos(t*i))

In other words, the integral of the unknown waveform multiplied by sine and
cosine functions was computed. You may also view this as two narrow FIR band
pass filters center about the frequency 'f'.

Now you can find the arc tangent of the ratio:

phase ~= arctan(sine_power/cosine_power)

to find the phase. This can then server as the control input to a PID algorithm.
The control output of course being the frequency. A simple proportional
algorithm could go something like:

If the phase is positive
 decrease the frequency slightly
else
 increase the frequency slightly

But beware, this can (will) have trouble locking. At the minimum, you'll need a
little part of 'D' in PID.

As you might expect, computing the division and then following that by arctan is
expensive (but doable...). So instead, I might suggest using the raw sine_power
and cosine_power terms. You may be lucky to just get away with only the
sine_power term. However, if your sine wave amplitude varies then the cosine
computation can help normalize the calculation.


Scott

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestspamspammitvma.mit.edu>

2000\08\21@110304 by Dan Michaels

flavicon
face
At 10:45 AM 08/21/2000 -0400, you wrote:
>Sorry, forgot to add a wink ;-)
>
>I use interrupts for long-period stuff (like the period between steps for my
>sine generation).  When I need short items, I pad with NOPs and delay loops
>(inline assembly works great).
>
>Essentially the same way as with assembly code, just easier to comprehend.
>
>Andy
>

This is how you get deterministic timing in C - by using inline assembly?
[guess it's difficult to get a straight answer on a monday morning].

- danM

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspamspamBeGonemitvma.mit.edu>

2000\08\21@110633 by Andrew Kunz

flavicon
face
>And it's *obvious* to the programmer what it is?
>
>How can you tell *exactly* how many cycles a routine takes
>without looking at the assembly code?

I said I don't WRITE much assembly code, but I still READ it!

The HiTech C compiler gives you the C with the assembly that it generates in the
.AS file.

Andy

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestKILLspamspammitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...