Home > other >  AVR microcontroller precise software latency
AVR microcontroller precise software latency

Time:10-07

I use is mega8 single-chip microcomputer, vibration crystal configuration is 11.0592 MHz, the compiler USES the ICC AVR 7.2, tested software delay with oscilloscope, code is as follows:
Ms delay time accurate, magnitude of us delay slightly larger, 100 us more error in the digital,

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The function name: delay_ms
Can work: delay milliseconds specified crystals (11.592 M) compiler ICCAVR7.2
Ginseng: MS - delay the number of milliseconds
The return value: no
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay_ms (unsigned int ms)
{

Unsigned int I=0;
Unsigned int j=0;
for( i=0; i{
for(j=0; J<1578; J++)
{
//asm (" nop ");//1578 is under 11.0592 MHz crystal vibration, through software simulation and the experiment value
}
}
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The function name: Delay_us
Can work: designated microsecond delay crystals (11.0592 M), the compiler ICCAVR7.2
And count: the US - the number of millisecond delay (about, is not very accurate, the more accurate the greater the MS)
The return value: no
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay_us (unsigned int us)
{
Unsigned int time=0;
For (time=1; Time{
Asm (" nop ");
Asm (" nop ");
Asm (" nop ");
Asm (" nop ");
Asm (" nop ");


}

}

CodePudding user response:

You can use the IAR system time delay function, or more accurate

CodePudding user response:

Is, just IAR not familiar with, the project and try so hard, the temporary use of ICC make use,

CodePudding user response:

Ms can use interrupts to dry, and improve efficiency
  • Related