TI INSTASPIN 下桥臂电阻采样改为U V W电流传感器采样,软件上要改什么地方啊?或者怎样换算符合算法要求?
Eric Ma:
首先你要计算一下换算比例,然后修改user.h中的USER_ADC_FULL_SCALE_CURRENT_A
其次: 修改hal.h中的readAdcData函数,如下标黄色三个值的正负符号,注意,算法里面以流进去电机电流的方向为正,如果你用霍尔采样,再经过运放,最终确定一下这个电流方向,如果反相了,则在value前面加符号。
static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData){ HAL_Obj *obj = (HAL_Obj *)handle;
_iq value; _iq current_sf = HAL_getCurrentScaleFactor(handle); _iq voltage_sf = HAL_getVoltageScaleFactor(handle);
// convert current A // sample the first sample twice due to errata sprz342f, ignore the first sample value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1); value = _IQ12mpy(value,current_sf) – obj->adcBias.I.value[0]; // divide by 2^numAdcBits = 2^12 pAdcData->I.value[0] = value;
// convert current B value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2); value = _IQ12mpy(value,current_sf) – obj->adcBias.I.value[1]; // divide by 2^numAdcBits = 2^12 pAdcData->I.value[1] = value;
// convert current C value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3); value = _IQ12mpy(value,current_sf) – obj->adcBias.I.value[2]; // divide by 2^numAdcBits = 2^12 pAdcData->I.value[2] = value;
另外一个函数,updateAdcBias, 如果是正相采样,则bias +=, 否则 -=。
static inline void HAL_updateAdcBias(HAL_Handle handle){ uint_least8_t cnt; HAL_Obj *obj = (HAL_Obj *)handle; _iq bias;
// update the current bias for(cnt=0;cnt<HAL_getNumCurrentSensors(handle);cnt++) { bias = HAL_getBias(handle,HAL_SensorType_Current,cnt); bias += OFFSET_getOffset(obj->offsetHandle_I[cnt]);
HAL_setBias(handle,HAL_SensorType_Current,cnt,bias); }
ERIC
TI INSTASPIN 下桥臂电阻采样改为U V W电流传感器采样,软件上要改什么地方啊?或者怎样换算符合算法要求?
desheng yang:
回复 Eric Ma:
Hi,Eric
TIDA-00913中提到中断中将PWM取反具体怎么理解?
interrupt void mainISR(void)
{HAL_PwmData_t negPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
// toggle status LEDif(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)){HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);gLEDcnt = 0;}
// acknowledge the ADC interruptHAL_acqAdcInt(halHandle,ADC_IntNumber_1);
// convert the ADC dataHAL_readAdcData(halHandle,&gAdcData);
// run the controllerCTRL_run(ctrlHandle,halHandle,&gAdcData,&negPwmData);
//每次中断negPwmData初始化为零,那么写入控制运行已经不能运行了吧?
// negate PwmData generated by SVGEN module in ROMgPwmData.Tabc.value[0] = _IQmpy(negPwmData.Tabc.value[0], _IQ(-1.0));gPwmData.Tabc.value[1] = _IQmpy(negPwmData.Tabc.value[1], _IQ(-1.0));gPwmData.Tabc.value[2] = _IQmpy(negPwmData.Tabc.value[2], _IQ(-1.0));
// write the PWM compare valuesHAL_writePwmData(halHandle,&gPwmData);
// setup the controllerCTRL_setup(ctrlHandle);
return;
} // end of mainISR() function
TI中文支持网



