Forum Discussion
Altera_Forum
Honored Contributor
14 years agoC Code for ADC
Hi, I have one question about the code.I have a A/D Converter on the DE0-Nano Dev Board. THe code is nearly the same like in the Demo for the A/D Converter how comes with the CD. My Question is...
Altera_Forum
Honored Contributor
14 years ago1) 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.