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);
}
}
need to give a variable delay in us range
Re: need to give a variable delay in us range
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
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
Re: need to give a variable delay in us range
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
Is it possibly to change the Vdelay_ms so that it can be use for microsecond delays?
Thanks