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.

debug code implementation

Status
Not open for further replies.

ThermalRunaway

New Member
Hi everyone,

As I've started taking on more complex programming tasks with Microcontrollers I've started to give consideration to the usefulness of debug and self test code within my projects. At the moment I am trying to think about the best way to implement this type of code.
For example, my current project sends debug code out on a serial port so that I can connect a terminal to it and monitor what my software is doing as it executes. It can tell me what functions I'm executing, values returned for sensor readings, and stuff like that.

This is all very well, but of course it adds to the overhead in terms of memory usage and runtime of the application. Ideally it would be nice if I could turn the debug mode on and off so that it only executes this extra code when I need it to. An easy way to do this is to declare a debug variable and then check it within the program each time the debug code would normally be called.

This improves matters, but there is still the overhead involved in continually checking my debug variable as the program is executing.

A more ideal solution would be if the debug code could be completely deactivated so that there is no additional overhead at all when the debug mode is not required. I can do this at compile time quite easily, but I can't figure a way to do this in a runtime situation. And this leads on to my question for more experienced embedded programmers:

Is it possible to implement debug/test code into applications that can be switched on and off at runtime in a way that totally removes the additional overhead when the mode is not required? Or, is it normal to continually check the status of a variable and live with the small overhead that results?

Thanks all,

Brian H.
 
hi,
Have you considered conditional assembly within your programs.?
**broken link removed**
 
Why not simply check 1 pin at startup and have it set a flag. Then simply "if" the flag, You will save a ton of CPU time

Ex:
Code:
//GLOBAL VARIABLES and DEFINITIONS
#define DEBUGPIN inputpin
char DEBUG_MODE = 0; 

...

//Check at startup
if(DEBUGPIN == 1)
    DEBUG_MODE = 1;

....

//Within all code
if(DEBUG_MODE)
{
    // DEBUG CODE
}
 
Last edited:
hi,
Have you considered conditional assembly within your programs.?
**broken link removed**

Hi Eric, thanks for the reply.

My language of choice is C, but yes I do understand what you're talking about and there is in fact an equivalent of this for my C compiler. The problem is that it's a compile-time decision, not a run-time decision. Once you've compiled the code with either the debug code included or not, you can't change it without recompiling and reprogramming.

BrianH
 
Why not simply check 1 pin at startup and have it set a flag. Then simply "if" the flag, You will save a ton of CPU time

Yes that is in fact the method I currently employ. It does save a lot of CPU time in comparison to needlessly running the debug code, but there is always the unavoidable overhead associated with continually checking your flag for the debug status as the code is running. The reason for my question is to confirm that the flag testing method is a reasonable method of switching the debug code in/out and that there isn't a more efficient method that doesn't involve continually testing a debug flag.

Thanks both, it looks like I'm on the best track already.

BrianH
 
Last edited:
i doubt it. Erics option is the only other .

Great - that's what I wanted to hear!

Sometimes when you're still learning stuff (self taught) you wonder if the way you think something should be done is in fact the best way of doing it, or if you're missing a trick. It seems that I am not missing any tricks here, so that's good.

Thanks again.

PS: Love your videos on You Tube Jason - been subscribed for over a year now I think!

Brian
 
Heh yeah, i feel the same way sometimes. Thats why i have so many post :) i always ask to make sure or just check to see if there is another better way. Usually there is. But remember since you are the post writer if anyone has suggestions and post it at least you will be updated :D

And thanks! as you can see i get board A LOT! heh ill be adding new videos soon. Have to market some products :D
 
heh ill be adding new videos soon. Have to market some products :D

Yes I want to go down that road as well. Currently I am working for a living, and although I enjoy being an Electronics Engineer, to be honest with you the pay isn't all that great (in comparison to other arguably less skillful trades), and I don't feel that Engineering gets the respect it deserves anymore (nor has it ever done since I've been in the game). So the one thing I've learned from all this is that in order to get satisfaction from your career, you really need to be working for yourself - even if it means starting out small and doing it alongside a full time regular job. In any case, the end goal of working for a living should be to work for yourself one day. And that's the direction I hope to be moving in.

Keep up the vids!
 
Nice post! yeah thats what im trying to do. I hope to at least make some type of money to be able to have a good stock of products. Not only to sell to online customers but to be able to open a small business on the side for things like Home Automation. Thats my main goal.

Want to be able to see and control everything at home from anywhere. The issue is mostly security but that shouldnt be a problem, i also want to create security systems and fire alarm panels. I used to do work installing them and found it over complex to setup heh

I think i can do a better job and create a better interface. Fire alarm panels and security panels cost a arm and a leg. So makething them for $40 and selling for $200 should bring profit :D

I wish i could work a normal job but cant i suffer from BAD Anxiety and barely leave my house. I can go about 2-3 blocks walking then get sick. It sucks!!! So technically im disabled but i try to work from home. Its fun learning anyway.
 
Last edited:
I wish i could work a normal job but cant i suffer from BAD Anxiety and barely leave my house.

I think that happens to most people to some extent. When you're starting out it can be especially difficult because you're new to the game and you have doubts about whether you have the right skills to be a good Electronics Engineer. But once you start doing it, you realise that on a day to day basis even more experienced Electronics Engineers have the same basic problems as you do. They sit down with them, think about them, try some ideas and find a solution. It's no different for them than it is for us, other than they have a bit more job experience to call upon when they face a problem. But the problems they experience are no different to those you and I would experience. They're exactly the same.

My experience has been that it's not your Electronic Engineering colleagues that you need to worry about - they're working for a living the same as you and, as they experience the same day to day problems as you, there's a basic feeling of being in the same boat.

AtomSoft said:
I think i can do a better job and create a better interface.

That's how most good businesses start out I reckon! Especially with attitudes like:

AtomSoft said:
Its fun learning anyway.

:)
 
Last edited:
Thanks heh, Its nice to know what i say and feel is good! heh

If i can help i will ... im off to go watch some tv now... brain needs a break. Got a headache. Then ill update my site with UART0 for the LPC210x... work ... (well work isnt work if its fun)
 
Status
Not open for further replies.

Latest threads

Back
Top