need to give a variable delay in us range

General discussion on mikroC.
Post Reply
Author
Message
Sanu
Posts: 3
Joined: 13 Feb 2010 13:08

need to give a variable delay in us range

#1 Post by Sanu » 15 Feb 2010 02:07

i need to give delays in micro seconds defined in del.how can i do that.can i use vdelay function
const int del[]={1000,1500,2000,2500,3000,3500,4000,4500};
int i;

void main() {
ADCON1 = 6;
CMCON = 7;
trisa=0x00;
trisb=0x00;
trisd=0x00;
TRISC=0X00;
portc=0xff;
i=0;
if(Button(&portb,3,1,0))i++;
porta=0b00000000;
Lcd_Config(&portd,0,2,1,6,5,4,3);
Lcd_Cmd(LCD_CURSOR_OFF);
LCD_Out(1,1,"test");
while(1) {
PORTA.f1 = ~PORTA.f1;
Delay_us(del);
}
}

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

Re: need to give a variable delay in us range

#2 Post by anikolic » 16 Feb 2010 15:27

Hi,
The best choice for now would be to use void Delay_Cyc(char cycles_div_by_10) function, which can be very precise according to your Instruction Cycle clock. So, calculate how many nops fit in one microsecond, and you can call Delay_Cyc() with this value divided by 10.
For example:
If you use PIC18F4550 @ 48MHz PLL than instruction cycle is Fosc/4 = 12Mhz, which means that execution of 12 nop instructions last exactly 1 microsecond. If you need, let's say 5 microsecond delay, this would be 12*5 = 60 nops, so you should call Delay_cyc(6);

Best regards,
Aleksandar
Web Department Manager

JPablo
Posts: 14
Joined: 05 May 2010 23:44

Re: need to give a variable delay in us range

#3 Post by JPablo » 31 May 2010 01:00

Is there any possibility for a Vdelay_us command? I am trying to drive some servos and would like to change the micro second variable.

Is it possibly to change the Vdelay_ms so that it can be use for microsecond delays?

Thanks

Post Reply

Return to “mikroC General”