9 years, 1 month ago.

mbed crashes with QEI and MODSERIAL (multiple interrupts)

I am currently using mbed with 3 QEI to monitor 3 separate encoders to read angle value of 3 motors. At the same time I am using MODSERIAL to communicate with a PC through a RS485 channel (at 1 mega baud). This channel is used to send command from PC to rotate the motor in different direction and also request for angle reading and state of the motors at a constant rate. They all work fine by itself when testing.

However, I am experiencing crashes from time to time when all three motors are moving at the same time (so all QEI and MODSERIAL are in place). It is interesting to note that when moving one motor at a time, there are no crashes. Also changing QEI mode from X4 to X2 encoding also reduces the chance of crashes. Currently I even modified the encoding to read only on rising edge of Channel A so it's like X1 encoding which has not seen to be causing crash so far, except when I start feeding back angle readings to PC through MODSERIAL.

So my question is whether having all these external interrupts functionality (12+ interrupts in total) all in place at once on mbed will cause any issue at all (because they work fine individually)? Has anybody had experience using a large number of interrupt services on mbed and what is the best way to handle this situation? I tried to disable/re-enable interrupt at various places so each interrupt execution is not interrupted by others and variable updates is protected so the operation can be atomic (and also variables are declared with volatile keyword as well).

One thing to note here is that all QEI and MODSERIAL are global objects (QEI is initialized probably in an initialization function in my code.)

QEI and MODSERIAL Initialization

MODSERIAL RS485(CPU_TXD1, CPU_RXD1, 2048);

QEI* Encoder1 = (QEI*) 0;
QEI* Encoder2 = (QEI*) 0;
QEI* Encoder3 = (QEI*) 0;
DigitalIn pin_encoder_1A(p11);
DigitalIn pin_encoder_1B(p12);
DigitalIn pin_encoder_2A(p29);
DigitalIn pin_encoder_2B(p28);
DigitalIn pin_encoder_3A(p16);
DigitalIn pin_encoder_3B(p17);

void init_QEI() {
	Encoder1 = new QEI(p12, p11, NC, QEI::X2_ENCODING);
	Encoder2 = new QEI(p28, p29, NC, QEI::X2_ENCODING);
	Encoder3 = new QEI(p17, p16, NC, QEI::X2_ENCODING);
        pin_encoder_1A.mode(PullDown);
	pin_encoder_1B.mode(PullDown);
	pin_encoder_2A.mode(PullDown);
	pin_encoder_2B.mode(PullDown);
	pin_encoder_3A.mode(PullDown);
	pin_encoder_3B.mode(PullDown);
}

Also the communication is happening at very high speed. Will this cause something like interrupt overrun? Because my weak knowledge about interrupt can someone give a clue how these interrupts should be handled together. If mbed is not able to keep up all the interrupt request, what will happen?

Have you solved your issue? Experiencing similar problem.

posted by Joshua Kukulsky 16 Mar 2017
Be the first to answer this question.