2018-01-02 13:46:54 +02:00
|
|
|
#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
|
|
|
|
|
2018-01-17 21:56:48 +02:00
|
|
|
#define SPEED_OF_SOUND 343 // 20°C dry air (m/s)
|
2018-01-02 13:46:54 +02:00
|
|
|
#define MAX_SONAR_RANGE 8 // Trigger + echo (m)
|
2018-01-22 21:23:27 +02:00
|
|
|
#define MIN_SONAR_RANGE 3 // Minimum distance that is still reliable
|
2018-01-17 21:56:48 +02:00
|
|
|
#define SONAR_DELAY 60 // Timeout for return signal
|
2018-01-02 19:32:11 +02:00
|
|
|
#define TIMER_MAX 65535 // For 16-bit timer
|
2018-01-17 21:56:48 +02:00
|
|
|
#define CYCLES_PER_US (F_CPU / 1000000)
|
|
|
|
#define SONAR_TIMEOUT (F_CPU * MAX_SONAR_RANGE) / SPEED_OF_SOUND
|
2018-01-02 13:46:54 +02:00
|
|
|
|
2018-01-22 21:23:27 +02:00
|
|
|
#define ECHO_TIMEOUT -1
|
2018-01-02 13:46:54 +02:00
|
|
|
|
|
|
|
void init_sonar(void);
|
2018-01-22 21:23:27 +02:00
|
|
|
int32_t read_sonar(void);
|
2018-01-02 13:46:54 +02:00
|
|
|
|
|
|
|
#endif /* SONAR_H */
|