18F4431 INTERRUPTS

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Almost. One thing you need to remember is that when reading a value from two separate registers you need to make sure the process is not disturbed by an interrupt. In any piece of code, which is not an interrupt service routine, you need to disable interrupts before you read the two register and you need to enable interrupts when you finish reading the pair of registers.

Maybe it would be helpful if you can describe the setup of the QEI module, and what should happen when the module generates an interrupt.
Hi P,
Here is the set-up:
I think I understand the need for sequencial OFF/ON of each interrupt.
C.
'************************ ADDED QEI **********************************
qeicon = %00011011 'QEI enabled in 4x Update mode; position TIME is reset on period match (POSCNT = MAXCNT)MOVED TEST&
''QEICON VELM=0 Velocity mode enabled, QERR=0 No over/underflo, UP/DOWN=0 REVERSE, QEIM=110 QEI EN POSCNT=MAXCNT), PDEC=11 1:64
ipr3.ic2qeip = 0 '& 1 'high pri intr QEI Interrupt priority bit
pie3.ic2qeie = 0 '& 1 'qei intr enb QEI Interrupt flag enable bit
pir3.ic2qeif = 0 'Has reached the MAXCNT value, INT QEI MODULE Interrupt flag bit
pir3.ic3drif = 0 'clr in s/w REG file motion feedback filter
PIE1.RCIE = 0 '0= Disables the EUSART receive interrupt

cap2bufl = 0x00
cap2bufh = 0x00
cap3bufl = 0x9f 'CAP3BUFL = 0x67
cap3bufh = 0x05 'CAP3BUFH = 0x01
'*************************************************************************
LOOP
s2m(0) = cap2bufl 'QEI
s2m(1) = cap2bufh 'QEI
Etc Etc.
GOTO LOOP
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
Just spotted a difference between the old TRACKER CODE and now!
Tracker uses POSCNT and now uses CA2BUFL.
There is no INDX.
I've changed the CODE to POSCNT.
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
I think I understand QEI better!
Is this correct:
Once set-up, the 2x QEI inputs are counted in CAP2BUFL-H contantly which turn the interrupt flag on, and pass the 2x bytes to POSCNTL-H.
In order to read the 2x POSCNT bytes, the interrupt must be switched off so that POSCNT doesn't get updated, until it has been read, then switched on again?
C.
 

ericgibbs

Joined Jan 29, 2010
21,448
hi C,
Post the line/s of your Code that control which interrupts are set on the QEI.
Also, the ISR Code for those interrupts.

Not the full program.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
hi C,
Post the line/s of your Code that control which interrupts are set on the QEI.
Also, the ISR Code for those interrupts.

Not the full program.

E
Hi E,
I'm trying to unravel my spaghetti brain at the moment, and looked again at the QEI section of the D/S including 17:10, where POSCNT is shown also IC2QEIF and IC3DRIF.

I think I mentioned that there is an ISR, but I was mixed up, and I recall a thread about it earlier.

Anyway, tomorrow is the day I go to my clever mate's house, so I'll have all of my notes and questions, and hopefully, I can post a working ISR afterwards.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
hi,
What is the problem posting the Code clips I asked for, you wanted a reply.?
E
Hi E,
Do you mean the ones I posted in #21?

Re: the ISR, there isn't one for the QEI only what's in #21.

Note: in the LOOP I now use POSCNT, as used in the tracker CODE.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
We've reviewed again the D/S, and come up with the same answer, which is for this purpose the 3x INTERRUPT flags are not needed, so there is no need for an ISR.

As this project only need the angle of the incremental encoder, it only needs to read POSCNT L and H.

As It's possible that as the INTERRUPTS aren't needed then maybe they don't need to be switched on at all, I can check this and report back.
c.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
As mentioned above, I don't think this program need the QEI INTERRUPTS, as they are used for other purposes.
This thread was to understand INTERRUPTs, so I searched for other reasons for the intermittent error.

It appears that if these 2x lines are in the MAIN INCLUDE:
[ ANSEL0 = %00000000
ANSEL1 = %00000000 ]
instead of in the program, then the error occures. I've now moved them back into the program and it's working again.
Until it breaks again, I'll move on.
Thanks to all for the sometimes detailed help.

Next add 'E's SPI MSG1 LOOP routine (1.3.21) into the program.
Cheers, C.
 

ericgibbs

Joined Jan 29, 2010
21,448
hi,
The QEI interrupts are when the Counter value passes through Zero or the Counter value matches your preloaded count value.
As you have discovered, they are not really needed for your project.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
hi,
The QEI interrupts are when the Counter value passes through Zero or the Counter value matches your preloaded count value.
As you have discovered, they are not really needed for your project.
E
Hi E,
Yes, I think one of them is for speed control, and one is for number of rotations, and perhapve indexing, I've forgotten the 3rd.
C.
 
Top