Skip to main content
Topic: Controlling Air-Core gauges (Read 14815 times) previous topic - next topic

Re: Controlling Air-Core gauges

Reply #15
Are you sure about that?  Wouldn't you need sine to continue until 2Ï€?  I assume that you need to reverse the polarity of sine just like cosine (see Michael Z's graph, attached to his reply).

But I think you're right: You probably could use the H-Bridge to reverse the polarity, and maybe even both sine and cosine, as needed.

Re: Controlling Air-Core gauges

Reply #16
2π would be a full 360 degrees. I only need ~180. SINE is positive until π which is 180 degrees.

Anyone see a problem with using a h-bridge to reserve polarity?

Re: Controlling Air-Core gauges

Reply #17
redacted

Re: Controlling Air-Core gauges

Reply #18
[quote author="tiagom"]I am using WINAVR for coding and programming my micro processor. Do you/anyone know if it supports SINE and COSINE tables?[/quote]I have not used WinAVR, but I would expect there to be a math library that supports sin() and cos().  They might be expensive, though.

Another option is to generate the SINE/COSINE tables yourself.  What I've done in the past is write a C program (any language that can create a text file will work) that run on my main computer (not on the AVR) and writes out C source code for a table.  If you only need 8-bit accuracy, then use char, otherwise you'll need int.  As Michael said, just multiply by the value needed (128 for 8-bit, 512 for 10-bit, etc) then print the result to the file as a comma-delimited list.  Afterwards, you can compile this generated C source into your firmware for a low-overhead SIN/COSINE.  Check it into your source revision repository, because you probably won't need to generate it again.  It might require a lot of Flash program memory, but that's usually cheaper than CPU cycles these days.

Re: Controlling Air-Core gauges

Reply #19
There are several sine/cosine generators. They are used by the demoscene to precalc sinewaves for scrollers, plasma, rotozoomers, etc. The output is directly usable in sourcecode.

i.e.: http://www.pouet.net/prod.php?which=14718

I don't know what I used to use back in the days.. I kept  reusing my tables for many years ;)

 

Re: Controlling Air-Core gauges

Reply #20
Most DSP chips have a sine table built in to the ROM.  There can be educational, because you can see how they're aligned.  One particular 16-bit table ranged from -32766 to +32766, and I never figured out why they avoided +/-32767.  Also, I noted that the sine wave peaks were one index ahead of the Ï€/2 and 3Ï€/2 locations.  I only noticed this because you can generate cosine from sine with the right offset, and I was missing the full cosine peak until I adjusted the index by one.

What's curious, as well, is that I've seen FFT implementations that were specifically tuned for a particular DSP and yet they did not even access the built-in sine table.  Instead, they compiled in their own table just like you have to do with a non-DSP MCU.