Microcontroller load display

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Microcontroller load display

4,334 Views
ohanica
Contributor III
Hello!

I've got the following question: How is it possible to know the load of an Microcontroller for a certain programm running on it.
I am using CodeWarrior Special Edition and a HCS08DZ60 controller. I wrote a program that builds to a 20k s.19 file. This is about 1/3 of the program memory of the controller. The controller is running at 8MHz. Now I want to know how "hard" it is for the uC to run this program. Is there any possibility (in the P&E debugger, or in CodeWarrior) to show the load of the MCU?
Is the load in a "one task system" allways 100% or does it differ depending on external events like interrupts, peripheral modules beeing active like ADC or CAN controller...

What I want to know is: can I use a smaller, less powerful microcontroller for the same project? Or are program memory, speed and needed peripherals the only features I need to decide which controller I can use.

Thanks,
JohannesSubmit Post
Labels (1)
0 Kudos
Reply
7 Replies

962 Views
bigmac
Specialist III
Hello Johannes,
 
The load on the MCU may be heavily dependent on interrupt activity, particularly peripheral interrupts that are activated by external events, and over which you have no control.  If it is possible for certain interrupts to occur very frequently due to the presence of noise, these may occupy a large portion of the available time.
 
In general, interrupt processing should be kept as short as possible, but if there can be wide variability in an ISR processing time, with the more lengthy periods occurring very infrequently, you will need to be aware of this, to allow for a worst case scenario that may be difficult to measure, or otherwise predict.
 
Assuming you are able to operate close to the maximum allowable bus frequency for the device, it should not matter which HCS08 derivative you choose, providing it has the resources that you need for the project.  To substantially increase the throughput rate, you would need to choose a more powerful MCU family, such as ColdFire.
 
However, before considering such a step, you may find that you can reduce the loading on the MCU with code changes that control the frequency and/or duration of the interrupts.
 
A very simple method to see whether interrupt processing represents a significant load might be to toggle a pin at a single point within your main loop.  If you get wide variability of the period between successive toggles, this probably indicates substantial ISR loading.
 
Incidently, a .S19 file size of 20k would probably represent code size of less than 8k.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-05-01 01:42 PM
0 Kudos
Reply

962 Views
allawtterb
Contributor IV
The debugger will not tell you the load, the microcontroller is always running (unless it is put in some sort of stop mode) and it has no idea what tasks are just waiting for something to happen and what is actually processing.  The best thing to do often is leave a port pin that can be used for debugging, this could even be just a status LED that has a convenient place to connect your o-scope.  You might do something as simple as setting a pin when the micro is doing anything that you would consider processing instead of waiting.  Jack Ganssle wrote an article on simple ways to look at the load on your system, ISR processing time etc at the following link.  It is worth a read for some ideas.
 
0 Kudos
Reply

962 Views
ohanica
Contributor III
Hello bigmac, hello allawtterb.

Thanks for your answers. Yes indeed this pin toggeling in the main loop is a very good idea. There are timer-based interrupts toggling different bits in my code. If one such bit is on certain actions are taken so my main loop takes longer time to run through. Because of this I get regular variations in loop-time.

I am handling incoming CAN-messages with an ISR also. Here I have no influence... ISR load depends on how  often there is information on the bus that is relevant to me. This slightly disturbs my regularity. CAN communication works fine. Is it   better/more performant   to use CAN frame buffers and polling technique for incomming CAN-communication?

@bigmac: How do you estimate/calculate that a S19-file of 20k results in 8k of code? Why? I thought the S19-file is a kind of machine code already (which contains instructions that are fetched from memory by the uC). Overhaead in this file format is never 40% i guess. In each s-line there is about 10% overhead (as I estimate).

regards,
Johannes
0 Kudos
Reply

962 Views
Lundin
Senior Contributor IV
I'd say it is more efficient to poll the CAN buffers, and do so several times while you are at it, so that all buffers are emptied. This will of course depend on the nature of the system and how often CAN messages are received. But CAN is in almost every case relatively slow in comparison with the CPU.

If the main() loop is busy with a lot of other things and can't poll quick enough, you can always store the incomming messages from the ISR in a queue in memory.

S19 files are ASCII codes, not machine code. So it takes two bytes of ASCII to describe one byte of data. And then there is the overhead. It seem very likely that a s19 of 20k on a Win XP PC would equal something around 8k of machine code. I have a project here on 4.3k and the s19 is 10k.
0 Kudos
Reply

962 Views
bigmac
Specialist III
Hello Johannes,
 
The attached file should provide some insight about the format of a S19 file, and the required overheads. 
 
Starting at 50 percent, because of two characters per byte representation, the further reduction due to overheads will also depend on how many bytes per S-record, or line.  Typically there would be 16 or 32 bytes represented per line.  Assuming 16-bit address values, the overhead per line would amount to 10 characters.  There will also be other overheads of much lesser overall effect.
 
For each 16-byte S-record, 42 characters (38%).
For each 32-byte S-record, 74 characters (43%).
 
Regards,
Mac
 
Actually, I forgot about the EOL characters, so add another two characters for CR/LF.
 



Message Edited by bigmac on 2008-05-06 02:10 AM

Motorola S-record description.zip

Message Edited by t.dowe on 2009-09-04 11:10 AM
0 Kudos
Reply

962 Views
fabio
Contributor IV
Regarding the CPU load, you can use an external pin (which is turned on when out of interrupts and turned in when inside an ISR). With the help of a scope, you can easily view the CPU loading.

Note that there is an additional overhead caused by the instructions needed to turn on/off the pin.

Another approach could be the use of the profiling tool. Unfortunatelly, it depends mostly on the BDM tool speed (as the profiler periodically reads the address of the current instruction in execution). Another drawback is that the full profiler is not available in the Codewarrior Special Edition ...

Best regards,
0 Kudos
Reply

962 Views
allawtterb
Contributor IV


ohanica wrote:
@bigmac: How do you estimate/calculate that a S19-file of 20k results in 8k of code? Why? I thought the S19-file is a kind of machine code already (which contains instructions that are fetched from memory by the uC). Overhaead in this file format is never 40% i guess. In each s-line there is about 10% overhead (as I estimate).

regards,
Johannes


This overhead is typical (over 50%) for the projects I am currently working on.  If you want to how much flash you are taking up take a look at your map file, I wouldn't be surprised if it was in the 8k-10k range.   
0 Kudos
Reply