1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Hi All

    what I am trying to do is when button is pressed, we get some pleasant door bell sound in the speaker...sound should last up to 10 second...

    No use of PWM! input = push button, output on one I/O pin = sound

    some example below:

    http://www.youtube.com/watch?v=ROsymjaJ3OY

    http://www.youtube.com/watch?v=DXBCwpSl7-A

    Any idea how to proceed? I mean how to get it sound like the one in the link...well it can be different...

    thanks!
     
  2. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    What are you using to play the sound? Are you planning on using that audio clip, or making something that sounds like it? If you want to make your own doorbell sound from scratch, you'll need PWM in one form or another. They might make doorbell modules that you can buy and connect your own switches to.
     
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You don't really need PWM. In the early PIC days people would make tunes by toggling an output pin at the "note" frequency, it's really not that hard to play a little tune.

    You can also take off the harsh sounding square wave edge by running the sound through an RC filter or a couple of RC filters before the amp.
     
  4. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    That'll get you the right "notes", but not the right "tone". In order to get a better tone, you'd need PWM.

    How much does this have to sound like a doorbell? Can you just have a two-tone sound (high then low)?
     
  5. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    A few years ago, there was a guy who invented an interesting way of playing sound from a PIC, but I forget exactly who it was. It had something to do with predicting the time constant of an RC filter. Maybe someone else remembers.
     
  6. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Nothing much...just a PIC16F, push button and , circuit attached for speaker! Guess so! will have to use PWM...dont have to use anything else...I will try to write a quick code later...as I am preparing for an exam now...I will choose 2 arbitrary frequencies in order to have 2 different tone but I was hoping to make an identifiable doorbell sound as one of those in the above link...but don't kow the correct frequencies to choose...anyway..

    Yeah I can produce a square wave by toggling a pin but will probably produce some strange sound
    unless doing some math...

    Yeah PWM is needed...that what I am planning to do just two tone...
    ding dong king of sound...but sound must last at least 5 seconds

    Anyway will try something

    Thanks all!
     
  7. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    If you're just doing the two-tone thing you probably don't need PWM. The PWM would be used to add a little "twang" to make it sound more realistic and to smooth off the edges, but you can get a regular two-tone 'beep boop" without it.
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It was an Elector magazine article named "Polyphonic Doorbell" This article resulted in a lot of "offsprings" Just google doorbell pic16f84
     
  9. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I decided to use PWM...it a two tones sound...so it not a lot of work...

    But I was wondering...for a nice effect...what delay should i use...I mean 0.5/1/... second between the two?

    ding
    call delay
    dong
    call delay

    the above is going to be played twice on every button press...so it gong sound like this:

    ding
    dong

    ding
    dong

    lol:D
     
  10. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I am trying to create 2 delays..

    one of 33ms for push button deboucing and another one of 1 second for the duration of each tone...

    Hope it makes sense! check the attachment!

    thanks!
     
    Last edited: Sep 30, 2012
  11. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    That looks like it might work, don't forget to use "movlw d'245' " etc unless you have set the radix to decimal.
    Add in a little test code in your main loop to toggle pins every time the flags are set and you will be able to see if it works.
     
    Eric007 likes this.
  12. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Attached is the full code...

    Hope it makes sense ...haven't tested it yet...

    twotones is called twice in main:

    ding
    dong

    ding
    dong

    so I can the above effect...each tone last for 1 secand...I have coded it the old way...i don't really like it coz at each delay or getkey...I am stuck in a *ugly* loop...t as there's nothing much going on + I don't have time to write a better code...

    doing breadboard now so i can test it...

    Thanks!

    [I will remove the code later] when everything ok!
     
  13. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    a quick stupid question...in my circuit attachement , which polarity (+ or -) of the capacitor goes to 'output'

    I forgot...:rolleyes:
     
  14. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    The other end of the speaker is presumably connected to Vss so will be lower than anything else.
     
  15. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    the speaker has '+' and '-'

    '-' will go to ground and '+' will go to one end of the cap (which on? + or -?)

    the othe end of cap is connected to the two transistor...
     
  16. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I think my code is WRONG!!!!:(

    I tried an old code project on the same circuit and ot worked...

    wiring is not a problem...

    Any help in my logic?? I know it sometimes hard to read some one else code...
     
  17. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    I never got much into ASM personally, but looking at your config settings I see

    &_INTRC_OSC_NOCLKOUT

    Isn't the & supposed to be separate? "& _INTRC_OSC_NOCLKOUT"
     
  18. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I checked and fixed that but still nothing...I am working on it...I got to be quick fixing it I got a big exam in two days time! #not good#
     
  19. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    - end of capacitor to speaker then Vss, + end of capacitor to the transistors, which can never be lower than Vss but sometimes are higher.
    You've got MCLR on, have you connected it to Vdd?
     
    Eric007 likes this.
  20. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I think I have found out the bug!

    I don't see where I have enabled global interrupt and timer0 interrupt!;)

    Hope it works when i fix that