leandroguida
Joined: 09 Dec 2008 Posts: 4
|
Sonar Sensor: How Beep the Buzzer ? |
Posted: Wed Dec 10, 2008 7:56 pm |
|
|
Hi there.
I'm working on a parking sonar sensor. The idea is simple. I send 10-pulse wave (40Khz) to a ultrasonic transducer, wait for my echo for a limited time. If the echo returns on this time, beep a buzzer with a higher interval between the beeps if it's too far, or with a smaller interval between the beeps if it's too near.
Well, my problem now is to beep the buzzer on these intervals. Let me explain why.
First of all. Some important information. My oscillator is 4MHz (So my system clock will be 1MHz, and I have 1uS per cycle, will help me with timer counting). My PIC is a 16F877A.
Here is how my program is organized:
1. Configure the CCP1 (For getting the echo), timer1 (For counting the time), enable interrupts.
2. Inside the while: set the timer to 0, send the wave (it's a function doing output_high/low), wait a little time (to avoid instant echo). enable CCP interrupt on Rise Edge.
3. Wait some time (time enough to receive a 2 meters of distance echo).
4. If I get the echo my CCP1 sets a flag, and I do all calculations.
As you can see, at least I hope you can , following the logic, there's no point in the main function that I can set a Output-High/low to beep the buzzer (starting with a interval of 500 mS).
I thought on doing this by PWM, but I had to do a very very low (kind of 2HZ frequency wave) to beep like I want him to beep.
I thought on doing a compare on match interrupt. But since the compare of CCP2 uses the timer1, and it's setup to use INTERNAL clock (1MHz), I'll overflow on 65535 uS.
Does anyone have an idea how can I do this ?
If it wasn't clear enough, let me know. |
|