MPS430 cordicPWM sine wave generator

The eval kit is a whole $4.30 including shipping, and it comes 2nd day

Fedex.




The person coded the cordic, and then implemented the sine wave with PWM.

Not really getting what the CORDIC was used for..doesn't the MPS430 store literals in memory?
 
M

miso

Jan 1, 1970
0
Not really getting what the CORDIC was used for..doesn't the MPS430 store literals in memory?

I'm sure there is some cordic description on line, but I can describe it
reasonably well from memory. The cordic has a table of sines and
cosines. It essentially goes from 90 deg, 45 deg, 22.5 deg etc in
decreasing powers of two. I say essentially because what you do is
pretend the circle has a power of two number of degrees, i.e.256
degrees, 512, etc. This makes the algorithm easier to program.

The cordic takes the angle in question and uses a successive
approximation scheme to drive it to zero. That is, if you were looking
for the sine or cosine of 50 degrees, your first step would be to
subtract 45 degrees, which is a value in your table. You keep this up
until you have driven it to zero as best as you can. the accumulators
will contain the sine and cosine of the initial angle.

Now you could generate a sine wave with stored samples of the signal,
but that isn't very flexible. To generate a sine wave with a cordic, you
accumulate phase. That is you pick a phase step size which represents
the fraction of a sine wave that you are going to use in the
approximation. Say you wanted 1 degree steps. Then you would feed the
cordic 1, 2, 3, etc. Now if you set up your pretend circle to have 256
degrees in it, then the phase accumulator will always return to zero and
the sequence would continue. So your phase input is a digital sawtooth
signal.

But you could have picked the phase interval to be some number which
won't return to zero. Say you picked 3 degree steps. Then the sequence
would go 0,3,6...255, 2,5,8, etc. This allows for more flexibility in
generating the sine wave relative to the clock.

I haven't looked at code yet, but that should be how it is written, with
some foo I left out. As you do the successive approximation scheme, you
are basically rotating a vector from the initial starting point to zero.
The cordic causes the vector to expand, so you need to seed the cordic
with a scaled version of the vector. I 'd have to dig up a book to
explain this is detail, but it is well documented.

So the person I presume picked or let the user input a phase step, then
creates the sine and cosine on the fly. Those values are then generated
with a PWM type DAC. You get the sine and cosine at the same time. This
means you have a quadrature phase available if need be.

There is a PHd. dissertation at Stanford that is the bible of cordic
processing. The authors name (first or maybe last) is Ahmed, but if you
search Stanford library on line, you would find the dissertation. It is
or was in the Terman library, or perhaps Green. It was way better than
what you find in most signal processing books. At least 90% of PHd
dissertations aren't worth the paper they are printed on, but we built
multi-millions of chips using schemes out of that dissertation back in
the day.

Most DSP books will cover generation of sine and cosine with the
cordic, but Ahmed's dissertation covered the transcendental functions.
So you could linearize thermocouples with it, etc. Or as I stated in the
other post, take the arcsine and do a FSK demod.
 
I'm sure there is some cordic description on line, but I can describe it

reasonably well from memory. The cordic has a table of sines and

cosines. It essentially goes from 90 deg, 45 deg, 22.5 deg etc in

decreasing powers of two. I say essentially because what you do is

pretend the circle has a power of two number of degrees, i.e.256

degrees, 512, etc. This makes the algorithm easier to program.



The cordic takes the angle in question and uses a successive

approximation scheme to drive it to zero. That is, if you were looking

for the sine or cosine of 50 degrees, your first step would be to

subtract 45 degrees, which is a value in your table. You keep this up

until you have driven it to zero as best as you can. the accumulators

will contain the sine and cosine of the initial angle.



Now you could generate a sine wave with stored samples of the signal,

but that isn't very flexible. To generate a sine wave with a cordic, you

accumulate phase. That is you pick a phase step size which represents

the fraction of a sine wave that you are going to use in the

approximation. Say you wanted 1 degree steps. Then you would feed the

cordic 1, 2, 3, etc. Now if you set up your pretend circle to have 256

degrees in it, then the phase accumulator will always return to zero and

the sequence would continue. So your phase input is a digital sawtooth

signal.



But you could have picked the phase interval to be some number which

won't return to zero. Say you picked 3 degree steps. Then the sequence

would go 0,3,6...255, 2,5,8, etc. This allows for more flexibility in

generating the sine wave relative to the clock.



I haven't looked at code yet, but that should be how it is written, with

some foo I left out. As you do the successive approximation scheme, you

are basically rotating a vector from the initial starting point to zero.

The cordic causes the vector to expand, so you need to seed the cordic

with a scaled version of the vector. I 'd have to dig up a book to

explain this is detail, but it is well documented.



So the person I presume picked or let the user input a phase step, then

creates the sine and cosine on the fly. Those values are then generated

with a PWM type DAC. You get the sine and cosine at the same time. This

means you have a quadrature phase available if need be.



There is a PHd. dissertation at Stanford that is the bible of cordic

processing. The authors name (first or maybe last) is Ahmed, but if you

search Stanford library on line, you would find the dissertation. It is

or was in the Terman library, or perhaps Green. It was way better than

what you find in most signal processing books. At least 90% of PHd

dissertations aren't worth the paper they are printed on, but we built

multi-millions of chips using schemes out of that dissertation back in

the day.



Most DSP books will cover generation of sine and cosine with the

cordic, but Ahmed's dissertation covered the transcendental functions.

So you could linearize thermocouples with it, etc. Or as I stated in the

other post, take the arcsine and do a FSK demod.

Thanks for taking the time with that lengthy explanation. Wiki has a sufficiently good article on it, an easy read http://en.wikipedia.org/wiki/CORDIC

Your TI link states he does 100KHz PWM, but they can't mean that literally.They must mean the PWM counter is being clocked at 100KHz where it's preloaded with the amplitude computed by CORDIC on the fly. CORDIC then makes sense when he's using a very large number of phase samples way in excess of the onboard RAM.
 
J

Jon Kirwan

Jan 1, 1970
0
On Thu, 13 Dec 2012 20:27:46 -0800 (PST),
Your TI link states he does 100KHz PWM, but they can't mean
that literally. They must mean the PWM counter is being
clocked at 100KHz where it's preloaded with the amplitude
computed by CORDIC on the fly. CORDIC then makes sense when
he's using a very large number of phase samples way in
excess of the onboard RAM.

I think it was putting out 60Hz, if I remember correctly what
I read there.

Jon
 
S

Spehro Pefhany

Jan 1, 1970
0
The eval kit is a whole $4.30 including shipping, and it comes 2nd day
Fedex.

The person coded the cordic, and then implemented the sine wave with PWM.

Well, it's an interesting exercise.. it's done in FPGAs when you need
a lot of time resolution, but for a 64-point sine wave with fixed
phase, all you need is 16 words of lookup table.


Best regards,
Spehro Pefhany
 
S

Spehro Pefhany

Jan 1, 1970
0
I've done 16-bit in/out sine/cos by direct lookup; memory is cheap
these days. OK, once I folded it in half so that I only needed 32K
points in the table.

I was suggesting folding it in quarters.. you go forward through the
table to pi/2, backwards to pi, then repeat with the sign flipped.
That's probably what you meant anyway.
When ram is scarce, like in a small flash-based uP or a small FPGA,
table lookup with linear interpolation is fast and easy, for stuff
like trigs and thermocouples. Cordic looks like a lot more trouble
than it's worth, and I'd imagine that accumulation of rounding errors
would need a lot of thought.

We are doing more like 24bits with tens of thousands of samples per
cycle, and very finely adjusted phase differences between generated
signals. The CORDIC (COordinate Rotation DIgital Computer) algorithm
is a reasonable choice for that. It is the algorithm used to calculate
trig functions in your HP35.
 
M

miso

Jan 1, 1970
0
You simply don't get it. You can change the frequency on the fly with
the cordic without changing the sample rate. You simply change the phase
step.
 
Well, it's an interesting exercise.. it's done in FPGAs when you need
a lot of time resolution, but for a 64-point sine wave with fixed
phase, all you need is 16 words of lookup table.

Sixteen very small words.
 
J

Jasen Betts

Jan 1, 1970
0
You simply don't get it. You can change the frequency on the fly with
the cordic without changing the sample rate. You simply change the phase
step.

That doesn't make cordic special, the same can be, and is done with other DDS
methods.
 
M

miso

Jan 1, 1970
0
That doesn't make cordic special, the same can be, and is done with other DDS
methods.

The cordic is easily the most flexible method for transcendental
function computations. I've been through the math library at Stanford
looking for easy algorithms to do such computation. There are faster
schemes, but the cordic is the easiest. It is an indispensable tool. It
is way more valuable than just sine/cosine computation. It was the heart
of many m-ary DPSK demod schemes we integrated.

You can be sloppy on board level designs, but you need to be efficient
in chips, especially mixed-mode where the transistors are not fine geometry.
 
J

josephkk

Jan 1, 1970
0
A DDS phase accumulator and a sine lookup table will do that. We do
that on a bunch of products: for example, an FPGA with a 48 bit DDS
accumulator driving a sine table with interpolation, always clocked
at, say, 128 MHz. That's simple and really fast.

I think Cordic pre-dates DDS.

By a bit, it predates the old 8087 math coprocessor.

?-)
 
Top