Inconsistent Interrupt behavior

Thank you Dave, good point. I changed this but am still getting issues. It’s definitely some sort of timing-entrance issue.

I will be posting some reproducible code at some point today. I checked the Motor busy loops its not that. The display is the only new addition to my hardware from the last time I tested a combined breadboard prototype with the dev board.

This might not be entirely on point but I wanted to share that I did some testing to decide if I wanted to poll my buttons or use interrupts. What I found was that an interrupt may trigger anywhere between 5 ms and 27 ms after a button press in my application. On average it triggered at 16 ms after the press. My main logic when the device is idle can run at almost 200 Hz right now, and if a button triggers more code I’m fortunate in that I don’t want more buttons to be registered until the previous routine is complete.

So ~16 ms with interrupts vs. ~ 5 ms without. IDK what else is at play but polling was the way to go for me. Gotta get that button info across a wireless link so I’m counting every ms. Easier to keep track of as well because I have less threads alive when debugging button stuffs.

Also that new string stuff. Make those static or cosnt. You are just asking for the garbage collector to get in there or even worse to run out of memory. In my experience the G30 is pretty nice about telling me that I ran out of memory if in a Try block and confusingly sometimes it is nice about it outside of Try, but without Try quiet failures happen often as well. So I always allocate significant memory inside Try.

Seems these strings can become significant memory usage depending on the size of Taba array, also if this whole code snippet can execute many times over its 20 ms slice and saveFlag is true then I suspect you are making lots of strings.

But maybe it isn’t a memory issue and just broken logic. I don’t know if the logic is correct for your application or not but I do know, and with all due respect, it is poorly written. The structure is poor. Even if this was the entire program aside from the setting of these flags it’s not immediately obvious what executes and when.

For example the for loop won’t execute for the second entry of taba until until saveFlag is true. It will just keep testing for fwdFlag and revFlag and running those blocks when they are true.Then what happens to saveFlag after it is true? – is it still true? Then for each entry of Taba you will just run the if (saveFlag) block until it’s false. You might want this, but good luck to anyone trying to make sense of why you want it.

Why is this meant to run the length of Taba anyway? it isn’t even used inside the block. Very mysterious to us without knowledge.

It’s the opposite of tight… it has the potential to never exit in many ways.

You mentioned in another thread that you never programmed a full MCU app before. I’m wondering if maybe you aren’t really following how things are going to execute. I’m thinking about how a lot of novice video game programmers will use a while loop for something like

while ( mouseButton is DOWN ) fireBullets();

They think this will make some nice automatic fire and they don’t realize that a game is meant to update at at least 30 frames per second and they are causing the engine to be stuck on processing a single frame (this single line in fact) generating hundreds of bullets in the same position and not drawing new images or processing the rest of the game’s objects until the mouse is released (actually probably until the OS shuts the game down because the engines I’ve used do not expose a volatile/interrupt-driven version of mouse information).

So in your case I’m wondering if you are aware that this code you have is not going to execute from top to bottom for each element of the taba array until the logic of saveFlag allows it to get through the while loops. Even if another thread runs, when it gets back to this one its still just in the while loops for the one entry of taba.

1 Like

Sorry about the essays, but one last thing. If pushing the button is supposed to bring the pin LOW then the pin should be configured as PULLUP.

I know you said “buttons are configured for pull down” which makes sense but just in case you meant “pins” those should be PULLUP.

1 Like

Yes I have the pins set as pullups. As far as the save flag, it is supposed to be like that. It is a calibration loop…I have to toggle the motor back and forth to find the value I want then save that position…it then restarts back at the top of the for loop where all the flags are set to false. No I am not generating a bunch of strings. Those are just motor inputs I need to move around to. I am trying to keep it as mysterious as possible while still getting the required information across.

I think I have it figured out (thanks to @bfisher’s suggestion …I had changed the Thread.Sleep(1) to 10 inside of the motor busy loops as others suggested. This actually made things far worse, so I tried what @bfisher suggested and actually made those while loops empty. Works like a charm so far…20+ runs and it hasn’t failed yet - and it was glitching out 50% of the time or more. I just have to verify it works once I uncomment the display code.

1 Like

Well boy do I feel silly. I missed some of the code at the top. Also knowing what it is meant to do makes it make a lot of sense. Still think you should consider following some “Clean Code” methodologies.

haha no worries. my test code just gets really messy because I keep switching things up. Doing the best I can though regardless of how it appears to you all. My entire career rides on this project, its got me so stressed I literally lucid dream about what capacitor and resistor values I should be picking.

I used to messily test out stuff too. Like just two weeks ago. Then one day someone demanded, “Show me how you got these numbers, run it again.”

Now I create branches in my repository for every test and although I don’t use the same amount of effort as when developing the actual app, I try to keep it clean.

These are slightly different definitions of “test”, but when I’m working on a new feature and its all spaghettified but I still think there is only a minor error then I unspaghettify before tackling it.

LOL my dreams (nightmares) are filled with the acrid smoke of burning motor lubricant and molten semiconductors.

Hang on while I google what a repository is lol can you elaborate on how you go about this / what exactly it accomplishes?

Git Repository. Git is a source control program. Using it properly makes it easy to keep track of what changes have been made and to roll back to previous versions of the code if needed. More advanced users can do a lot. Many teams use it to make it more simple for multiple programmers to work on the same files without stepping on each other’s toes.

If you aren’t using source control, then stop what you’re doing, learn the basics of Git, and start using it. I can’t stress how foolish it is to ignore this lifesaving tool.

Make a copy of what you have now in case you make a mistake, and then start using git from this point on. Never too late!

I use Git Bash to enter git commands I learned on this site:

Git Basics

This stuff is integrated into Visual Studio but I only use that as far as the visuals concerning the “State” of my working branch. For instance if I see a lock icon next to each of my files int eh solution explorer then I know I have changed nothing since my last “git commit.”

1 Like

With a GIT repository do you need a Sleep(10)?

4 Likes

maybe not, but you still need magic salt or unicorn poo

3 Likes

Hey man, I hope this all going well for you. I wanted to make this analogy as to why there seems to be some push back against your questions:

So you’re Michael Thomas right? You landed your project the best gig in town: playing for the Saints. You want Drew Brees (Brett) to throw you a touchdown pass to end the game. He keeps telling you to run the deep route (post entire, simple and testable programs that feature the bugs in question) but you keep asking for the same short slant. But Brees can’t even see you because Max Unger (all of the unknowns) is standing tall in front of the pocket.

Sean Payton (Mike) is just laughing cause he’s got all the talent he needs with or without you.

So you gotta learn to run the route. And, hey, put it in the playbook (Git Repository)

1 Like

@jwizard93 Lol good analogy. I thought I had it working but then started getting hangs when using the debugger…if I run the code without debugging, it doesn’t fail.

With the debugger, it always hangs in the same spot - it issues Go_Until to my motor driver which begins the motor moving, then the G30 just shoots off somewhere into oblivion and doesn’t hit the breakpoint at the next line. I have tried restructuring the code like 10 different ways…

Sounds like a problem discussed many times in the forum.

What are the differences between running under the debugger and without?

1 Like

@Mike Haven’t searched the forum yet just been running ridiculous amounts of tests trying to get it to fail and noting down what happens…getting one failure occasionally even without the debugger where it goes through the code but its like the motor is choked (or the code is forced through before commands complete) and struggles to move. Happens like 1% of the time but its definitely still something I need to iron out.

Running with the debugger seems to be choking the processor too much even with all of the previous suggestions. With the debugger, it fails after executing the Go_Until command about 50% of the time, if not more. Without the debugger, processor has room to breath and code runs great ALMOST everytime

Ive never had these issues you have. And I have what I’m assuming is a very similar project in at least a few regards. When I attach the debugger everything happens as expected, it just happens at a slower rate.

I made sure that I could slap a big theoretical pause button on this app. and I could do anything with the processor save mess with my app’s variable while “paused” and when returning to my normal app everything would still be gravy. (This is all theory / thought process while designing but maybe provable by the fact that the debugger never messes up the app)

Put Go_Until in a Try block and try to catch something useful.

Or step into Go_Until and find the exact line that actually causes the crash.

@jwizard93 looks like you know what you are doing :wink:

I have it in a try block (no exceptions thrown) and I also stepped through the code. It finishes the execution of sending data across SPI then as soon as it leaves that method it goes nowhere traceable (at least that I have found so far)…doesn’t hit the breakpoint on the next line.

I ran this same exact code on the development board and did not have this issue. I am wondering how many wrong capacitors my tech put on this board lol I found like 5 through visual inspection. If she put, say a 1 uF cap for the 100 nF decouplers, would that cause any weird behavior?