--- Quote Start ---
1) Make sure you compile everything with -O3
2) Get rid of superfluous boolean variables, use break and return.
3) Use do { ... } while (...); to remove the test from the loop top
4) Don't use 'const int' - it is still likely to be a variable.
I would code the bottom of the loop as:
// wait done
nWaitCnt = nMaxWait;
for (;;) {
Data16 = IORD(READ_ADC_BASE,0); //Data16 = Wert des Kanals
if (Data16 & DONE_FLAG)
break;
if (--nWaitCnt == 0)
// All gone horribly wrong....
return 0;
}
DigitalValue = Data16 & 0xFFF // 12 bits
// stop
IOWR(READ_ADC_BASE, 0, 0); //Kanal löschen
return DigitalValue; //DigitalValue zurückgeben
You may also want to use gcc's __builtin_expect() to force which code paths are inlined.
--- Quote End ---
Hi again, I tried the Code but It didn`t work but my old Code also. What ever I do I alway had the Max Value and I don`t know why. The A/D Converter is not connected and I get the max Value??
Maybe somebody could help. Thx