PDA

View Full Version : Help w/ speaker for 16F690 and SOUND command



bhiggenson
- 14th March 2009, 01:19
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

Pic2008
- 14th March 2009, 01:50
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).

bhiggenson
- 14th March 2009, 01:55
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.

Archangel
- 14th March 2009, 04:41
It will not work without the capacitor. The book says and I concur 10µf.

Archangel
- 15th March 2009, 20:54
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.

bhiggenson
- 20th March 2009, 18:57
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?

Byte_Butcher
- 20th March 2009, 19:37
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

Byte_Butcher
- 20th March 2009, 19:40
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?

bhiggenson
- 20th March 2009, 22:17
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.

Archangel
- 21st March 2009, 02:06
From the Data sheet: ANSEL and ANSELH must be configured to use port C as I/O.


;@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.

Byte_Butcher
- 21st March 2009, 02:13
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.

bhiggenson
- 22nd March 2009, 14:14
Thanks very much for the help. I didn't have ANSELH and that was the missing link. Very much appreciated!

Archangel
- 22nd March 2009, 16:59
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.

Byte_Butcher
- 22nd March 2009, 18:55
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! :o

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