 |
oSpeaker Object
|
|
|
Description: |
| | A Hardware Object that generates and outputs a tone of up to 9.7khz to a speaker.It is capable of generating a frequency output between 38Hz and 9,765Hz. |
| | The following table lists the size and availability of the oSpeaker Object.
| | Object | Size | Description | A1 | A2 | B1 | B2 | C1 |
 | oSpeaker | 2 Bytes | Controls a Speaker. | x | x |
|
Operation: |
| | When the Operate property is 1, the oSpeaker Object cycles I/O line 21 at a rate specified by the Tone property thereby producing a tone output that can drive a speaker. The Tone property specifies the frequency of the tone. The specified frequency is expressed as a 16-Bit divisor to a fixed frequency of 2.5 MHz. The valid range of the divisor is 1 to 65279. The higher the value, the higher the frequency. If 0 is given as the divisor, then the output is shut off. The maximum usable value for the divisor is 65279 and if the divisor is between 65280 and 65536 then the divisor is read as (divisor - 65279). The value to use as a divisor for the desired frequency can be calculated with the following formula. Divisor = 65,535 - (2,500,000 / Frequency) For example: The frequency to product the musical note E5 is 659.26Hz. To produce the frequency 659.26Hz the divisor 61743 is specified as show in the following example: 65,535 - (2,500,000 / 659.26) = ~61742.87 which would be rounded to 61743 The lowest frequency that can be generated is 38.1481Hz [(65,535 - (2,500,000 / 38.1481)) = 1] The highest frequency that can be generated is 9,765.625 [(65,535 - (2,500,000 / 9,765.625)) = 65279] The oSpeaker Object generates one frequency. Note that two oSpeaker Objects will not produce two independent frequencies. if you need two or more independent frequencies or need music capabilities, see the oSoundgin object. The Freq property is an instance of the oFreqH object which the oSpeaker Object uses to generate a square wave output to drive the speaker. Since all instances of the oFreqH Object use the same PIC hardware then all instances of the oSpeaker Object will output at the same frequency. Also note that all other objects that use the oFreqH object will also use the same 16-Bit value as well. (see oFreqH Object for more detail) |
Properties: |
| The following table lists the properties of the oSpeaker Object:
|
Methods: |
| | The following table lists the Methods of the oSpeaker Object:
| Methods | Description |
| Beep(x,y,z) | Puts x into the Tone property, sets Operate to 1, does a delay of y milliseconds, then sets Operate to 0 and does a delay of z milliseconds. If no value is specified a default value of 62346 (Musical Note G5 / 783.9Hz) is used. y has a range of 65.536 seconds and a default of 250 (1/4 second). z has a range of 65.536 seconds and a default of 0. |
|
Examples: |
| In the following example, the oSpeaker Object is told to beep.
| Visual Basic Syntax | C and Java Syntax |
'This program uses an oSpeaker
'with the Beep method.
Dim Spk As New oSpeaker
Sub Main()
Do
Spk.Beep(64000,100)
Spk.Beep(64500,100)
Spk.Beep(65000,100)
Spk.Beep(63500,50)
Spk.Beep(63600,50)
Spk.Beep(0,100)
Spk.Beep(5500,100)
Spk.Beep(0,100)
Spk.Beep(20500,100)
Spk.Beep(0,100)
Spk.Beep(5500,100)
Spk.Beep(0,100)
Loop
End Sub | // This program uses an oSpeaker
// with the Beep method.
oSpeaker Spk = New oSpeaker;
Void Main(Void){
Do{
Spk.Beep(64000,100);
Spk.Beep(64500,100);
Spk.Beep(65000,100);
Spk.Beep(63500,50);
Spk.Beep(63600,50);
Spk.Beep(0,100);
Spk.Beep(5500,100);
Spk.Beep(0,100);
Spk.Beep(20500,100);
Spk.Beep(0,100);
Spk.Beep(5500,100);
Spk.Beep(0,100);
} While (1);
} |
| Basic Syntax | |
'This program uses an oSpeaker
'with the Beep method.
Spk As oSpeaker
Do
Spk.Beep(64000,100)
Spk.Beep(64500,100)
Spk.Beep(65000,100)
Spk.Beep(63500,50)
Spk.Beep(63600,50)
Spk.Beep(0,100)
Spk.Beep(5500,100)
Spk.Beep(0,100)
Spk.Beep(20500,100)
Spk.Beep(0,100)
Spk.Beep(5500,100)
Spk.Beep(0,100)
Loop | |
|
Connections: |
| | The oSpeaker Object uses I/O line 21. The output of the I/O line needs to be filtered before it can be connected to a speaker. A simple filter can be constructed with two resistors and two capacitors as shown in the wiring diagram. Caution: Do NOT connect the outputs of the ooPIC directly to a speaker. The TTL circuitry of the ooPIC is not designed to drive the power requirements of a speaker. Doing so can potentially damage the ooPIC's TTL outputs. 
In addition, if volume control is needed, an amplified circuit can be used. The LM386 is a commonly used operational amplifier. Shown in the following schematic, it is used to amplify the audio signal after it has gone through the filter circuit. 
|
Related Items:
|
| | The following table lists objects with related functions
| | Object | Description | A1 | A2 | B1 | B2 | C1 |
 | oSoundgin | Controls a Soundgin Sound Effects Engine / Voice Synthesizer chip. | x | x | x |
 | oTone | Outputs a tone. | x | x | x |
|
Version History and Bug List: |
| | Firmware Ver B2: Introduced. Bugs: No known bugs. |
|