完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用STM32 FOC 5.2的电机库,硬件做电流采样时使用的是海外放大,但电机库中使用的是同向放大,ST的配置上位机中的电流采样参考图:不过是
我们的电流采样电路如下: 所以要修改ST的FOC电机库源码,路径是:。./MCSDK_v5.2.0-Full/MotorControl/MCSDK/MCLib/F1xx/Src/r3_hd2_pwm_curr_fdbk.c对应如下内容: void R3HD2_GetPhaseCurrents( PWMC_Handle_t * pHdl, Curr_Components* pStator_Currents ) { uint8_t bSector; int32_t wAux; PWMC_R3_HD2_Handle_t * pHandle = (PWMC_R3_HD2_Handle_t *) pHdl; /* Deactivate TIMx CH4 to disable next triggers using bit-banding access */ *(uint32_t*) (pHandle-》wTIMxCH4_BB_Addr) = 0u; /* Reset the SOFOC flag to indicate the start of FOC algorithm*/ pHandle-》bSoFOC = 0u; bSector = (uint8_t) pHdl-》hSector; switch ( bSector ) { case SECTOR_4: case SECTOR_5: /* Current on Phase C is not accessible */ /* Ia = PhaseAOffset - ADC converted value) */ wAux = (int32_t)( ADC1-》JDR1 ); wAux *= 2; wAux = wAux - (int32_t)( pHandle-》wPhaseAOffset ) ; /* Saturation of Ia */ if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component1 = -INT16_MAX; } else if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component1 = INT16_MAX; } else { pStator_Currents-》qI_Component1 = (int16_t) wAux; } /* Ib = PhaseBOffset - ADC converted value) */ wAux = (int32_t)( pHandle-》pParams_str-》ADCx2-》JDR1 ); wAux *= 2; wAux = wAux - (int32_t)( pHandle-》wPhaseBOffset ) ; /* Saturation of Ib */ if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component2 = -INT16_MAX; } else if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component2 = INT16_MAX; } else { pStator_Currents-》qI_Component2 = (int16_t) wAux; } break; case SECTOR_6: case SECTOR_1: /* Current on Phase A is not accessible */ /* Ib = PhaseBOffset - ADC converted value) */ wAux = (int32_t)( ADC1-》JDR1 ); wAux *= 2; wAux = wAux - (int32_t)( pHandle-》wPhaseBOffset ) ; //Ib /* Saturation of Ib */ if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component2 = -INT16_MAX; } else if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component2 = INT16_MAX; } else { pStator_Currents-》qI_Component2 = (int16_t) wAux; } /* Ia = -Ic -Ib */ wAux = (int32_t)( pHandle-》pParams_str-》ADCx2-》JDR1 ); wAux *= 2; wAux = (int32_t) pHandle-》wPhaseCOffset - wAux; //Ic wAux -= (int32_t) pStator_Currents-》qI_Component2; //-Ic-Ib wAux = -wAux-pStator_Currents-》qI_Component2 /* Saturation of Ia */ if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component1 = INT16_MAX; } else if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component1 = -INT16_MAX; } else { pStator_Currents-》qI_Component1 = (int16_t) wAux; } break; case SECTOR_2: case SECTOR_3: /* Current on Phase B is not accessible */ /* Ia = PhaseAOffset - ADC converted value) */ wAux = (int32_t)( ADC1-》JDR1 ); wAux *= 2; wAux = wAux - (int32_t)( pHandle-》wPhaseAOffset ) ; /* Saturation of Ia */ if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component1 = -INT16_MAX; } else if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component1 = INT16_MAX; } else { pStator_Currents-》qI_Component1 = (int16_t) wAux; } /* Ib = -Ic -Ia */ wAux = (int32_t)( pHandle-》pParams_str-》ADCx2-》JDR1 ); wAux *= 2; wAux = (int32_t) pHandle-》wPhaseCOffset - wAux; wAux -= (int32_t) pStator_Currents-》qI_Component1; /* Saturation of Ib */ if ( wAux 》 INT16_MAX ) { pStator_Currents-》qI_Component2 = INT16_MAX; } else if ( wAux 《 -INT16_MAX ) { pStator_Currents-》qI_Component2 = -INT16_MAX; } else { pStator_Currents-》qI_Component2 = (int16_t) wAux; } break; default: break; } pHandle-》_Super.hIa = pStator_Currents-》qI_Component1; pHandle-》_Super.hIb = pStator_Currents-》qI_Component2; pHandle-》_Super.hIc = -pStator_Currents-》qI_Component1 - pStator_Currents-》qI_Component2; } |
|
|
|
只有小组成员才能发言,加入小组>>
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-22 05:56 , Processed in 0.379028 second(s), Total 44, Slave 38 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号