UG-549
ADuCM310 Hardware Reference Manual
Rev. C | Page 38 of 192
The following example shows how to implement this:
int IdacOutC(int iChan, int iIdealVal)
{
ADI_IDAC_TypeDef *psIDAC[6] =
{pADI_IDAC0,pADI_IDAC1,pADI_IDAC2,pADI_IDAC3,pADI_IDAC4,pADI_IDAC5};
unsigned int iError; //Error as it is processed.
int iSh = 0x20;
do
{
iSh -= 0x08;
iError = IdacCor(iChan,iIdealVal,iSh); //Get correction.
}
while(iError>31 && iSh>0);
if (iIdealVal >=iSh)
psIDAC[iChan]->IDACDAT = (((iIdealVal-iSh)&0x3FF8)<<14) + (iError<<12); //Output
corrected value.
else
psIDAC[iChan]->IDACDAT = 0 + (iError<<12); //Output corrected value.
return 1;
}
int IdacCor(int iChan, int iIdealVal, int iShift)
{
int iVal; //14 bit value.
int iErr; //Error as it is processed.
iVal = iIdealVal-iShift; //Reduce 11 bit DAC by fraction of minor DAC.
//Add together errors from 11 bit DAC.
iErr = pIDACCOR->pusErr5[iChan][(iVal>>9)&0x1f];
iErr += pIDACCOR->pusErr2[iChan][(iVal>>7)&3];
iErr += pIDACCOR->pusErr4[iChan][(iVal>>3)&0xf];
iErr = ((iVal&0x7)*256 + iErr + iShift*256 - 0x8000*3)/256; //Minor val + error + shift.
return iErr;
}