//-----------------------------------------------------------------------------
/// \brief Set measurement output channel
///
/// \descr Set the parameters of an output channel, but do not activate the automatic output
///
/// Arguments
/// - UINT8 ucOutChn: CAN output channel [0...9]
/// - UINT8 ucType: Type of measurement value, see CMDIF_Meas... in CmdIfType.h
/// - UINT8 ucMeasChn: measurement channel [0...3]
/// - UINT8 ucMin: minimum change for new signal output
/// (if no signal change is recognized, at least every 40ms
/// a CAN message will be sent)
///
/// Return
/// - UINT8 ucResult: CMDIF_Error (in case of incorrect argument,
/// ucOutChn, ucType, ucMeasChn)
/// CMDIF_ResultOk (else)
//-----------------------------------------------------------------------------
void CmdIf_SetMeasOutChn(void)
{
UINT8 ucOutChn = CmdIf_ArgBuffer.SetMeasOutChn.ucOutChn;
UINT8 ucMeasChn = CmdIf_ArgBuffer.SetMeasOutChn.ucMeasChn;
// get divider for averaging
INT32 lDiv = (INT32) Nvm_RamCopy.AltuMeasOut.ulClockDivider + 1; // ulClockDivider = divider - 1
// calculate factor for averaging and round result
INT32 lMult = (2 * ALTU_AvrgNorm + lDiv) / (2 * lDiv);
CmdIf_RetBuffer.ucResult = CMDIF_ResultOk; // initialize to default value
// avoid illegel pointer if meas. channel/output channel out of range
if((ucOutChn < ALTU_OutChannels) && (ucMeasChn < ALTU_MeasChannels))
{
switch(CmdIf_ArgBuffer.SetMeasOutChn.ucType)
{
case CMDIF_MeasVoltageAvrg: // average value of voltage on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lVoltage[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging
break;
case CMDIF_MeasVoltageSmpl: // 1 sample of voltage on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lVoltage[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasCurrAmpAvrg: // average value of current amplified on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lCurrAmp[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging
break;
case CMDIF_MeasCurrAmpSmpl: // 1 sample of current amplified on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lCurrAmp[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasCurrNrmAvrg: // average value of current not amplified on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lCurrNrm[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging
break;
case CMDIF_MeasCurrNrmSmpl: // 1 sample of current not amplified on measurement lines
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lCurrNrm[ucMeasChn];
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasVoltExtAvrg: // average value of voltage on extension port
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrAvrg()->lVoltExt;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = lMult; // use scaling factor for averaging
break;
case CMDIF_MeasVoltExtSmpl: // 1 sample of voltage on extension port
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & HalAdc_GetPtrSmpl()->lVoltExt;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpPosRel: // simulated relative stepper position
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lActPosRel;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpPosAbs: // simulated absolute stepper position
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lActPosAbs;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpPsens: // stepper position sensor (simulated or input signal)
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & Nvm_RamCopy.AltuStpPos.lPsensState;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpCurrent: // stepper coil cuurnt (vector addition)
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lCurrent;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpSpeed: // stepper speed
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lSpeed;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
case CMDIF_MeasStpAcceleration: // stepper acceleration
Nvm_RamCopy.AltuMeasOut.aplAddr [ucOutChn] = & StpSim_lAcceleration;
Nvm_RamCopy.AltuMeasOut.alAvrgMult[ucOutChn] = ALTU_AvrgNorm; // scaling factor 1
break;
default:
CmdIf_RetBuffer.SetMeasOutChn.ucResult = CMDIF_Error;
break;
}
Nvm_RamCopy.AltuMeasOut.aunMinChange[ucOutChn] = CmdIf_ArgBuffer.SetMeasOutChn.ucMin;
}
else
{
CmdIf_RetBuffer.SetMeasOutChn.ucResult = CMDIF_Error; // illegal output channel
}
}
//-----------------------------------------------------------------------------
/// \brief Enable/disable measurement output
///
/// \descr selective enable/disable of mesurement output by channel number
///
/// Arguments
/// - UINT16 unEnMask: Enable mask - bit0 = Chn0, bit1 = Chn1, ...
///
/// Return
/// - UINT8 ucResult: CMDIF_ResultOk
//-----------------------------------------------------------------------------
void CmdIf_SetMeasOutEnable(void)
{
UINT16 unMask, unIx;
unMask = 1; // begin with bit position 0
for(unIx=0; unIx