SPRUHJ1I January 2013 – October 2021 TMS320F2802-Q1 , TMS320F28026-Q1 , TMS320F28026F , TMS320F28027-Q1 , TMS320F28027F , TMS320F28027F-Q1 , TMS320F28052-Q1 , TMS320F28052F , TMS320F28052F-Q1 , TMS320F28052M , TMS320F28052M-Q1 , TMS320F28054-Q1 , TMS320F28054F , TMS320F28054F-Q1 , TMS320F28054M , TMS320F28054M-Q1 , TMS320F2806-Q1 , TMS320F28062-Q1 , TMS320F28062F , TMS320F28062F-Q1 , TMS320F28068F , TMS320F28068M , TMS320F28069-Q1 , TMS320F28069F , TMS320F28069F-Q1 , TMS320F28069M , TMS320F28069M-Q1
This can be done in the main loop. This code example includes the code required to interface with the fill and drain valves and sensors. It will also update the water level as part of the washing machine simulation.
if(gMotorVars.VelPlanRun == TRUE) {
STVELPLAN_setEnable(stVelPlanHandle, TRUE);
}
// Run SpinTAC Velocity Plan
STVELPLAN_run(stVelPlanHandle);
// Update sensor values for SpinTAC Plan
// Get values for washer valve components
STVELPLAN _getVar(stVelPlanHandle, 3, &gVelPanVar[3]); // Get value of FillVale
STVELPLAN _getVar(stVelPlanHandle, 3, &gVelPanVar[4]); // Get value of DrainValve
if(gVelPanVar[3] == TRUE) {
// if FillValve is open, increase water level
gWaterLevel += 1;
}
else if(gVelPanVar[4] == TRUE) {
// if DrainValve is open, decrease water level
gWaterLevel -= 1;
}
if(gWaterLevel >= WASHER_MAX_WATER_LEVEL) {
// if water level is greater than maximum, set fill sensor to true
gWaterLevel = WASHER_MAX_WATER_LEVEL;
gVelPanVar[0] = TRUE;
}
else {
// if water level is less than maximum, set FillSensor to false
gVelPanVar[0] = FALSE;
}
if(gWaterLevel <= WASHER_MIN_WATER_LEVEL) {
// if water level is at the minimum & set DrainSensor to true
gWaterLevel = WASHER_MIN_WATER_LEVEL;
gVelPanVar[1] = TRUE;
}
else {
// if water level is greater than minimum, set DrainSensor to false
gVelPanVar[1] = FALSE;
}
// Set values for washer sensor components
STVELPLAN _getVar(stVelPlanHandle, 0, gVelPanVar[0]); // Set value for FillSensor
STVELPLAN _getVar(stVelPlanHandle, 1, gVelPanVar[1]); // Set value for DrainSensor
if(STVELPLAN_getStatus(stVelPlanHandle) != ST_PLAN_IDLE) {
// Send the profile configuration to SpinTAC Move
gMotorVars.SpeedRef_krpm = _IQmpy(STVELPLAN_getVelocitySetpoint(stVelPlanHandle),
_IQ24(ST_SPEED_KRPM_PER_PU));
gMotorVars.MaxAccel_krpmps = _IQmpy(STVELPLAN_getAccelerationLimit(stVelPlanHandle),
_IQ24(ST_SPEED_KRPM_PER_PU));
gMotorVars.MaxJrk_krpmps2 = _IQ20mpy(STVELPLAN_getJerkLimit(stVelPlanHandle),
_IQ20(ST_SPEED_KRPM_PER_PU));
}
else {
STVELPLAN_setEnable(stVelPlanHandle, FALSE);
}