QEI module

lakmal
Posts: 1
Joined: Fri Sep 14, 2007 9:23 am

QEI module

Postby lakmal » Mon Sep 17, 2007 3:15 am

Do you have any plans of developing a SIMULINK block for the QEI interface?

Is it possible to develop my own dsPIC (or any other PIC) Simulink block using the Simulink's "S function builder" ?

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Postby LubinKerhuel » Tue Sep 18, 2007 9:30 pm

Hello,

QEI is not planned in a near future. My priority is:
- Make the toolbox compatible with all matlab version
(Chinese, Japanese etc…)
- Make the I2C blockset
- Make the CAN blockset
Then I will look at others peripheral like QEI.

I do not know how to build a block for dsPIC using the Simulink's "S function builder". I do not know if this is possible.
However, you could use the ‘Custom C function’ of the dsPIC toolbox to build easily your own Simulink block generating C code for dsPIC. Do you need an example on how using this block ?
Note that this block is not available in the evaluation version of the toolbox.

For information, I am planning to release version of the toolbox supporting only one microcontroller. This version will be cheaper, allowing hobbyists and students to get a complete version for the microcontroller they are using.

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Re: QEI module

Postby malife » Fri Mar 21, 2008 12:37 am

If you are looking on how to implement the QEI module and have a registered version (that includes the C function call) take a look at this example of how to implement the QEI with the C Function Call block

Hope you find this helpful.

Mariano

Simon_says
Posts: 17
Joined: Mon Dec 01, 2008 9:01 pm
Contact:

Re: QEI module

Postby Simon_says » Sat Jan 10, 2009 10:53 pm

Hello Lubin...
I need some help with this model. I tried to read the QEI module using Mariano example and it worked fine. Thanks a lot Mariano! However, I tried to use your sample model with a slight modification in order to read the counts of the QEI unsuccesfully. Coul you advise me if I am doing something wrong? Here is the model and the C code (same as yours) . I am still learning the dsPIC and the way to use the C function block. I am having a lot of questions that I´ll ask soon... But so far so good. Thanks a lot!

Jose Luis
Attachments
QEI1.mdl
(29.6 KiB) Downloaded 300 times
QEI_Functions.c
(1.41 KiB) Downloaded 402 times

Bobes
Posts: 36
Joined: Wed Nov 25, 2009 11:27 am
Location: Brno, CZE
Contact:

Re: QEI module

Postby Bobes » Wed Nov 17, 2010 11:13 pm

Well, I should have posted this sooner, but this is the code modification for 2 encoders, on dsPIC33fj128mc804

Code: Select all

#include <p33FJ128MC804.h>

void QEIInit(void){

 
 //QEI configuration register
  POS1CNT = 0;               // Set Current Position
  MAX1CNT = 0;              // Use QEI in 2x mode
 
  POS2CNT = 0;               // Set Current Position
  MAX2CNT = 0;              // Use QEI in 2x mode

  DFLT1CON = 0b0000000100000000;        // Digital filter set to off, Count Error Interrupt Disable
  DFLT2CON = 0b0000000100000000;        // Digital filter set to off, Count Error Interrupt Disable

  QEI1CONbits.QEIM = 7;           // x4 reset by MAXCNT pulse
  QEI1CONbits.POSRES = 0;         // doesn't Allow Index pulse to reset counter
  QEI1CONbits.SWPAB = 1;          // direction
 
  QEI2CONbits.QEIM = 7;           // x4 reset by MAXCNT pulse
  QEI2CONbits.POSRES = 0;         // doesn't Allow Index pulse to reset counter
  QEI2CONbits.SWPAB = 1;          // direction
 
  //ConfigIntQEI
    IEC3bits.QEI1IE = 1;                // Enable QEI interrupt
    IPC14bits.QEI1IP = 2;               // Interrupt priority level 2
   
    IEC4bits.QEI2IE = 1;                // Enable QEI interrupt
    IPC18bits.QEI2IP = 2;               // Interrupt priority level 2
   // extern volatile int ct_turns;
   // ct_turns = 0x8000;
   
}



/*------------------------------------------------------------------*/
void __attribute__((__interrupt__)) _QEI1Interrupt(void)
{
   extern volatile int ct_turnsE1;
   // if it overflowed
     if (QEI1CONbits.UPDN ==  1){
       ct_turnsE1++;
     } else {
       ct_turnsE1--;
     }
     IFS3bits.QEI1IF = 0;    // clear the interrupt flag
}

void __attribute__((__interrupt__)) _QEI2Interrupt(void)
{
   extern volatile int ct_turnsE2;
   // if it overflowed
     if (QEI2CONbits.UPDN ==  1){
       ct_turnsE2++;
     } else {
       ct_turnsE2--;
     }
     IFS4bits.QEI2IF = 0;    // clear the interrupt flag
}



Return to “Request for new functions / Peripheral / Chip support”

Who is online

Users browsing this forum: No registered users and 1 guest