hi,
erstmal danke für die antworten...
@tobi
meinst du while(1) - ist es nicht ein notwendiges teil von "do" weiter oben?was soll denn die endlosschleife am ende von entfernung()?
jetzt nichts, eigentlich ist es ja auch später zunächstmal nur ein net aussehneder gag...was bringt umschaun wenn dus eh nicht benutzt?
habe ich mit einem eigenständigem programm, dass so aussah wie "entfernung" - incl. ausgaben im terminal, und wie bereits geschrieben, getestet - die entfernung, wenn ich vor die Sensoren blatt papier halte (bei der hand funktioniert es nicht so gut, weiss nicht warum), auch angezeigt. Allerdings oft mit ausreissern, die nicht zu der tatsächlichen entfernung passen...und dann prüfen ob die 25 abstand passen
@ehenkes - danke für´s angebot zum testen...
inka.h:
inka.c:Code:#ifndef INKA_H_ #define INKA_H_ #endif /*INKA_H_*/ /*********************warten auf start****************************/ void WaitforStart(void); // blink until any switch is pressed, // then wait until switch is released /********************ultrasonic***********************************/ void InitUltrasonics(void); void RestoreAsuro(void); int Chirp(void);
Code:#include "asuro.h" #include "inka.h" /**************************warten auf start*************************/ void WaitforStart(void) // blink until any switch is pressed, { // then wait until switch is released unsigned int t1, t2; unsigned int col=OFF; while (1) // blinking StatusLED until any switch is pressed { t1 = PollSwitch(); t2 = PollSwitch(); if (t1==t2) { if (t1) { break; } else { col ^= GREEN; StatusLED(col); } } Msleep(50); } StatusLED(OFF); // turn off StatusLED and ... BackLED(ON,ON); // ... turn on both BackLED's while (1) // wait until switch is released { t1 = PollSwitch(); t2 = PollSwitch(); if (t1==t2) { if (!t1) { break; } } Msleep(50); } BackLED(OFF,OFF); // turn off BackLED's indication start of race } /*****************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; }gut, dass mit dem init werde ich rausnehmen und noch einmal testen...Was soll eigentlich das Init() in entfernung()?







Zitieren
Lesezeichen