Let's Make Robots!

EDIT: Interrupts (in C) ?

Hi,

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):

while(j<time){

//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!

_ZlaTanskY_

 

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:

#define _LEGACY_HEADERS
#include <htc.h>



__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
  & UNPROTECT & BORDIS & IESODIS & FCMDIS);



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

main()
{

    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

_ZlaTanskY_

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...