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" ?
QEI module
-
- Site Admin - Expert
- Posts: 616
- Joined: Wed Mar 07, 2007 11:23 pm
- Location: Bayonne- France
- Contact:
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.
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.
Re: QEI module
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
Hope you find this helpful.
Mariano
-
- Posts: 17
- Joined: Mon Dec 01, 2008 9:01 pm
Re: QEI module
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
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 1234 times
-
- QEI_Functions.c
- (1.41 KiB) Downloaded 1311 times
Re: QEI module
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
}
Who is online
Users browsing this forum: No registered users and 37 guests