⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldd.c

📁 ADI公司的关于光通讯模块的监控程序,在KEIL FOR ARM 的编译环境编译.程序大小约12K,芯片是ADu7020.
💻 C
字号:
// LDD.c

/********************************************************************/
/*                                                                  */
/*      Laser Diorde Driver Control                                 */
/*                                                                  */
/********************************************************************/

#include <ADuC7020.h>
#include "common.h"

void delay(int i){
    while (i >0)
    i--;
}

void InitLdd(void){

    WORD dac_final, dac_current;

    dac_final = ((PAV_MSB<<8) + PAV_LSB);

    for(dac_current=0; dac_current<dac_final; dac_current++){
        delay(100);
        DAC0DAT = (dac_current<<16);
    }    
    
    SetDac(1);              // Set DAC1 - ErRef

}

void SetDac(unsigned char channel){

    if(channel == 0){
    DAC0DAT = ((A2h[248]<<24) + (A2h[249]<<16)); // high byte + low byte
    }
    
    if(channel == 1){
    DAC1DAT = ((A2h[250]<<24) + (A2h[251]<<16)); // high byte + low byte
    }

    dac_update = FALSE;
}


/********************************************************************/
/*                                                                  */
/*      Laser Diorde Driver ER calibration                          */
/*                                                                  */
/********************************************************************/
void ErCalibration(BYTE mode){

    static HALFWORD erref_low, erref_high, immon_low, immon_high, slope, offset;
    static BYTE cal_low_done=0, cal_high_done=0;

    switch(mode){
        case 1:                 // store ERREF and IMMON setting data at normal temp (25degC)
            erref_low = DAC1DAT>>16;
            immon_low = (TXMOD_RAWDAT_MSB<<8) + TXMOD_RAWDAT_LSB;
            ER_CON=0;           // clear ER_CON resister
            cal_low_done=1;
            break;

        case 2:                 // store ERREF and IMMON setting data at high temp (85degC)
            erref_high = DAC1DAT>>16;
            immon_high = (TXMOD_RAWDAT_MSB<<8) + TXMOD_RAWDAT_LSB;
            ER_CON=0;           // clear ER_CON resister
            cal_high_done=1;
            break;

        case 3:                 // calculate compensation slope and offset
            if((cal_low_done==1) && (cal_high_done=1)){
                
                // slope is calculated in positive integer number multiplied by 1000
                slope = 1000*(erref_low - erref_high)/(immon_high - immon_low);
                offset = erref_low + (slope * immon_low)/1000;
                
                // store slope and offset
                ER_SLOPE_MSB = slope>>8;
                ER_SLOPE_LSB = slope&0x00FF;
                ER_OFFSET_MSB = offset>>8;
                ER_OFFSET_LSB = offset&0xFF;
                ER_CON=0;     // clear ER_CON resistser
            
            }
            break;
    }
}

/********************************************************************/
/*                                                                  */
/*      Laser Diorde Driver ER compensation                         */
/*                                                                  */
/********************************************************************/
void ErCompensation(void){

    HALFWORD erref, immon, slope, offset;
    
    immon = (TXMOD_RAWDAT_MSB<<8) + TXMOD_RAWDAT_LSB;                   // read Immon
    slope = (ER_SLOPE_MSB<<8) + ER_SLOPE_LSB;
    offset = (ER_OFFSET_MSB<<8) + ER_OFFSET_LSB;    

    if(offset > (slope  * immon / 1000)){
        erref = offset - (slope * immon / 1000);        // find compensated erref
        DAC1DAT = erref<<16;                            // update ERREF voltage

    // update DAC1 monitor value at I2C resisters
    ER_MSB = erref>>8;
    ER_LSB = erref&0x00FF;

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -