CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sonar Sensor: How Beep the Buzzer ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
leandroguida



Joined: 09 Dec 2008
Posts: 4

View user's profile Send private message

Sonar Sensor: How Beep the Buzzer ?
PostPosted: Wed Dec 10, 2008 7:56 pm     Reply with quote

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 Very Happy , 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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 10, 2008 10:21 pm     Reply with quote

Software PWM:
http://www.ccsinfo.com/forum/viewtopic.php?t=35160
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group