This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DVR8301 - lab03a with the POT using as speed dial



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.



 

  • 1.  you don't need to use the CTRL_getMaximum

    CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);

    will work fine, but you need to use your pot value which should be in IQ24(-1.0) to IQ24(1.0) range to set the % of speed. 

    you can either base this Speed off of the maximum speed as defined by the IQ_FULL_SCALE_FREQUENCY, or you can just set a maximum value that's not specifically tied to the maximum frequency (which is usually a bit higher than your maximum speed). For example you may want to hard code that through the POT you only allow +/- 5000 RPM. 

    2. The function is called in ctrl.c, however this isn't anything that you need to manually set, the library takes care of this for you. You'll see that the variable maxSpeed_pu isn't even a variable you have access to.

     


  • Because of our application, we run the motor with one direction only, therefore:

     pAdcData->potentiometer = _IQmpy(value * 4096, _IQ(20)); //  IQ24(0.0) to IQ24(1.0) range to set the % of speed

    ....
      gMotorVars.SpeedRef_krpm = _IQmpy( gAdcData.potentiometer, CTRL_getMaximumSpeed_pu(ctrlHandle) );

     

    Thank you !