Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Has anyone had problems with QEI affecting the rest of the CODE?

camerart

Active Member
Hi,
I am using an 18F4431 with a QEI and an incremental encoder.
On it's own it works perfectly, and I use it for degrees so 0 to 359 then over to 0 again.

I've now added a second section for reading a GPS module, which also works ok, but when the QEI goes over 359, then it stalls the program.
Any ideas please?
Cheers, Camerart
 
Last edited:

camerart

Active Member
No it's a statement - previously you had interrupts enabled, sending your code off to 'who knows where' - you've now disabled them.
Hi N,
I've been using this QEI for years and thought I understood it, but eveidently I don't!
I work through it with a mate at the weekends, and we both guess it works without any INTERRUPTs, which it does, but perhaps that's just lucky?

I looked back into programs where I first used it. (an aerial aiming tracker) and saw this in the INTERRUPT section:
--------------------------------------------------
On High Interrupt
Save System
PIR3.IC2QEIF = 0 'poscnt=maxcnt
PORTA.4 = 0 'QEA PIN
PORTA.4 = 1 'QEB PIN
PIE3.IC2QEIE = 1 'qei intr enb
-------------------------------------------------------------------
Is this what you're thinking of?

NOTE: When used earler, QEI ran on it's own, and appeared to use HIGH INTERRUPT
This time there is a GPS input INTERRUPT, and it is also set to HIGH INTERRUPT, and with the QEI set as DISABLED, both work ok.
EDIT: Is there any possibility, that OSHONSOFT is setting INTERRUPTs in the background?
C
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
Hi N,
I've been using this QEI for years and thought I understood it, but eveidently I don't!
I work through it with a mate at the weekends, and we both guess it works without any INTERRUPTs, which it does, but perhaps that's just lucky?

I looked back into programs where I first used it. (an aerial aiming tracker) and saw this in the INTERRUPT section:
--------------------------------------------------
On High Interrupt
Save System
PIR3.IC2QEIF = 0 'poscnt=maxcnt
PORTA.4 = 0 'QEA PIN
PORTA.4 = 1 'QEB PIN
PIE3.IC2QEIE = 1 'qei intr enb
-------------------------------------------------------------------
Is this what you're thinking of?

NOTE: When used earler, QEI ran on it's own, and appeared to use HIGH INTERRUPT
This time there is a GPS input INTERRUPT, and it is also set to HIGH INTERRUPT, and with the QEI set as DISABLED, both work ok.
EDIT: Is there any possibility, that OSHONSOFT is setting INTERRUPTs in the background?
C
Yes "PIE3.IC2QEIE = 1"

You MUST NOT enable interrupts unless you have an ISR - where do you think they are jumping to?, check the Oshosoft helpfile.

However, the section you've just posted looks to be part of an ISR (On High Interrupt), which you didn't have in the code you posted here.
 

camerart

Active Member
Yes "PIE3.IC2QEIE = 1"

You MUST NOT enable interrupts unless you have an ISR - where do you think they are jumping to?, check the Oshosoft helpfile.

However, the section you've just posted looks to be part of an ISR (On High Interrupt), which you didn't have in the code you posted here.
Hi N,
Where I said " I looked back into my programs" the 'high interrupt' section was from 2019.

"Where are they jumping to"? I've no idea! Most of this is a mystery to me, although I have looked closer in the past, but that's faded away.

So even though it's working fine along with the 'GPS interrupt', do you still think I have to add the QEI one? (It always broke, when they both ran together)
C
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Hi N,
Where I said " I looked back into my programs" the 'high interrupt' section was from 2019.

"Where are they jumping to"? I've no idea! Most of this is a mystery to me, although I have looked closer in the past, but that's faded away.

So even though it's working fine along with the 'GPS interrupt', do you still think I have to add the QEI one? (It always broke, when they both ran together)
C
The same still applies - WHERE ARE THEY JUMPING TO - if you enable interrupts you must have code for them to jump to, such as in post #23. As you've never posted any GPS code, we've no idea what you're doing.

It's no good posting just bits of code, or code from old projects, you need the to post the entire code from what you're trying to do. Although, as I mentioned before, no one here much uses OshonSoft anyway.
 

camerart

Active Member
The same still applies - WHERE ARE THEY JUMPING TO - if you enable interrupts you must have code for them to jump to, such as in post #23. As you've never posted any GPS code, we've no idea what you're doing.

It's no good posting just bits of code, or code from old projects, you need the to post the entire code from what you're trying to do. Although, as I mentioned before, no one here much uses OshonSoft anyway.
Hi N,
Some people don't like full CODE, and I was told to just post snippets.
Here is the full todays CODE:
NOTE: It's still being worked on!
C
 

Attachments

  • 18F4431 32MHz XTL BASE_SLAVE RX_QEI 271122.bas
    19.8 KB · Views: 29

camerart

Active Member
Except it didn't, because you enabled QEI interrupts without any code for them.
Hi N,
This I don't understand?
As it is at #27 (on PIC 2), it is reading the QEI and passing it into PIC1 via SPI, which is converts the 2x BYTEs into degrees and displays accurately, so to me it's working, other than that I don't understand?
C
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Hi N,
This I don't understand?
As it is at #27 (on PIC 2), it is reading the QEI and passing it into PIC1 via SPI, which is converts the 2x BYTEs into degrees and displays accurately, so to me it's working, other than that I don't understand?
C
In the full code you've posted, presumably modified via your friend?, the QEI interrupts are disabled - your original code enabled them.

I'll give you a simple 'example' :D

Your mother has three friends - Mr. Uart, Mrs Timer and Miss QEI.

She tells you to go to Mr. Uart's house, and do what he tells you - he gives you a cake, and tells you to take it back to your mother.

Next, she tells you to go to Mrs. Timer's house, and do what she tells you - she gives you a loaf of bread, and tells you to take it back to your mother.

Finally, she tells you to go to Miss QEI's house, and do what she tells you - you get there, and no one is in - so you spend the rest of your live standing outside waiting for instructions from her.

That's a VERY crude and simple example of what you were doing.
 

camerart

Active Member
In the full code you've posted, presumably modified via your friend?, the QEI interrupts are disabled - your original code enabled them.

I'll give you a simple 'example' :D

Your mother has three friends - Mr. Uart, Mrs Timer and Miss QEI.

She tells you to go to Mr. Uart's house, and do what he tells you - he gives you a cake, and tells you to take it back to your mother.

Next, she tells you to go to Mrs. Timer's house, and do what she tells you - she gives you a loaf of bread, and tells you to take it back to your mother.

Finally, she tells you to go to Miss QEI's house, and do what she tells you - you get there, and no one is in - so you spend the rest of your live standing outside waiting for instructions from her.

That's a VERY crude and simple example of what you were doing.
Hi N,
Now I understand!
I've done lots of hanging around waiting for stuff, and I'd probaly eat a bit of cake, and face the concequences later.

I assume then that I've got to I've got to figure out which flags and enables bits to put in order? Is that something like you'd expect?
C
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Hi N,
Now I understand!
I've done lots of hanging around waiting for stuff, and I'd probaly eat a bit of cake, and face the concequences later.

I assume then that I've got to I've got to figure out which flags and enables bits to put in order? Is that something like you'd expect?
C
As you're not using QEI interrupts, then simply don't enable them.
 

camerart

Active Member
Hi,
Just remembered!
When I posted the earlier CODE, with the interrupts, in another part of the program, I had disabled HIGH INTERRUPT. I'm sure this confused everyone, as I missed it out.
This is the way I program, and each time I come to an issue like this this is the sort of tangle I get into.
C
 

camerart

Active Member
Hi,
I'm still stuck and had forgotten this thread, and asked the same question at AAC.
I'm trying to understand how ISR work, and what actually happens at the very high speeds, I'm having difficulty understanding.

As mentioned, I'll concentrate on the ISR with my mate, who can go through it with me.

One question though is, when moving the QEI input (which needs to not miss any counts) do all other interrupts need to be off?
C.
 

camerart

Active Member
Hi,
I think we've sorted out the INTERRUPT problem!
There are 3x INTERRUPTS 1x for position, 1x for speed, and 1x for rotation count.
As this project doesn't need any of them, they can be disregarded.

The error seems to be:
ADCON0
ADCON1
Since these were placed in the INCLUDE, is when the intermittent error started, I'm not sure why, but I went along the wrong fork with INTERRUPTS.
Thanks for all of the effort, much appreciated.
C
 

Latest threads

New Articles From Microcontroller Tips

Top