Let's say that we will do speed control through the POT on the DVR8301.
The POT has been correctly programmed as followed:
( with the help of http://e2e.ti.com/support/microcontrollers/c2000/f/902/t/329620.aspx )
hal.c
=====
....
#ifdef USING_POTENTIOMETER
ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_8,ADC_SocChanNumber_B0);
ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_8,ADC_SocTrigSrc_EPWM1_ADCSOCA);
ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ADC_SocSampleDelay_9_cycles);
#endif
....
hal_obj.h
=========
{
.....
#ifdef USING_POTENTIOMETER
_iq potentiometer; //!< the potentiometer value
#endif
} HAL_AdcData_t;
hal.h
=====
static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
{
HAL_Obj *obj = (HAL_Obj *)handle;
....
#ifdef USING_POTENTIOMETER
// read the dcBus voltage value
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_8); // divide by 2^numAdcBits = 2^12
// bound pot value so all values near 0 are stored as 0, all near 4095 stored as 4095
value = (value > 4090) ? 4095 : ((value < 5) ? 0 : value);
// scale value into IQ24
pAdcData->potentiometer = value * 4096;
#endif
...
}
1. How to feed the ADC value to the parameter gMotorVars.SpeedRef_krpm?
I think we have to get the max speed (by calling CTRL_getMaximumSpeed_pu()) and scale it with the
potentiometer value then feed it to the CTRL:
// Using the potentiometer here to control the speed
gMotorVars.SpeedRef_krpm = _IQmpy(gAdcData.potentiometer,CTRL_getMaximumSpeed_pu(ctrlHandle));
// set the speed reference
CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
Is this the correct way to do it ?
2. when is the CTRL_setMaximumSpeed_pu(handle, value_to_set) get called ?
I could not find the code when this is called. Do we have do this at initialization time with parameters from
user.h? If yes, could you show me how the value_to_set would be calculated from the user.h?
I am thinking to incorporate this code to the lab03a to test out the POT.
Thanks.