oTone Object

Main Index
Object List
Back to top of page Description:
 The oTone Object is a Hardware Object that generates and outputs a low frequency tone.

It is capable of generating a frequency output between 8.9Hz and 1,132Hz.

 The following table lists the size and availability of the oTone Object.
 ObjectSizeDescriptionA1A2B1B2C1
oTone5 BytesAn Object that outputs a tone.xxx
Back to top of page Operation:
 

When the Operate property is 1, the oTone Object cycles the I/O line specified by the IOLine property 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 frequency is derived from a 1,132kHz clock divided by 128 minus the value of the Tone property. [1132/(128-Value)]  For example, a value of 120 will produce a 141.5Hz Tone. [(1132/(128-120)) = 141.5]  If 0 is given as the Tone, then the output is shut off.  This is useful for some rudimentary low frequency tones.  If you need a higher frequency, see the oSpeaker object.  if you want music, see the oSoundgin object. 

The lowest frequency that can be generated is 8.913Hz  [(1132/(128-1)) = 8.913]
The highest frequency that can be generated is 1132Hz  [(1132/(128-127)) = 1132]

Note that the frequencies are not linear.  This will be most noticeable at the higher frequencies. 
(1132/1=1132Hz, 1132/2=566hz). 

Two or more oTone Objects can be set to use the same I/O line.  When this is done, the cycles of the multiple tones are combined.

The oTone Object's output shares its timing with the rest of the ooPIC's multitasking objects.  A large number of Objects running concurrently with the oTone Object can result in distortions on the higher frequency tones.

The Freq property is an instance of the oFreqL Object which is created when the oTone object is.  The oTone Object uses the oFreqL Object to create the actual tone output.  Attributes of the tone can be adjusted by directly manipulating the oFreqL Object.  (see oFreqL Object for more detail)

Back to top of page Properties:

The following table lists the properties of the oTone Object:

Property

Description

Tone
A value that specifies the tone to output.
Object Class: oByte Value Range: 0 - 127 (MSB of byte not used)
Data Type: Numeric Default Value: 0
Determines the tone using the following formula: frequency = 1132/(128-Divisor)
OperateDescription
0The tone is disabled.
1The tone is generated at 8.913Hz.
2The tone is generated at 8.984Hz.
3-125The tone is generated at the specified frequency.
126The tone is generated at 566Hz.
127The tone is generated at 1132Hz.
IOLine
A value that specifies which I/O Line to use to output the tone.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
Operate
A value that selects whether or not the tone is outputted.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe tone is not generated.
1cvOnThe tone is generated.
Freq
The I/O function object used to output the tone.
Object Class: oFreqL Value Range: 0 - 127
Data Type: Numeric Default Value: 0
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of page Examples:
In the following example, the oTone Object is used.
Visual Basic SyntaxC and Java Syntax
' Produce an alarm every 
'  two seconds.

Dim T As New oTone

Sub Main()
  T.IOLine = 21
  Do
    Call Alarm
    ooPIC.Delay = 2000
  Loop
End Sub

Sub Alarm()
  T.Operate = 1    
  Do 5 Times
    T.Value = 120
    ooPIC.Delay = 30
    T.Value = 117
    ooPIC.Delay = 30
  Loop
  T.Operate = 0
End Sub
// Produce an alarm every
// two seconds.

oTone T = New oTone;

Void Main(Void){
  T.IOLine = 21;
  Do{
Call    Alarm;
    ooPIC.Delay = 2000;
  } While (1);
}

Void Alarm(Void){ Byte x = 0;
  T.Operate = 1;
  Do{ x++
    T.Value = 120;
    ooPIC.Delay = 30;
    T.Value = 117;
    ooPIC.Delay = 30;
  } While (x<5);
  T.Operate = 0;
}
Basic Syntax 
' Produce an alarm every 
'  two seconds.

Dim T As New oTone(21)

Do
  Call Alarm
  Delay = 2000
Loop

Sub Alarm()
  T.Operate.TurnOn
  Do 5 Times
    T.Value = 120
    ooPIC.Delay = 30
    T.Value = 117
    ooPIC.Delay = 30
  Loop
  T.Operate.TurnOff
End Sub
 
  
' Combine 2 tones

Dim T As New oTone
Dim G As New oTone

Sub Main()
  T.IOLine = 21
  T.Value = 113
  T.Operate = 1
  G.IOLine = 21
  G.Value = 127
  G.Operate = 1
  Do 
    ooPIC.Delay = 150
    G.Operate = 0
    ooPIC.Delay = 150
    G.Operate = 1
    G = G - 1
  Loop
End Sub
Back to top of pageConnections:
 The oTone Object uses the single I/O line specified by the IOLine property.  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.  Note that I/O lines 16 through 23 are used for special purposes.  Be sure not to specify any of these I/O lines if these special functions are in use.

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.

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.

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oClockProvides a programmable logic clockxxx
oSoundginControls a Soundgin Sound Effects Engine / Voice Synthesizer chip.xxx
oSpeakerControls a Speaker.xx
Back to top of page Version History and Bug List:
 Firmware Ver B1: Introduced.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.