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.

LaunchXL, BoostXL and potentiometer

Hello,


I am trying to connect a potentiometer to the LaunchXL board with the code of the Lab4, to make a current controller controlled by a knob.

To do that I have thought of this steps:

  1. Connect a potentiometer between the 3.3V and ADCINA6, SOC8
  2. Add a new voltage sensor to pUserParams->numCurrentSensors
  3. In drvsetupadcs add:
    • DC_setSocChanNumber(obj->adcHandle, ADC_SocNumber_8,ADC_SocChanNumber_A6);
    • ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_8,ADC_SocTrigSrc_EPWM1_ADCSOCA);
    • ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ADC_SocSampleDelay_7_cycles);
  4. In typedef struct _DRV_AdcData_t_ add:
    1. _iq potentiometer;
  5. In the DRV_readAdcData add:
    • value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_8);
    • value = _IQ12mpy(value,HARDCODED_SFACTOR) - HARDCODED_BIAS;
    • pAdcData->potentiometer = value;

I would like to know if the steps I have taken to setup the adc and potentiometer are correct.

I would also like to know where is the Iq current updated so I can copy the value of pAdcData->potentiometer to the new Iq reference. That is the last step which I have not figured out.

Thank you in advance

Paulo Neves

  • I've got some code for this. Will reply back soon. 

  •  this is the code to add to your HAL_readAdcData() function.  You will of course have to set-up your ADC conversion as well. In this case we are adding the additional two samples to our main ADC conversion. So after the first 7 channels are used for currents and voltages of the inverter we convert (in the same interrupt) the values of the pots, and post them in ResultNumber 8 and 9.  Since you don't really need the pot values at the same rate as the current loop you could set this up ander a different ADC set-up and Read function....but this is quicker if you want to get something working.

     

      // read pot1
      value_temp = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_8);

      // bound pot value so all values near 0 are stored as 0, all near 4095 stored as 4095
      if(value_temp < 5) {
       value_temp = 0;
      }
      if(value_temp > 4090) {
       value_temp = 4095;
      }
     
      // scale value into IQ24
      pAdcData->pot1 = value_temp * 4096;

      // read pot2
      value_temp = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_9);    
     
      // bound pot value so all values near 0 are stored as 0, all near 4095 stored as 4095
      if(value_temp < 5) {
       value_temp = 0;
      }
      if(value_temp > 4090) {
       value_temp = 4095;
      }

      // scale value into IQ24
      pAdcData->pot2 = value_temp * 4096;

      return;
    } // end of HAL_readAdcData() function

     

  • "I would also like to know where is the Iq current updated so I can copy the value of pAdcData->potentiometer to the new Iq reference. That is the last step which I have not figured out."

    If you are using proj_lab04 or 05 you should review

    updateIqRef() function.

    And actually, what I posted above gives you pot1 or pot2 values that are bound from IQ24(0.0) to IQ24(1.0).  If you want to support a bound of IQ24(-1.0) to IQ24(1.0) you should update the calculations to

    pAdcData->pot1 = (value_temp - 2048) * 8192;  //Offset to support negative bounding; multiply by 2^13 to get IQ24.

    you don't really need to use this calculation since you have a per unit value already from your pot

      _iq iq_ref = _IQmpy(gMotorVars.IqRef_A,_IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A));

    so you could simple set iq_ref = the pAdcData pot value

    but do use the rest of the function as setting a speed with the same direction as your torque command is critical.

     

  • Wow that is exactly what I was looking for. I will study and implement the steps and will report back. Great support thanks.

  • Everything worked good. I just had to adjust the offset of the minimum value of the pot, so the motor is stopped when the potentiometer is on full resistance.


    Thank you a lot

  • I want to add on this,
    there are two parameters- iq_ref and gMotorVars.IqRef_A.
    i am putting the potentiometer read data to iq_ref in updateIqRef() function then motor run fast also consuming the current increasingly with increase in rpm as potentiometer value increases.
    Now i want to freeze the current at particular value so that if i further rotate the potentiometer, the rpm and current should not be increased (current limiting). So for that purpose does gMotorVars.IqRef_A is required?
    i did some test by putting
    if(gPotentiometer >= _IQ(0.2)){
    gMotorVars.IqRef_A = _IQ(1.0);
    }
    in for(;;) loop. But rpm and current continue to increase with potentiometer.
    Am i doing something wrong?

    Thanks.
  • Hello,

    Please consider creating a new post if the discussion on this thread doesn't answer your question. Old posts are generally closed and no longer tracked. You can provide the necessary information regarding your issue in the new post and include a link to this post if you'd like.

    Elizabeth