I have been experimenting with exactly this for a couple of days. I will show you what I have in hope that it helps.
In the KMS_API document the user block is defined.
The user.states definitions are in the user.h file
Before you change a user state there are parameters you can modify.
To set the user state to run speed you would write:
user.state= USER_RUN_SPEED;
if you want to idle the motor you would write:
user.state= USER_IDLE;
You then need to drive a target speed by setting user.command.targetSpeed.
The KMS code uses QMath in the calculations and the conversion of a float to a LQ type is easy to do but not obvious. Check out Chapter 24 Math for the details on the QMath library.
If you use the feedback_3ph.c as an example piece of code the raw ADC reading is converted to a _sq with the use of the function (_sq): tempSQ = (_sq)(adcResults->phaseBCurrent - v->calib.offsetIb);
Likewise the conversion of the RAW ADC result to LQ is accomplished using the (_lq) function.
In the following code an ADC input is used to control the speed. Before you would call the code below something like this
adc0Results[0] = (_lq) adc0RawResults[0];
conversion to type _lq would have to be done and would be dependent on the conversion you want to make.
/* code start */
// declare these as global variables in main.c
_lq adcSpeed = 0;
_lq adcSpeedAccum = 0;
_lq adcSpeedAvg = 0;
uint16_t speedUpdateCounter = 0;
// this code takes the ADC reading, downshifts it by 4 to remove noise and uses that as a percentage of the maximum applicaton speed (in this case 20krpm)
adcSpeed = _LQmpyLQX((adc0Results[0] >> 4), 8, _LQ(20000.0/FULL_SCALE_SPEED_RPM), 24);
adcSpeed = _LQsat(adcSpeed, _LQ(1.0), _LQ(0.0));
// this code averages the adc reading over 125 samples before setting it to user.command.targetSpeed
// it will also handle setting the control mode if the commanded speed is larger than 0
if(adcSpeed > _LQ(0.0))
{
user.state= USER_RUN_SPEED;
if(speedUpdateCounter >= 125)
{
speedUpdateCounter = 0;
adcSpeedAvg = (adcSpeedAccum / 125) & 0x00FF0000;
user.command.targetSpeed = adcSpeedAvg;
adcSpeedAccum = 0;
}
else
{
adcSpeedAccum = adcSpeed + adcSpeedAccum;
speedUpdateCounter++;
}
}
else
{
user.state= USER_IDLE;
adcSpeedAccum = 0;
adcSpeedAvg = 0;
speedUpdateCounter = 0;
}
When we have a good example of this we will post a document about it.
Happy motoring,
Philip