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.

F28M35H52C: Reconfigure eQEP module during runtime

Part Number: F28M35H52C

Hi,

i am using the eQEP module with incremental encoders and it works well.
By now i am using a predefined struct with constant values to initialize the eQEP.

Struct:

typedef struct {int theta_elec;         // Output: Motor Electrical angle (Q15)
                int theta_mech;         // Output: Motor Mechanical Angle (Q15)
                int DirectionQep;       // Output: Motor rotation direction (Q0)
                int QEP_cnt_idx;        // Variable: Encoder counter index (Q0)
                int theta_raw;          // Variable: Raw angle from Timer 2 (Q0)
                int mech_scaler;        // Parameter: 0.9999/total count, total count = 4000 (Q26)
                int pole_pairs;         // Parameter: Number of pole pairs (Q0)
                int cal_angle;          // Parameter: Raw angular offset between encoder and phase a (Q0)
                int index_sync_flag;    // Output: Index sync status (Q0)

                Uint32 SpeedScaler;     // Parameter :  Scaler converting 1/N cycles to a GLOBAL_Q speed (Q0) - independently with global Q
                _iq Speed_pr;           // Output :  speed in per-unit
                Uint32 BaseRpm;         // Parameter : Scaler converting GLOBAL_Q speed to rpm (Q0) speed - independently with global Q
                int32 SpeedRpm_pr;      // Output : speed in r.p.m. (Q0) - independently with global Q

                _iq  oldpos;            // Input: Electrical angle (pu)
                _iq Speed_fr;           // Output :  speed in per-unit
                int32 SpeedRpm_fr;      // Output : Speed in rpm  (Q0) - independently with global Q
                void (*init)();         // Pointer to the init funcion
                void (*calc)();         // Pointer to the calc funtion
                }  POSSPEED;

Predefinition for a specific motor:

#define POSSPEED_Motor1 {0x0, 0x0,0x0,0x0,0x0,3355,4,0,0x0,\
		75,0,6000,0,\
       0,0,0,\
       (void (*)(long))POSSPEED_Init,\
       (void (*)(long))POSSPEED_Calc }

Use the define to create a qep object:

POSSPEED qep_posspeed = POSSPEED_Motor1;


And finally init the QEP in the init part of my main file on the c28:
qep_posspeed.init(&qep_posspeed);

This works quite well so far.

Now i want to be able to change the eQEP configuration during runtime in order to connect a different motor
without having to change the values in the code and without recompiling it. But when i start to replace the specific values
for motor 1 with variables i get the error message that the POSSPEED expression must have constant values:

e.g.

#define POSSPEED_genericMotor {0x0, 0x0,0x0,0x0,0x0,3355,polePairs,0,0x0,\
		75,0,6000,0,\
       0,0,0,\
       (void (*)(long))POSSPEED_Init,\
       (void (*)(long))POSSPEED_Calc }

So the question is, how can i reconfigure/reinitialize the eQEP module during run time ?

Thanks and best regards.

  • You can just access the members of the qep_posspeed to reassign them new values directly--like qep_posspeed.pole_pairs = 2. qep_posspeed itself is the variable. Does that work?

    Whitney
  • Thanks for the hint. It works.

    		if (newEncoderValuesFlag == 1) {
    			newEncoderValuesFlag = 0;
    			tmp_SpeedScaler = (4.0*(150e6/4.0)*60.0)/(4.0*incEncCountsPerRevolution*incEncNMax);
    			qep_posspeed.mech_scaler = (int)((0.9999/(4*incEncCountsPerRevolution)*67108864));
    			qep_posspeed.pole_pairs = (int)(polePairs);
    			qep_posspeed.SpeedScaler = (Uint32)(tmp_SpeedScaler);
    			qep_posspeed.BaseRpm = (Uint32)(incEncNMax);
    			qep_posspeed.init(&qep_posspeed);
    			}

    Now i just change the values of the members and do a reinit of the qep.
    What a simple solution. Don't know why i did not figure it out myself.
    Thanks a lot for the quick response.

    Problem solved.

    Best wishes.

    Michael