Altera_Forum
Honored Contributor
13 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 it possible to let the code work faster or s shorter program so i can read the ADC faster. Here is the code but the commends are German. --- Quote Start --- #define START_FLAG 0x8000 //1000 0000 0000 0000# define DONE_FLAG 0x8000 //1000 0000 0000 0000 alt_u16 ADC_Read(alt_u8 NextChannel){ //Wiedergabewert 16bit ( Übergabewert 8bit) int bDone = FALSE; alt_u16 Data16, DigitalValue = 0; // 16bit Data16 const int nMaxWait = 10; //Konstante nMaxWait = 1000 int nWaitCnt = 0; // start Data16 = NextChannel; //Data16 = Übrgabewert (zu lesneder Kanal) IOWR(READ_ADC_BASE, 0, Data16); //schreibe zu lesender Kanal Data16 |= START_FLAG; // Data 16 -> Startflag IOWR(READ_ADC_BASE, 0, Data16); // Übertragung starten // wait done while(!bDone && nWaitCnt++ <= nMaxWait){ //Schleife hört auf wenn bDone = true oder nWaitCnt >=nMaxWait Data16 = IORD(READ_ADC_BASE,0); //Data16 = Wert des Kanals bDone = (Data16 & DONE_FLAG)?TRUE:FALSE; //Vergleich Kanal mit Done_Flag } if (bDone) // Wenn Data16 = DONE_FLAG -> Data16 Null schreiben DigitalValue = Data16 & 0xFFF; // 12 bits // stop IOWR(READ_ADC_BASE, 0, 0); //Kanal löschen return DigitalValue; //DigitalValue zurückgeben --- Quote End --- thanks everybody for helping