Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Weird GUI Numberbox Post ReplyPost New Topic
<< Prev Page of 2
Author
Message << Prev Topic | Next Topic >>
Malibu
Newbie
Newbie


Joined: 07 July 2018
Location: Australia
Online Status: Offline
Posts: 12
Posted: 15 July 2018 at 8:19am | IP Logged Quote Malibu

I'm happy to say my numberbox mystery is solved

I shelved the idea of using a numberbox, but it bothered me that I hadn't worked out what the problem was, so I added some temporary code in to try and get to the bottom of the NumberBox problem.

With putting the code in exactly how the rest of the code is structured and basically how I had it previously, the problem popped up again right away - the ghosted keypad.

Then in a "What was I thinking?!?!?" moment, I realised that my TOUCHUP interrupt is probably way too long. At 106 lines of code, the poor uController was having a brain-freeze trying to keep up.
So... I wrote a new SUB, put all of the interrupt code in that and set a flag in the interrupt to get dealt with elsewhere...
Aaaaahhh, that was it... I used the keypad over 100 times and it didn't miss a beat!

Ooops, a basic mistake that's caught me more than a few times before now.

Thanks for everyone's help! (Oh, and I have an external supply hooked up now)

John


Back to Top View Malibu's Profile Search for other posts by Malibu
 
Geoffg
Guru
Guru
Avatar

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2349
Posted: 15 July 2018 at 2:33pm | IP Logged Quote Geoffg

As Grogster said... "Thou shalt not hang around or process code in interrupts."
Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage
 
Grogster
Guru
Guru
Avatar

Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 5897
Posted: 15 July 2018 at 2:53pm | IP Logged Quote Grogster

Malibu wrote:
...I realised that my TOUCHUP interrupt is probably way too long. At 106 lines of code...


Ahhhhh - yes, just a tad.

Malibu wrote:
I wrote a new SUB, put all of the interrupt code in that and set a flag in the interrupt to get dealt with elsewhere...
Aaaaahhh, that was it... I used the keypad over 100 times and it didn't miss a beat!

Ooops, a basic mistake that's caught me more than a few times before now.

Thanks for everyone's help!


Yes, you must not spend any real processing time inside interrupts. I did the same as you, when I was learning the GUI controls. It's natural to think you should put all that you want to happen inside the interrupt, inside the interrupt.

I also used to get odd things happening when I would put the code in the interrupt, so I know what you have just been through. It really does require that you rethink your approach to the code, and I pretty much have settled on just setting and clearing flags, usually with a single IF/THEN/ELSE statement, then exit the interrupt so the main loop takes command of the ship again. It is really easy to check the flags - ANY flags, outside of the interrupt. Essentially, your interrupts should be ASAP - As Short As Possible.

Glad you got it sorted. You will have noted how having the interrupt so long, DID create a very obscure bug, which is never a good think unless you LIKE scratching all your hair out.

EDIT: Actually, when I just looked up some of my interrupts, I use SELECT CASE rather then IF/THEN/ELSE, but the concept is the same. Just set or clear flags. As an example, my interrupt for OK and EXIT buttons used on lots of pages - this is how the system detects them, and the main loop waits for one of those flags to become true, then it does the work. Loop until LCD_OK kind of idea.

Quote:
SUB EXIT_OK 'Touch interrupt for EXIT and OK buttons on any page
LCD_EXIT=0:LCD_OK=0
Select Case Touch(REF)
Case BU_EXIT
LCD_EXIT=
1
Case BU_OK
LCD_OK=
1
End Select
End SUB



Edited by Grogster on 15 July 2018 at 3:10pm


__________________
Smoke makes things work. When the smoke gets out, it stops!
Back to Top View Grogster's Profile Search for other posts by Grogster Visit Grogster's Homepage
 
Malibu
Newbie
Newbie


Joined: 07 July 2018
Location: Australia
Online Status: Offline
Posts: 12
Posted: 15 July 2018 at 3:43pm | IP Logged Quote Malibu

Quote:
"Thou shalt not hang around or process code in interrupts."


"Amen!" to that!

Quote:
Yes, you must not spend any real processing time inside interrupts. I did the same as you, when I was learning the GUI controls.


It's funny though, I already knew that from hard learned lessons in assembly code on 16F's... I was kicking myself when I realised what I had done.
Maybe I just spent too long coding in VB6 and forgot all the "good" coding rules.

Here's what I finished up with
sub TouchUp
  TouchControl=touch(LastRef)
  Touched = 1
end sub

The code stays in a DO:LOOP until I get the flag set, then it operates on which button was touched.

MUCH better!

John
Back to Top View Malibu's Profile Search for other posts by Malibu
 
Grogster
Guru
Guru
Avatar

Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 5897
Posted: 15 July 2018 at 4:46pm | IP Logged Quote Grogster

MUCH better, indeed. That's a lovely little interrupt now.



__________________
Smoke makes things work. When the smoke gets out, it stops!
Back to Top View Grogster's Profile Search for other posts by Grogster Visit Grogster's Homepage
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
<< Prev Page of 2
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1084 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.11