dialog program to calculate the sine table for 3 phase inverter
the number of points must be a multiply of six
this table is a simple sine table used from µC 908HCMR32 to create the
pulse train for the power stage a bridge with six Mosfets or IGBTs.
other tables adds 3th harmonics, this gives more voltage
;******** sine table with 192 base points
SINE_TABLE
DB 128T,132T,136T,140T,145T,149T,153T,157T
DB 161T,165T,169T,173T,177T,180T,184T,188T
DB 192T,195T,199T,202T,205T,209T,212T,215T
DB 218T,221T,223T,226T,229T,231T,234T,236T
DB 238T,240T,242T,244T,245T,247T,248T,250T
DB 251T,252T,253T,253T,254T,254T,255T,255T
DB 255T,255T,255T,254T,254T,253T,253T,252T
DB 251T,250T,248T,247T,245T,244T,242T,240T
DB 238T,236T,234T,231T,229T,226T,223T,221T
DB 218T,215T,212T,209T,205T,202T,199T,195T
DB 191T,188T,184T,180T,177T,173T,169T,165T
DB 161T,157T,153T,149T,145T,140T,136T,132T
DB 128T,124T,120T,116T,111T,107T,103T,099T
DB 095T,091T,087T,083T,079T,076T,072T,068T
DB 064T,061T,057T,054T,051T,047T,044T,041T
DB 038T,035T,033T,030T,027T,025T,022T,020T
DB 018T,016T,014T,012T,011T,009T,008T,006T
DB 005T,004T,003T,003T,002T,002T,001T,001T
DB 001T,001T,001T,002T,002T,003T,003T,004T
DB 005T,006T,008T,009T,011T,012T,014T,016T
DB 018T,020T,022T,025T,027T,030T,033T,035T
DB 038T,041T,044T,047T,051T,054T,057T,061T
DB 065T,068T,072T,076T,079T,083T,087T,091T
DB 095T,099T,103T,107T,111T,116T,120T,124T
Create a dialogue window with a button and a relative message routine
insert the code below in this routine
to calculate the sine function we need to include the "math.h"
the variables like "char cBuffer[50000];" are declared as global
the zero line has the value 128, from 128 to 255 the sine is positive
under 128 the sine is negative
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char cBuffer[50000];
char *ptrx;
#define CR 0x0D
#define LF 0x0A
void CCalcTabDlg::OnButCalc()
{
double pi=3.14159265359;
double value;
int ii;
int SinusMaxTab = 192;
int Umax = 127;
int sinus;
int MaxRow;
ptrx = cBuffer;
ptrx += sprintf(ptrx,";******** sine table with 192 base points %c%c",CR,LF);
ptrx += sprintf(ptrx,"SINE_TABLE%c%c",CR,LF);
MaxRow=0;
ii=0;
while(ii < (SinusMaxTab/2) )
{
value = Umax * sin((2 * pi) /SinusMaxTab * ii );
sinus = int(value + 0.5) + 128 ;
if(!MaxRow)ptrx += sprintf(ptrx,"%c%c DB %03dT",CR,LF,sinus);
else ptrx += sprintf(ptrx,",%03dT",sinus);
MaxRow++; if(MaxRow == 8) MaxRow=0;
ii++;
}
ptrx += sprintf(ptrx,"%c%c",CR,LF);
MaxRow=0;
while(ii < SinusMaxTab )
{
value = Umax * sin((2 * pi) /SinusMaxTab * ii );
sinus = int(value - 0.5) + 128;
if(!MaxRow)ptrx += sprintf(ptrx,"%c%c DB %03dT",CR,LF,sinus);
else ptrx += sprintf(ptrx,",%03dT",sinus);
MaxRow++; if(MaxRow == 8) MaxRow=0;
ii++;
}
ptrx += sprintf(ptrx,"%c%c",CR,LF);
CString m_strOutfilename="sinus192.inc";
CFile m_file;
if (!m_file.Open(m_strOutfilename,CFile::modeCreate|CFile::modeWrite,NULL))
{
AfxMessageBox("Error to open file");
}
else
{
m_file.Write(cBuffer,ptrx - cBuffer);
}
}