旋转编码器软解码

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

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);

}
  • 7
    点赞
  • 90
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
ESP8266是一款支持Wi-Fi通讯的微控制器,而旋转编码器是一种常见的旋转输入设备。那么,关于ESP8266如何使用旋转编码器,我可以给您一些建议。 首先,为了使用旋转编码器,您需要将其连接到ESP8266的GPIO引脚。通常,旋转编码器有3个引脚,其中两个用于输出旋转方向信号,另一个用于输出脉冲计数信号。您可以将旋转编码器的引脚连接到ESP8266的GPIO引脚,并使用件中断或轮询来读取编码器的状态。 接下来,您需要编写代码来处理旋转编码器的信号。您可以使用ESP8266的开发环境(如Arduino)来编程。在代码中,您可以设置一个计数器来跟踪旋转编码器的脉冲计数,并根据旋转方向信号来增加或减少计数器的值。例如,当旋转编码器顺时针旋转时,计数器递增;当旋转编码器逆时针旋转时,计数器递减。 您可以根据您的需求,将旋转编码器的计数值用于控制其他设备的操作。例如,您可以使用计数器的值来调整电机的速度或控制蓝牙音箱的音量等。此外,您还可以使用ESP8266的Wi-Fi功能,将旋转编码器的状态数据发送到云端或其他设备进行远程监控和控制。 总之,通过将旋转编码器连接到ESP8266,并编写相应的代码,您可以实现对旋转编码器的监控和控制。这样,您可以将旋转编码器与ESP8266的强大功能相结合,实现更多有趣和实用的应用场景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_34309267

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值