I am trying to make Delay_us(4), but when I run it and test it with simple led blinking it blink around 500ms it is not exactly 500ms. But when I try with Delay_ms(500) I have no issue, did anybody know the reason? The reason why I need so small delay is because I try to make sin wave with maximum of 1kHz.
Code:
Code: Select all
long int wait = 0;
void main() {
//*****************************
OSCCON = 0b01110111;
OSCTUNE = 0b10000000;
//*****************************
TRISD = 0x00;
ANSELD = 0x00;
LATD.B0 = 1;
while(1){
wait ++;
if(wait == 125000 ){
LATD.B0 = ~LATD.B0;
wait = 0;
}
Delay_us(4);
}
}