MPS430 cordicPWM sine wave generator

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

formatting link

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

Reply to
miso
Loading thread data ...

formatting link

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

Reply to
bloggs.fredbloggs.fred

formatting link

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.

Reply to
miso

erprojects/609573.aspx

WM.

re literals in memory?

Thanks for taking the time with that lengthy explanation. Wiki has a suffic iently good article on it, an easy read

formatting link

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 prelo aded with the amplitude computed by CORDIC on the fly. CORDIC then makes se nse when he's using a very large number of phase samples way in excess of t he onboard RAM.

Reply to
bloggs.fredbloggs.fred

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

Jon

Reply to
Jon Kirwan

formatting link

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

--
"it's the network..."                          "The Journey is the reward" 
speff@interlog.com             Info for manufacturers: http://www.trexon.com 
 Click to see the full signature
Reply to
Spehro Pefhany

formatting link

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.

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.

--
John Larkin         Highland Technology, Inc 

jlarkin at highlandtechnology dot com 
 Click to see the full signature
Reply to
John Larkin

formatting link

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.

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.

Reply to
Spehro Pefhany

formatting link

I didn't need to save that much ram; the quarters thing needs more thinking and more runtime.

Even at 24 bits, I'd expect that lookup and interpolation would be pretty good, and certainly fast. Use 32-bit values in the lookup table. Sine isn't that radical a curve.

--
John Larkin         Highland Technology, Inc 

jlarkin at highlandtechnology dot com 
 Click to see the full signature
Reply to
John Larkin

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.

Reply to
miso

For dirty PWM sinewave, CORDIC is merely academic exercise.

The accuracy of interpolation of the Nth order with K nodes is O(1/K^(N+1)) The 16 bit accurate linear interpolation of sine requires LUT with 512 entries over a quarter of period. For 24 bit accuracy with linear interpolation, the LUT would be 8K entries; which is not very comfortable with FPGA. Cubic interpolation should perform to 24 bit accuracy with LUT of 512 entries; for the cost of increased complexity.

Here is the elegant way of generating precise sine and cosine waveforms with minimum math:

formatting link

Vladimir Vassilevsky DSP and Mixed Signal Consultant

formatting link

Reply to
Vladimir Vassilevsky

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.

--
John Larkin         Highland Technology, Inc 

jlarkin at highlandtechnology dot com 
 Click to see the full signature
Reply to
John Larkin

formatting link

Sixteen very small words.

Reply to
krw

An 8K table with 16 or 24 bits per entry is only 131 or 196 kbits, and even modest FPGAs have a lot more block ram than that.

This one has 8 channels, each with a 4Kx16 lookup table, using a modest FPGA with ram to spare.

formatting link

Each channel has a 48 bit phase accumulator and interpolation. We use

16 bit dacs clocked at 128 MHz.

OK, but a general DDS can't use memory of previous points to compute the next point. We like the freedom to do FM, or chirps, or jump instantly to any phase angle. A lookup table is static.

Many FPGA rams are dual-ported, which makes the interpolation even easier.

--
John Larkin         Highland Technology, Inc 

jlarkin at highlandtechnology dot com 
 Click to see the full signature
Reply to
John Larkin

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

--
?? 100% natural 

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Reply to
Jasen Betts

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.

Reply to
miso

phase

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

?-)

Reply to
josephkk

By a lot, it (almost) predates the IC.

Here is the original paper (1959):-

formatting link

It's one of those inventions that changes the world.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward" 
speff@interlog.com             Info for manufacturers: http://www.trexon.com 
 Click to see the full signature
Reply to
Spehro Pefhany

phase

Somehow that does not surprise me.

?-)

Reply to
josephkk

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.