本人做的超声波障碍物探测器,好像很大干扰,请教解决【恢复】
本人参考了一些电路,利用max232升压驱动发声,再用NE5532放大接收,最后用比较器输出电平。MCU用Mega8,内部8M振荡,OC2用CTC模式输出脉冲,ICP1作输入,RS485与电脑通信。MCU控制每秒发出4个40KHz的脉冲,收回的却不止4个。用485发回一看,ICP1中断好几十次,不知何解。发上电路图,与网友共同探讨。http://cache.amobbs.com/bbs_upload782111/files_11/ourdev_530729.jpg
电路原理图(很菜的) (原文件名:sonic-sch.jpg)
http://cache.amobbs.com/bbs_upload782111/files_11/ourdev_530730.gif
接收回来的数据(每秒中断次数) (原文件名:uart_data.gif)
http://cache.amobbs.com/bbs_upload782111/files_11/ourdev_530731.jpg
用CNC雕刻的线路板(示意图,因为电路修改过,某些铜箔已划断) (原文件名:sonic-PCB.jpg) 本来就不只四个,有论文讲了检测要找包络峰点,我用数字示波器看过波,那论文是有道理的,我自己没做检测电路,只是发40K,另外用个收40K,观察回波波形 超声波。。。很有得搞的。。。
注意下几个问题:
1、发射的余震时间的控制
2、两个探头的距离
3、回波接收电路的处理
4、如果要分析问题的所在,最好还是要有示波器,不然这样盲目的调试是不会有什么好的结果的。
一家之言,仅供参考。总之上面的1~3点需要不断的去做调试,才能得到比较理想的效果。 很久以前就想玩这个,楼主有什么成果要共享一下啊!呵呵 好像看了很多人做的接收电路里面有个40KHZ的滤波选波电路吧,也就是只接收发出去的40KHZ的波,而楼主这个好像什么干扰波都收回来了! 为什么会收到这么多?
可能是:
1. 直射波。
2. 余波。 附上代码(用ICC生成的GCC代码):
//ICC-AVR application builder : 2008-12-05 10:45:44
// Target : M8
// Crystal: 8Mhz
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define in_485 PORTC&=~_BV(PC5)
#define out_485 PORTC|=_BV(PC5)
#define led_on PORTD&=~_BV(PD5)
#define led_off PORTD|=_BV(PD5)
volatile char start_recv=0,tc=0,sc=0;
void sonic_send(void)
{
unsigned char pulsecnt;
cli();
PORTB|= (1<<PB3);
TCNT2 = 0x9C; //setup
OCR2 = 0x64;
TCCR2 = 0x19; //start
for (pulsecnt=0;pulsecnt<4;pulsecnt++)
{
while (PINB&(1<<PB3)); //1
while (!(PINB&(1<<PB3))); //0
}
TCCR2 = 0x00; //stop
PORTB|= (1<<PB3);
start_recv=1;
sc=0;
tc=0;
TIMSK|=_BV(TICIE1);
sei();
}
void port_init(void)
{
PORTB = 0xFF;
DDRB = _BV(DDB3);
PORTC = ~_BV(PC5); //m103 output only
DDRC = _BV(DDC5);
PORTD = 0xFF;
DDRD = _BV(DDD1)|_BV(DDD5);
}
//TIMER1 initialize - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1KHz
// actual value: 1.000KHz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xE0; //setup
TCNT1L = 0xC0;
OCR1AH = 0x1F;
OCR1AL = 0x40;
OCR1BH = 0x1F;
OCR1BL = 0x40;
ICR1H = 0x1F;
ICR1L = 0x40;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
SIGNAL(SIG_INPUT_CAPTURE1)
{
//timer 1 input capture event, read (int)value in ICR1 using;
// value=ICR1L; //Read low byte first (important)
// value|=(int)ICR1H << 8; //Read high byte and shift into top byte
volatile unsigned int sd=ICR1L;
sd|=(unsigned int)(ICR1H<<8);
sc++;
if(tc>40)
{
TIMSK&=~_BV(TICIE1);
start_recv=0;
if(sc<=4)led_on;
out_485;
UDR=(unsigned char)(sc>>8);
while(!(UCSRA&(1<<UDRE)));
_delay_ms(1);
out_485;
UDR=(unsigned char)(sc&0x00FF);
sc=0;
tc=0;
}
}
SIGNAL(SIG_OVERFLOW1)
{
//TIMER1 has overflowed
if(start_recv)tc++; //接收开始后tc累加,当tc=122时,经过了1秒
}
//TIMER2 initialize - prescale:1
// WGM: CTC
// desired value: 80KHz
// actual value: 79.208KHz (1.0%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT2 = 0x9C; //setup
OCR2 = 0x64;
TCCR2 = 0x00; //stop
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = (1<<URSEL) | 0x06;
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0xD8;
}
SIGNAL(SIG_UART_RECV)
{
//uart has received a character in UDR
volatile unsigned char c = UDR;
}
SIGNAL(SIG_UART_TRANS)
{
//character has been transmitted
in_485;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
cli(); //disable all interrupts
port_init();
timer1_init();
timer2_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x24; //timer interrupt sources
sei(); //re-enable interrupts
//all peripherals are now initialized
}
int main(void)
{
init_devices();
while(1)
{
sonic_send();
while((start_recv==1)&&(tc<50));
TIMSK&=~_BV(TICIE1);
start_recv=0;
_delay_ms(1000);
led_off;
}
} EZYH 发表于 2008-12-6 09:55 static/image/common/back.gif
附上代码(用ICC生成的GCC代码):
//ICC-AVR application builder : 2008-12-05  ...
不知道楼主最后怎么解决的,最近想搞这块
页:
[1]