In timer640.c:
Current version:
void delay_us(unsigned short time_us)
{
unsigned short delay_loops;
register unsigned short i;
delay_loops = (time_us+3)/5*CYCLES_PER_US; // +3 for rounding up (dirty)
// one loop takes 5 cpu cycles
for (i=0; i < delay_loops; i++) {};
}
The delay_loops calculation appears to be incorrect. If you pass in 1us, you get a delay_loops of 0 (1+3=4, 4/5=0, 0*16=0). For the Axon you really want something close to 16 cycles, or 3 loops (provided the 5 cycle per loop comment holds true).
Proposed new version:
void delay_us(unsigned short time_us)
{
unsigned short delay_loops;
register unsigned short i;
delay_loops = ((time_us * CYCLES_PER_US)+3) / 5; // +3 for rounding up (dirty)
// one loop takes 5 cpu cycles
for (i=0; i < delay_loops; i++) {};
}
With this version, if you pass in 1us, you get a delay_loops of 3 (1*16=16, 16+3=19, 19/5=3), which equates to 15 cycles (closest possible to the 16 cycles per us on the Axon).
Is this correct, or am I missing something?