:: Home :: Code Snippets :: Drivers :: Projects :: About ::
 Main Menu
  Code Snippets

 Open Drivers
 EA-DOGM - LCD Display Driver
 PIC32 mcompat - PIC32 mcompat
 qTask - Queued Task Manager
 _build - Embedded build information

 Open Projects
 fplCore - Self contained controller
 uProfiler - uController uProfiller
 oLogic - Oscilloscope Logic Viewer
 oLogic 1.4 - NEW Logic Viewer
 SSX32 - Serial Servo Driver



Supply House
  Allied Electronics
  Clearwater Technologies

  N34D Blog

Times various internal functions and code sections


The uProfiler is a hardware based profiler that you can use to debug your uController project.

This profiler connects to your PC via USB, and apears as a CDC Serial port.

Connect to this serial device with an ANSI Color terminal.

I had been using a few pins connected to my scopes to measure pulse widths so I could measure various loops and functions, and sending debug info into a terminal.

Then I saw the code profiler built into CCS C compiler, I tried to reverse it a bit, as I didnt have their ICSP programmer. Then I just decided to dive in and put something together that would not tie down the PIC, and something I could remove from source very easily.

Checkout the usage.txt file listed on the right.

In your code, include the uprofiler.h file, and insert various pieces of code into your source
and you can debug the following:

  • Determine main loop running time
  • Time various functions (up to 16)
  • Time various sections of code (up to 16)
  • View up to 16x 8 bit variables or 8x 16bit variables
  • Inc/Clear 15 counters
  • Set and Clear 16 flags
  • Turn on/off 5 LED's (also displays on screen
  • Set a State output (useful for state machines or status)

All this with very little impact on your C source code. All measurements are done in the uProfiler, as well as all the ANSI color output. Just connect to an ANSI Serial terminal.

We take the generaly unused pin B7 (Microchip uControllers)
and create a BitBang'd serial output from it, and use that to feed
the uProfiler.

The overhead your C program incures is minimal, just the time it takes to bitbang 1 byte for most of the profiler functions.

Exceptions are viewing variables, that sends 3 bytes for 8bit, and 6 bytes for 16bit.

It is easily possible to modify the header file, and use a hardware UART to lower the impact.

Note: Great pains were taken to tune the timming functions within the uProfiler. We are accurate to within +/- 15us. Now I know that a super critical loop can be lower than this. If you need super accurate timming, please, use a dedicated pin and a scope.

Note 2.0: There may be a pin timing input on this project in the very near future

Here is an example:


#define UPROFILER_BAUD 19200 #include "uprofiler.h"

void blink(void)

output_high(PIN_B5); delay_ms(50);

uProfState(0x03); uProfFlagClear(0x01);

output_low(PIN_B5); delay_ms(50); }

void main() { unsigned int16 x,y,z;


while(TRUE) { uProfMain();


uProfLedOn(0x00); uProfState(0x01);


uProfSecStart(0); x=5000; y=200; z = x/y; uProfWord(z,6); uProfSecEnd(0);

uProfFunStart(0x00); blink(); uProfFunEnd(0x00);

} }
 Project Specs
sw ver: 1.1
mcu: 18F2553
compiler: CCS C

PIC: 18F46K20
All Caps: .01uF


uprofiler.zip - All files

:: Home :: Resources :: PIC Microcontrollers ::
:: 10F :: 12F :: 16F :: 18F :: 24F :: 24H :: 30F :: 33F ::
(C) Copyright 2009 mculabs.com - contact: info@mculabs.com