hi,
ich habe nun den folgenden code in die asuro.c eingefügt:
aufgerufen wird es durch:Code:/*****************ultrasonic********************************/ /** * being used insted TIMER2_OVF_vect during ultrasonic polling */ ISR(TIMER2_COMP_vect) { TCNT2 += 0x25; count36kHz++; if(!count36kHz) timebase++; } /** * initialises the Ultrasonic module * this function is automaticly called by Chirp */ void InitUltrasonics(void) { // Change Oscillator-frequency of Timer 2 // to 40kHz, no toggling of IO-pin: TCCR2 = (1 << WGM21) | (1 << CS20); OCR2 = 100; // 40kHz @8MHz crystal TIMSK |= (1 << OCIE2); // OCIE2: Timer/Counter2 Output Compare Match Interrupt Enable ADCSRA = (0 << ADEN); // deactivate ADC ACSR |= (1 << ACIS1); // Comparator Interrupt on Falling Output Edge ADMUX = 0x03; // connect ADC3-input with comparator SFIOR |= (1 << ACME); // connect ADC multiplexer to comparator DDRD &= ~(1 << 6); // use Port D Pin 6 as input (AIN0) } /** * restores the hardware after using the Ultrasonic module * this function is called automaticly after a Chirp */ void RestoreAsuro(void) { TCCR2 = (1 << WGM20) | (1 << WGM21) | (1 << COM20) | (1 << COM21) | (1 << CS20); OCR2 = 0x91; // duty cycle for 36kHz TIMSK |= (0 << OCIE2); // OCIE2: Timer/Counter2 Output Compare Match Interrupt Enable ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1); // clk/64 ACSR |= (0 << ACIS1); if(autoencode) { EncoderInit(); } Sleep(1); } /** * @return distance in cm */ int Chirp(void) { unsigned int sleeptime = 0, dist = 0; InitUltrasonics(); // chripen: count36kHz = 0; while(count36kHz != 20) { OCR2 = 100 + 20 / 2 - count36kHz; } TCCR2 = (1 << WGM21) | (1 << CS20); OCR2 = 100; // analyse echoes: while(TRUE) { Sleep(1); sleeptime++; if((ACSR & (1 << ACI))) { dist = (unsigned int) ((long) ((344L * ((sleeptime * 1000L) / 72L) / 10000L) / 2L)); ACSR |= (1 << ACI); break; } ACSR |= (1 << ACI); if(sleeptime > 3500) { return -1; } } RestoreAsuro(); return dist; }
das ergebnis beim kompilieren sieht nicht so furchtbar schlecht aus:Code:#include "asuro.h" int main(void) { Init(); { SerWrite("\r\n --- georgs ultrasonic test ---",35); Msleep(1000); StatusLED(OFF); do { Chirp(); SerWrite("\r\n distanz in cm: ",30); Msleep(500); PrintInt(dist); } while(1); } return 0; }
aber trotzdem scheint es irgendwo zu klemmen. Könnte mir jemnad einen tipp geben welche datei denn noch irgendwo fehlt? benutzt habe ich die lib 2.7., habe vorsichtshalber alle parts als sources eingefügt (entfernen kann ich sie nach erfolgreichem kompilieren probeweise ja immer noch...)Code:../ultrasonic.c: In function `main': ../ultrasonic.c:16: warning: implicit declaration of function `Chirp' ../ultrasonic.c:19: error: `dist' undeclared (first use in this function) ../ultrasonic.c:19: error: (Each undeclared identifier is reported only once ../ultrasonic.c:19: error: for each function it appears in.) make: *** [ultrasonic.o] Error 1 Build failed with 3 errors and 1 warnings...
danke...







Zitieren

Lesezeichen