my appologies for the delayMicroseconds(0) in replying.... pun intended.
I'm working on an ignition timing circuit which has a potentiometer on A0 that essentially translates into a delay that is the inverse of the Timing Advance. So, if I want all 20 degrees advance then my pot is set to 0 and that is translated into delayMicroseconds(0).
I'm using this function because I want as much resolution as possible... and adding say 20-40us of programming overhead is still acceptable compared to being limited to a 1ms resolution..
This is how I've been coping with the 0 and 16383 limit:
if (u_offsetTime == 0){ //when delayMicroseconds(0) = 16383µs.. glitch in library.
u_offsetTime = 1;}
if (u_offsetTime >= 0x3ffe){ //delayMicroseconds limit is 0x3fff, so we seperate the number into 2 variables.
u1_offsetTime = (u_offsetTime - 0x3ffe); //made this 1 less than 0x3fff because I want to be EXTRA sure that it doesn't do funny things.
u_offsetTime = 0x3ffe;
if (u1_offsetTime >= 0x3ffe){
u2_offsetTime = (u1_offsetTime - 0x3ffe);
u1_offsetTime = 0x3ffe;}
else { u2_offsetTime = 1;}
}
else {
u1_offsetTime = 1;
}
so far it seems to be working fine and I'm able to have (16382 * 3)us of delay if I need it...
I feel like I'm trying to cut a turkey with a fork. It's crewed but it seems to be working.
Thanks for all the replies.