如圖1所示,在電角度從'π/3'到'π'的過程中,即扇區2和扇區3,U相和W相電流變化幅度最大且單調,幅度為3/2。同理,扇區4和扇區5,U相和V相電流變化幅度最大且單調,扇區6和扇區1,V相和W相電流變化幅度最大且單調。看下面ADC通道配置,處於磁區1時ADC1偵測V相電流,ADC2偵測W相電流,如我們預期的那樣,這就是這兩個ADC配置陣列的由來。
.ADCConfig1 = { MC_ADC_CHANNEL_4<<ADC_JSQR_JSQ4_Pos //V ,MC_ADC_CHANNEL_5<<ADC_JSQR_JSQ4_Pos //U ,MC_ADC_CHANNEL_5<<ADC_JSQR_JSQ4_Pos //U ,MC_ADC_CHANNEL_5<<ADC_JSQR_JSQ4_Pos //U ,MC_ADC_CHANNEL_5<<ADC_JSQR_JSQ4_Pos //U ,MC_ADC_CHANNEL_4<<ADC_JSQR_JSQ4_Pos //V }, .ADCConfig2 = { MC_ADC_CHANNEL_3<<ADC_JSQR_JSQ4_Pos //W ,MC_ADC_CHANNEL_3<<ADC_JSQR_JSQ4_Pos //W ,MC_ADC_CHANNEL_3<<ADC_JSQR_JSQ4_Pos //W ,MC_ADC_CHANNEL_4<<ADC_JSQR_JSQ4_Pos //V ,MC_ADC_CHANNEL_4<<ADC_JSQR_JSQ4_Pos //V ,MC_ADC_CHANNEL_3<<ADC_JSQR_JSQ4_Pos //W },
void R3_2_GetPhaseCurrents( PWMC_Handle_t * pHdl, ab_t* pStator_Currents )
LL_TIM_CC_DisableChannel(TIMx, LL_TIM_CHANNEL_CH4);
bSector = pHandle->_Super.Sector; hReg1 = *pHandle->pParams_str->ADCDataReg1[bSector] * 2; hReg2 = *pHandle->pParams_str->ADCDataReg2[bSector] * 2;
hReg1 = ADC1->JDR1 * 2; hReg2 = ADC2->JDR1 * 2;
switch(bSector) { case SECTOR_6: case SECTOR_1: /* A相电流不可用 */ /* B相电流 = B相零漂 - ADC采样值 */ wAux = ( int32_t )( pHandle->PhaseBOffset ) - ( int32_t )( hReg1 ); /* B相电流异常判断 */ if ( wAux < -INT16_MAX ) { pStator_Currents->b = -INT16_MAX; } else if ( wAux > INT16_MAX ) { pStator_Currents->b = INT16_MAX; } else { pStator_Currents->b = ( int16_t )wAux; } /* C相电流 = C相零漂 - ADC采样值 */ /* A相电流 = -C相电流 -B相电流 */ wAux = ( int32_t )( pHandle->PhaseCOffset ) - ( int32_t )( hReg2 ); wAux = -wAux - ( int32_t )pStator_Currents->b; /* A相电流异常判断 */ if ( wAux > INT16_MAX ) { pStator_Currents->a = INT16_MAX; } else if ( wAux < -INT16_MAX ) { pStator_Currents->a = -INT16_MAX; } else { pStator_Currents->a = ( int16_t )wAux; } break; }
void * R3_2_TIMx_UP_IRQHandler( PWMC_R3_2_Handle_t * pHandle) { TIM_TypeDef* TIMx = pHandle->pParams_str->TIMx; ADC_TypeDef * ADCx_1 = pHandle->pParams_str->ADCx_1; ADC_TypeDef * ADCx_2 = pHandle->pParams_str->ADCx_2; uint32_t ADCInjFlags; /* ADC状态检测 LL_ADC_FLAG_JSTRT为通道开始标志 LL_ADC_FLAG_JEOS为通道转换结束标志*/ ADCInjFlags = ADCx_1->SR & (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS); if ( ADCInjFlags == LL_ADC_FLAG_JSTRT ) { /* ADC转换已开始,但未完成*/ do { /* 等待转换结束 */ ADCInjFlags = ADCx_1->SR & (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS); } while ( ADCInjFlags != (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS) ); } else if ( ADCInjFlags == 0 ) { /* ADC转换未开始*/ while ( ( TIMx->CNT ) < ( pHandle->pParams_str->Tw ) ) { /* 等待一段时间,我配置的是3us */ } ADCInjFlags = ADCx_1->SR & (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS); if ( ADCInjFlags == LL_ADC_FLAG_JSTRT ) { /* ADC转换已开始,但未完成 */ do { /* 等待转换结束 */ ADCInjFlags = ADCx_1->SR & (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS); } while ( ADCInjFlags != (LL_ADC_FLAG_JSTRT|LL_ADC_FLAG_JEOS) ); } } else { /* ADC转换已结束 */ } /* 关闭ADC1和ADC2转换 */ LL_ADC_INJ_StopConversionExtTrig(ADCx_1); LL_ADC_INJ_StopConversionExtTrig(ADCx_2); /* 根据扇区设置下一个电流转换通道 */ ADCx_1->JSQR = pHandle->pParams_str->ADCConfig1[pHandle->_Super.Sector]; ADCx_2->JSQR = pHandle->pParams_str->ADCConfig2[pHandle->_Super.Sector]; /* 设置ADC1和ADC2触发源为内部 */ LL_ADC_INJ_SetTriggerSource(ADCx_1,pHandle->ADC_ExternalTriggerInjected); LL_ADC_INJ_SetTriggerSource(ADCx_2,pHandle->ADC_ExternalTriggerInjected); /* 使能ADC触发源 */ LL_TIM_CC_EnableChannel(TIMx, LL_TIM_CHANNEL_CH4); /* 开始转换 */ LL_ADC_INJ_StartConversionExtTrig(ADCx_1, pHandle->ADCTriggerEdge); LL_ADC_INJ_StartConversionExtTrig(ADCx_2, pHandle->ADCTriggerEdge); return &( pHandle->_Super.Motor ); }