Turn OFF Sound command


Closed Thread
Results 1 to 6 of 6
  1. #1
    Gator_sound's Avatar
    Gator_sound Guest

    Unhappy Turn OFF Sound command

    Hi all,

    I am wondering how its possible to turn off the sound command using 18LF1320. I am creating an alarm clock and I am using the sound command to generate the alarm. I've tried to make the pin connected to the piezo low, i.e. PortB.0 = 0 but no luck. Any ideas? Thanks for the helps in advance. I tried looking through the forums for this topic but no luck.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Are you saying that, you use SOUND command to drive your piezzo and it works.
    Then it continues sounding but you can not stop it?

    If this is the case, post your sound command here.


    -------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Gator_sound's Avatar
    Gator_sound Guest


    Did you find this post helpful? Yes | No

    Default

    Sayzer,

    I have the code where it goes on for a certain amount and off for half a second but I would like to press a button and the entire sound command turns off, like a regular alarm clock. Relating to the alarm clock the buzzer would go on until you press a button, once you press the buzzer will stop sounding. the following is my code:

    INCLUDE "MODEDEFS.BAS"
    DEFINE OSC 4

    OSCCON = %01100110
    ADCON1 = %11111111 'PINS TO DIGITAL OUTPUTS

    INPUT PORTB.2 'START BUTTON
    INPUT PORTB.4 'STOP BUTTON
    OUTPUT PORTB.0 'LED
    OUTPUT PORTB.1 'PIEZO

    PORTB.1 = 0
    PORTB.0 = 0

    CONT_SOUND:
    IF PORTB.2 == 0 THEN 'turns the alarm on
    CONTINUESOUND:
    Sound PORTB.1, [1,255] 'Sound command
    GoSub CHECKING_STOP
    ENDIF

    GoTo CONTINUESOUND

    CHECKING_STOP:
    IF PORTA.4 == 0 Then
    Toggle PORTB.0 'LED indication that it has made it to the loop
    PORTB.1 = 0
    EndIF

    Return

    STOP_BUZZER:
    PORTB.1 = 0
    TOGGLE PORTB.0
    GoTo CONT_SOUND
    End

  4. #4
    Gator_sound's Avatar
    Gator_sound Guest


    Did you find this post helpful? Yes | No

    Talking

    Sayzer,

    I got it to stop going off. I just put the frequency to 0.

    For example, SOUND PORTB.1, [0,5]

    Than go where ever I need to go. Thanks Sayzer for inquiring about my problem. Feel bad I didn't figure it out in the first place.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    I am not sure how your code is designed to work; may be you just added an example to show the idea here.

    I modified your code a little bit as below. May be it is similar to what you need.

    Code:
    INCLUDE "MODEDEFS.BAS"
    
    OSCCON = %01100110  'Set for 4Mhz, but need to check the rest!
    TRISA =  %00000000  'All outputs.
    TRISB =  %00010100
    'PORTB.2 'START BUTTON
    'PORTB.4 'STOP BUTTON
    'PORTB.0 'LED
    'PORTB.1 'PIEZZO
    
    ADCON1 = %11111111   'All digital
    
    
    '===========Variables & Hardware assignment=============
    ALM_Flag  var bit     'Alarm status
    LED       VAR PORTB.0 'Pin for LED
    PIEZZO    var PORTB.1 'Pin for Piezzo
    Start_BTN VAR PORTB.2 'Pin for Start Button
    Stop_BTN  VAR PORTB.4 'Pin for Stop Button
    
    
    '==========Initial Settings=============================
    low LED
    LOW PIEZZO
    ALM_Flag = 0
    
    
    Start:
    
       IF Start_BTN = 0 THEN 
          WHILE Start_BTN = 0 : WEND   'Wait for finger release!
          ALM_Flag = 1                 'Turns the alarm flag ON once.
       ENDIF
    
    
       IF Stop_BTN = 0 Then 
          WHILE Stop_BTN = 0 : WEND   'Wait for finger release!
             ALM_Flag = 0             'Turns the alarm flag OFF once.
       ENDIF
       
       IF ALM_Flag = 1 then 
          Sound PIEZZO, [1,255] 'Run Sound Command
          'Depending on the piezzo type you have, you can just use HIGH and LOW commands.
          'Example: HIGH PIEZZO  'This will run the piezzo until you LOW the Piezzo pin.
          HIGH LED              'LED indicates that Alarm is ON. Or do you want this to Flash?
       else
          LOW PIEZZO    'Stop sounding.
          LOW  LED      'Alarm is OFF.
       ENDIF 
       
    GoTo Start
    
    
    End


    There are couple of things to pay attention.

    1. Exactly when do you need to TOGGLE the LED?

    2. Are buttons pressed by a user? If yes, "WHILE" will help you to wait for finger release. Check the example.

    3. Check your piezzo type. You may just use HIGH and LOW commands to drive it. Thus, couple of lines will be good enough for your code.

    -----------------------
    Last edited by sayzer; - 19th November 2006 at 08:45.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Gator_sound's Avatar
    Gator_sound Guest


    Did you find this post helpful? Yes | No

    Smile

    sayzer,

    The LEDs are there to indicate that the code went into the sub routine or through the loop. I tried driving the piezo though with the high and low command but it did nothing. Its why I resorted to asking the forum. I think I'll use the while statement though. I was just testing out the different components of my project with respect to their code. I'm doing an alarm clock with some RF technology integrated. I used LEDs to check if they my code was working properly as a way of debugging. I understand its not the most efficient way of doing things but it worked well with small parts of my code.

    Thanks for taking the time to revise and update my code. I'll look more into it some more in a bit. I appreciate it.

Similar Threads

  1. Help w/ speaker for 16F690 and SOUND command
    By bhiggenson in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 22nd March 2009, 18:55
  2. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  5. Re: quick fix for sound command?
    By Melanie in forum Code Examples
    Replies: 0
    Last Post: - 9th July 2004, 01:44

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts