Help w/ speaker for 16F690 and SOUND command


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2009
    Posts
    6

    Default Help w/ speaker for 16F690 and SOUND command

    I'm just trying to test the SOUND command with a 16F690. Unfortunately, I'm not getting any sound, but I'm pretty sure it's not on the sofware side of things, but the hardware side. The PICBASIC compiler manual shows a capacitor in series with a speaker. I input an alternating tone with the sound command where it should alternate tone/silence/tone/silence and I hear a faint "clicking" sound so I think it's trying to work.

    Does anyone have experience with more specifics as to the speaker/capacitor arrangement that would work.

    I also tried to directly drive a piezo element I had in an old parts bin, but that didn't work either.

    TIA

    Brad

  2. #2
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Have you connected the polarity of the speaker correctly?
    What do you see on that pin using oscilloscope?
    Make sure you have disable analog pin and chg it to digital output (if applicable).

  3. #3
    Join Date
    Feb 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Good thoughts, but speaker is connected correctly. Pin is outputting. I can see activity on an LED, but I don't have a scope to be able to verify that the output is oscillating at some frequency. My old HP scope died a couple years ago and I never had a need to replace it.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    It will not work without the capacitor. The book says and I concur 10µf.
    Last edited by Archangel; - 14th March 2009 at 04:43.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Code:
    sound portB.6, [120,20]
    keep first number below 125, second number is duration. If you are using the Microchip low pin count demo board, be advised the black plastic header does not necessarily go to the pins they appear to.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Feb 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    I removed the sound command from my main program just so I could focus on that. The only line of code I have now is:

    sound portc.0, [100,100]

    the LED tied to portc.0 lights up, but all I get is an initial click from the speaker. I've tried 6-10 different capacitors and that doesn't help either.

    Anyone have any other thoughts? I've tried changing the tone from 1 to 127 and no change. When I use one of the "white noise" tones, say 157, then I do see the LED flicker and the speaker crackles with the LED flicker.

    I wish I had a scope, but I don't.

    Any other thoughts?

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    PORTC.0 is also an analog port with comparator and ADC. Is the port configured correctly to be a digital output?
    I know the sound command *says* it automatically makes it an output, but....?

    Have you tried the speaker on a different port? maybe yer PIC is busted.

    Any chance you have the PIC's oscillator set to the wrong frequency and it's outputting your sound at some super high "only dogs can hear it" frequency?

    Have you tried a really low note setting like 10 or 20?

    That's all that comes to mind now.


    steve

  8. #8
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Oh, and what's your power supply?

    A speaker is a pretty low impedance load. Any chance that when the speaker turns on it drags your supply voltage down to unhappy levels?

  9. #9
    Join Date
    Feb 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    I downloaded an application that uses the sound card and provides AC osciliscope capabilities (no DC). With no speaker (load) attached I see a spike when the sound starts and a matching inverted spike when the sound stops and since I don't think it does DC I expect it's shifting to a TTL high during this period. There is no detectable waveform present. When I switched back to the note 157 (white noise) I DO see a square wave form that is random in nature. Still no clue here why it's not producing any noise for the 1-128 notes.

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    From the Data sheet: ANSEL and ANSELH must be configured to use port C as I/O.
    Code:
    ;@MyConfig =  
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF 
    @ __config  MyConfig 
    
    DEFINE OSC 4
    PortA = 0
    PortB = 0
    PortC = 0
    TRISA = 1
    TRISB = 0
    TRISC = 0
    i var byte
    ANSEL = 0
    ANSELH = 0
    CM1CON0 = 0
    CM2CON0 = 0
    main:
    
    portc = 0
    pause 500
    
    for i = 1 to 15; step -1
    
    
    portC = i
    i=i  << 1 
    pause 250
    next i
    sound portB.6, [120,2,124,2,123,2,121,2]
    sound portC.6, [120,2,124,2,123,2,121,2]
    goto main
    end
    Without them sound works on PortB but not PortC, the code snippet above is configured to use the MicroChip low parts count demo board.
    Last edited by Archangel; - 21st March 2009 at 02:08.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    From the Data sheet: ANSEL and ANSELH must be configured to use port C as I/O.
    Uh huh... that would've been my first guess.

  12. #12
    Join Date
    Feb 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default It works!

    Thanks very much for the help. I didn't have ANSELH and that was the missing link. Very much appreciated!

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    You are welcome, with appropriate credit to byte_butcher for his comment in post 7, providing me the clue. Very happy it works for you, and for what I learned helping.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  14. #14
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    In my brief (almost 3 months now!) exposure to PIC's, one of the most important things I've learned is that if a port doesn't act the way I expect, the first thing to look for is whether or not I've got all the appropriate registers set to make sure my pin is digital or analog, input or output, etc.

    I've been tripped up by that one too many times already!

    Glad I could help be part of the solution for once.

Similar Threads

  1. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  2. Replies: 4
    Last Post: - 10th November 2006, 07:37
  3. SOUND command not working
    By RUBiksCUbe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th December 2005, 22:41
  4. question about SOUND command
    By bartman in forum General
    Replies: 7
    Last Post: - 1st December 2005, 13:50
  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