旋转编码器软解码

旋转编码器软解码_第1张图片
英飞凌AURIX系列支持RDC软解码。如上图所示,主要使用PWMP和PWMN两路信号软件方式产生一对正弦激励信号(10K),旋变产生的SIN和COS信号返回给DSADC通道做软解码使用。
旋转编码器软解码_第2张图片
软解码初始化函数

void DSADC_RDC_Init(void)
{
	DSADC_ModuleInit();
	DSADC_RDC_ChannelInit();
	DSADC_GLOBRC.U = 0x30003;//restart CH0 conversion
}

初始化模块

void DSADC_ModuleInit(void)
{
	// create module config
	IfxDsadc_Dsadc_Config dsadcConfig;
	IfxDsadc_Dsadc_initModuleConfig(&dsadcConfig, &MODULE_DSADC);
	// initialize module
	IfxDsadc_Dsadc_initModule(&dsadc, &dsadcConfig);
}

RDC硬件配置

void DSADC_RDC_ChannelInit(void)
{

    boolean                         result = TRUE;
    IfxDsadc_Rdc_Config             config;
    IfxDsadc_Rdc_ConfigHw           ConfigHw;
    IfxDsadc_Dsadc_CarrierGenConfig configCarrier;
    IfxDsadc_Dsadc_ChannelConfig    configChannel;

    /* FIXME add initConfig() */
    int signDelay = 1;                                                                            /* APPLICATION SPECIFIC */

    /** Carrier generation configuration */
    configCarrier.bitReversed         = TRUE;                                           		/* Default */
    configCarrier.carrierWaveformMode = IfxDsadc_CarrierWaveformMode_sine;              		/* Default */
    configCarrier.frequency           = 10e3;                                           		/* Default. This is only the expected frequency, real frequency may differ */
    configCarrier.inverted            = FALSE;                                          		/* Default */
    configCarrier.pinDriver           = IfxPort_PadDriver_cmosAutomotiveSpeed1;         		/* Default. recommended, but it can be also board specific. */
    configCarrier.pinMode             = IfxPort_OutputMode_pushPull;                    		/* Default. recommended, but it can be also board specific. */
    configCarrier.pinNeg              = &IfxDsadc_CGPWMN_P33_11_OUT;                     		/* APPLICATION SPECIFIC */
    configCarrier.pinPos              = &IfxDsadc_CGPWMP_P33_12_OUT;                     		/* APPLICATION SPECIFIC */

    /** Default configuration for one DSADC resolver input channel  */
    configChannel.auxFilter.bypassed             = TRUE;                                        /* Default. Don't change */
    configChannel.auxFilter.combFilterShift      = IfxDsadc_AuxCombFilterShift_noShift;         /* Don't care, unused */
    configChannel.auxFilter.combFilterType       = IfxDsadc_AuxCombFilterType_comb1;            /* Don't care, unused */
    configChannel.auxFilter.decimationFactor     = 4;                                           /* Don't care, unused */
    configChannel.auxFilter.eventGate            = IfxDsadc_AuxGate_definedByESEL;              /* Don't care, unused */
    configChannel.auxFilter.eventSelect          = IfxDsadc_AuxEvent_everyNewResult;            /* Don't care, unused */
    configChannel.auxFilter.serviceRequest       = IfxDsadc_AuxServiceRequest_never;            /* Default. Don't change */

    configChannel.channelId                      = 0;                                           /* Don't care, will be overwritten by driver */
	configChannel.channelPins                    = NULL_PTR;                                    /* Don't care, will be overwritten by driver */

    configChannel.combFilter.bypassed            = FALSE;                                       /* Default. Don't change */
    configChannel.combFilter.combFilterShift     = IfxDsadc_MainCombFilterShift_shiftBy3;       /* APPLICATION SPECIFIC */
    configChannel.combFilter.combFilterType      = IfxDsadc_MainCombFilterType_comb3;           /* APPLICATION SPECIFIC */
    configChannel.combFilter.decimationFactor    = 16;                                          /* APPLICATION SPECIFIC */
    configChannel.combFilter.serviceRequest      = IfxDsadc_MainServiceRequest_everyNewResult;  /* Default. Don't change */
    configChannel.combFilter.startValue          = 1;                                           /* Default. Don't change */

    configChannel.demodulator.inputDataSource    = IfxDsadc_InputDataSource_onChipStandAlone;   /* Default. Don't change */
    configChannel.demodulator.integrationTrigger = IfxDsadc_IntegratorTrigger_alwaysActive;     /* Default. Don't change */
    configChannel.demodulator.sampleClockSource  = IfxDsadc_SampleClockSource_internal;         /* Default. Don't change */
    configChannel.demodulator.sampleStrobe       = IfxDsadc_SampleStrobe_sampleOnRisingEdge;    /* Default. Don't change */
    configChannel.demodulator.timestampTrigger   = (INVERTER_TRIGGER_RISING_EDGE_AT_PERIOD
                                                    ? IfxDsadc_TimestampTrigger_fallingEdge
                                                    : IfxDsadc_TimestampTrigger_risingEdge);
    configChannel.demodulator.triggerInput       = IfxDsadc_TriggerInput_a;                     /* APPLICATION SPECIFIC */

    configChannel.firFilter.dataShift            = IfxDsadc_FirDataShift_shiftBy2;              /* APPLICATION SPECIFIC */
    configChannel.firFilter.fir0Enabled          = TRUE;                                        /* APPLICATION SPECIFIC */
    configChannel.firFilter.fir1Enabled          = TRUE;                                        /* APPLICATION SPECIFIC */
    configChannel.firFilter.internalShift        = IfxDsadc_FirInternalShift_noShift;           /* APPLICATION SPECIFIC */
    configChannel.firFilter.offsetCompensation   = TRUE;                                        /* Default. Don't change */

    configChannel.integrator.discardCount        = signDelay + 1;                               /* Default */
    configChannel.integrator.integrationCount    = 16;                                          /* Default */
    configChannel.integrator.integrationCycles   = 1;                                           /* Default. Don't change */
    configChannel.integrator.windowSize          = IfxDsadc_IntegrationWindowSize_internalControl;/* Default. Don't change */

    configChannel.modulator.commonModeVoltage    = IfxDsadc_CommonModeVoltage_b;                /* Default */
    configChannel.modulator.inputGain            = IfxDsadc_InputGain_factor1;                  /* Default */
    configChannel.modulator.inputPin             = IfxDsadc_InputPin_a;                         /* Don't care, will be overwritten by driver */
    configChannel.modulator.modulatorClockFreq   = 10.0e6;                                      /* Default. This is only the expected frequency, real frequency may differ */
    configChannel.modulator.negativeInput        = IfxDsadc_InputConfig_inputPin;               /* Default. Don't change */
    configChannel.modulator.positiveInput        = IfxDsadc_InputConfig_inputPin;               /* Default. Don't change */

    configChannel.module                         = &MODULE_DSADC;                               /* Default */

    configChannel.rectifier.enabled              = TRUE;                                        /* Default. Don't change */
    configChannel.rectifier.signDelay            = signDelay;                                   /* Default */
    configChannel.rectifier.signPeriod           = 16;                                          /* Default */
    configChannel.rectifier.signSource           = IfxDsadc_RectifierSignSource_onChipGenerator;/* Default */

    /** Hardware configuration for DSADC resolver interface */
    ConfigHw.carrierGen                          = configCarrier;

    /* Here DSADC event is connected into a TIM channel. In this example, TIM0 CH0 is used.
     * Then, from tc27xC_um_v2.0OM.pdf Table 26-72 or Table 26-73, MUX value of b1011 is obtained */
    ConfigHw.gtmTimestamp.gtm                    = &MODULE_GTM;
    /* IfxGtm_ATOM0_7_TOUT7_P02_7 can be connected to TIM1 CH7 with mux. value b0001 */
    ConfigHw.gtmTimestamp.pwmTim                 = &IfxGtm_TIM1_7_TIN7_P02_7_IN;
    ConfigHw.gtmTimestamp.rdcTim                 = IfxGtm_Tim_1;
    ConfigHw.gtmTimestamp.rdcTimChannel          = IfxGtm_Tim_Ch_0;
    ConfigHw.gtmTimestamp.rdcTimMuxValue         = 11;

    ConfigHw.inputConfig                         = configChannel;

	ConfigHw.inputSin                           = IfxDsadc_ChannelId_1;
	ConfigHw.inputCos                           = IfxDsadc_ChannelId_0;

    ConfigHw.outputClock                         = NULL_PTR;
    ConfigHw.servReqPriority                     = IFX_INTPRIO_DSADC_CH0_PRIO;
    ConfigHw.servReqProvider                     = 0;
    ConfigHw.startScan                           = FALSE;

    /** Configuration for DSADC resolver interface */
    /* set ALL gain to zero for using default values */
    config.kd                = 0;
    config.ki                = 0;
    config.kp                = 0;
    config.errorThreshold    = 1.0f / 180 * IFX_PI;                                 /* Default */
    config.hardware          = ConfigHw;
    config.offset            = 0;     										    	/* APPLICATION SPECIFIC */
    config.periodPerRotation = 3;       											/* APPLICATION SPECIFIC */
    config.resolution        = 4096;    											/* APPLICATION SPECIFIC */
    config.reversed          = 0;       											/* APPLICATION SPECIFIC */
    config.speedLpfFc        = 35;//30~100                                                 /* Default */
    config.sqrAmplMax        = 3500*3500;//2700*2700                                /* APPLICATION SPECIFIC */
    config.sqrAmplMin        = 1000*1000;//2100*2100                                /* APPLICATION SPECIFIC */
    config.userTs            = 0.0001; 												/* Default */
    config.dsadc             = &dsadc;                              				/* Default */

    result                  &= IfxDsadc_Rdc_init(&Rdc, &config);
    result                  &= IfxDsadc_Rdc_stdIfPosInit(&dsadcRdc, &Rdc);

}

你可能感兴趣的:(旋变,软解码)