Let's Make Robots!

EDIT: Interrupts (in C) ?


My question is if it is possible to estimate or calculate the time a µcontroller needs in order to execute a few commands. I'm trying to get exactly 1 second that a whole series of commands take, something like this (programmed in C):


//several commands..


The whole while-loop should take exactly 1 second (to make a pretty correct clock), but I don't know if there is a way to calculate the time. I'm just doing trial and error right now but I guess there are better ways?

Thanks in advance!



EDIT: I'm testing these interrupts now (in C language), found some tutorials on the internet, and got the timer working but the external interrupt doesn't work for me. The datasheet says that RA2-pin (I'm using a pickit2 with a PIC16F690) is the INT-pin.

Here's the code i'm using to light a led if the external interrupt on RA2-pin is activated:

#include <htc.h>


void interrupt LED(void){
    if (INTF){
        INTF = 0;
        RC0 = 1;


    PORTA = 0;              
    PORTC = 0;
    TRISA = 1;
    TRISC = 0;               
    INTCON = 0b10010000;
    while(1)               //  Loop Forever

I use a male to male jumper cable to connect the Vdd to RA2, nothing happens. I tried putting an output high and connecting that output with RA2, nothing... What am I doing wrong?

Thanks in advance


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Use the stopwatch in mplab. It's in the simulator under the the debugger menu. Make sure you set the frequency your processor is running at under debugger->settings. Set breakpoints at the start and end of the section of code you want to time.

I know because I just caught myself looking for a way to "up vote" Merser's comment...