inspektors/robot/include/sonar.h
2018-01-23 23:23:33 +02:00

32 lines
779 B
C

#ifndef SONAR_H
#define SONAR_H
#include "common.h"
// Trigger
#define TRIG_DDR DDRC
#define TRIG_PORT PORTC
#define TRIG_PIN PINC
#define TRIG_BIT PC4
// Echo
#define ECHO_DDR DDRC
#define ECHO_PORT PORTC
#define ECHO_PIN PINC
#define ECHO_BIT PC5
#define SPEED_OF_SOUND 343 // 20°C dry air (m/s)
#define MAX_SONAR_RANGE 8 // Trigger + echo (m)
#define MIN_SONAR_RANGE 4 // Minimum distance that is still reliable
#define SONAR_DELAY 60 // Timeout for return signal
#define TIMER_MAX 255 // For 8-bit timer
#define CYCLES_PER_US (F_CPU / 1000000)
#define SONAR_TIMEOUT (F_CPU * MAX_SONAR_RANGE) / SPEED_OF_SOUND
#define ECHO_TIMEOUT -1
void init_sonar(void);
int32_t read_sonar(void);
#endif /* SONAR_H */