inspektors/robot/include/sonar.h

32 lines
709 B
C
Raw Normal View History

#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)
#define MAX_SONAR_RANGE 8 // Trigger + echo (m)
2018-01-17 21:56:48 +02:00
#define SONAR_DELAY 60 // Timeout for return signal
#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-17 21:56:48 +02:00
#define SONAR_ERROR 0
void init_sonar(void);
2018-01-17 21:56:48 +02:00
uint16_t read_sonar(void);
#endif /* SONAR_H */