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.

C2000WARE: Instaspin eQEP electrical Angle Calculation using enc.h

Part Number: C2000WARE

Hello,

I'm trying to teach Instaspin sensored FOC. I'm using an Encoder with 2048 Pulses/revolution connected to the EQEP Module 2 of the F280049.

As the motor rotates at 600 RPM (==10 RPS) i get an index pulse every 100ms which seems fine, the Pulses on the A and B inputs seem to be good as well. 

The Encoder GPIO config is:

    // GPIO14 Encoder2 Input A
    GPIO_setMasterCore(14, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_14_EQEP2_A);
    GPIO_setDirectionMode(14, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(14, GPIO_PIN_TYPE_STD);

    // GPIO15 Encoder2 Input B
    GPIO_setMasterCore(15, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_15_EQEP2_B);
    GPIO_setDirectionMode(15, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(15, GPIO_PIN_TYPE_STD);

    // GPIO29 EncoderB Index
    GPIO_setMasterCore(29, GPIO_CORE_CPU1);
    GPIO_setPinConfig(GPIO_29_EQEP2_INDEX);
    GPIO_setDirectionMode(29, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(29, GPIO_PIN_TYPE_STD);

The EQEP Clock is also enabled
--------------------------------------------------------
The EQEP module is configured as
  //
  // Configure the decoder for quadrature count mode
  //
  EQEP_setDecoderConfig(obj->qepHandle[qep], (EQEP_CONFIG_2X_RESOLUTION |
                                     EQEP_CONFIG_QUADRATURE |
                                     EQEP_CONFIG_SWAP));

  EQEP_setEmulationMode(obj->qepHandle[qep], EQEP_EMULATIONMODE_RUNFREE);

  //
  // Configure the position counter to reset on an index event
  //
  EQEP_setPositionCounterConfig(obj->qepHandle[qep], EQEP_POSITION_RESET_IDX,
                                0xFFFFFFFF);//0x00001FFF
                                
  //Index interrupt 
  Interrupt_register(INT_EQEP2,eqep_ind_latch);
  EQEP_enableInterrupt(EQEP2_BASE, EQEP_INT_INDEX_EVNT_LATCH);
  EQEP_clearInterruptStatus(EQEP2_BASE, EQEP_INT_INDEX_EVNT_LATCH);
  Interrupt_enable(INT_EQEP2);
The ISR is used to toggle an led which happens every 100 ms due to the 600 RPM.
Now I would like to use the enc.h and enc.c files provided with the tutorials. Therefore I configured the Encoder as:
  encHandle = ENC_init(&enc,sizeof(enc));
  ENC_setup(encHandle,1,USER_MOTOR_NUM_POLE_PAIRS,USER_MOTOR_ENCODER_LINES,0,USER_IQ_FULL_SCALE_FREQ_Hz,(USER_ISR_FREQ_Hz),USER_MOTOR_MAX_SPEED);//(USER_ISR_FREQ_Hz/USER_NUM_ISR_TICKS_PER_SPEED_TICK)
  EQEP_setPosition(EQEP2_BASE,0);
ENC_setup(encHandle,1,USER_MOTOR_NUM_POLE_PAIRS,USER_MOTOR_ENCODER_LINES,0,USER_IQ_FULL_SCALE_FREQ_Hz,(USER_ISR_FREQ_Hz),USER_MOTOR_MAX_SPEED);
(USER_MOTOR_NUM_POLE_PAIRS=3,USER_MOTOR_ENCODER_LINES=2048,USER_IQ_FULL_SCALE_FREQ_Hz=1000,USER_ISR_FREQ_Hz=24e3,20e3)
--
According to the user guide the remaining thing to do is to call ENC_run in the main ISR as:
 ENC_run(encHandle,
                EQEP_getPosition(EQEP2_BASE),
                HAL_getQepIndex(halHandle),
                HAL_getQepDirection(halHandle),
                1);
        ENC_calcElecAngle(encHandle,EQEP_getPosition(halHandle->qepHandle[1]));
       motor_speed_enc = ENC_getSpeedRPM(encHandle);
I tried that but the motor_speed_enc just returns -1, does anybody has an clue what I'm doing wrong?
Is the scaling factor for speed calculation 
ENC_SPEED_SCALING_FACTOR in enc.h right for an encoder with 2048 lines?
Thank you in advance.