high tech c and geting time in milli or micro seconds?

i would like to get the time since my pic started in milli or micro seconds is that possible?

how would i do it?

am using a pic16f88 with the internal 8MHz oscillator and i compile my code with “Hi-Tech C”

You could start a timer and use it for that purpose.

With an 8 MHz clock, Timer 1 with a prescale of 2 would count in microseconds (plus or minus a few percent, due to the inaccuracy of the internal osc). It would roll over every 65 milliseconds.

jasonharper:
It would roll over every 65 milliseconds.

What do you mean with that?

I think he means count at steps of 64 ms

You need to maintain a counter in memory with your software that is incremented every time the hardware counter overflows. By varying the prescaler, counter load value and software counter size you can have any resolution you need, within reason.

Leon

i hate to sound annoying or so but i don’t understand how to set one of these timers in C.

is there any example code anywhere, witch tells my what each function does.

Here is how it is done in C18 using the timer library:

/*
** Timer0.c
** Timer test program for PIC18F4520
**
**
*/

//8 MHz clock and 1/16 prescaler
//


#include <p18f4520.h>
#include <timers.h>

//function prototypes
void init(void);
void dly(unsigned int);


// Defines
#define LED			LATAbits.LATA0
#define PB			PORTAbits.RA1

// Macros
#define nop() _asm nop _endasm

void main(void)
{
	init();
	while (1)  
	{
		LED = 1;
		dly(0xFFF0);			//516 ms delay
		LED = 0;           
		dly(60000);			//3.6 s delay 
		nop();          
	}
}


void init(void)
{
	// run internal oscillator at 8 MHz
	OSCCON = OSCCON | 0x70;
	while (OSCCONbits.IOFS == 0) ;
	PORTA = 0x00;
	ADCON1 = 0x0F;		// set up PORTA to be digital I/Os
	TRISA = 0x02;		// PORTA<7:2,0> outputs PORTA<1> input
	OpenTimer0( TIMER_INT_OFF &
            	T0_16BIT &
            	T0_SOURCE_INT &
            	T0_PS_1_16 );
}



void dly(unsigned int c)
{
	INTCONbits.TMR0IF = 0;
	WriteTimer0(c);
	while (INTCONbits.TMR0IF == 0)
		;
}

Leon

duhjalpmig:
i would like to get the time since my pic started in milli or micro seconds is that possible?

how would i do it?

am using a pic16f88 with the internal 8MHz oscillator and i compile my code with “Hi-Tech C”

PIC - wrong forum