oFreqH Object

Main Index
Object List
Back to top of pageDescription:
 A Hardware Object that generates and outputs a high frequency square wave.

The following table lists the size and availability of the oFreqH Object and its variations
 ObjectSizeDescriptionA1A2B1B2C1
oFreqH 2 BytesGenerates and outputs a high frequency square wave.xx

Back to top of pageOperation:

 When the Operate property is 1, the oFreqH Object cycles I/O line 21 at a rate specified by the Rate property.

The Rate property is a clock divider value that specifies the frequency.  The frequency generated is expressed as a 16-Bit divisor to a fixed frequency of 2.5 MHz.  [Frequency = (2,500,000 / (65,535 - Rate))] The valid range for Rate is 1 to 65279.  If 0 is given as the divider, then the output is shut off, if the divisor is 65280 or above then the divisor is read as (Rate - 65279).

The Rate can be calculated for the desired frequency using the following formula: Rate = 65,535 - (2,500,000 / Frequency)
For example: The frequency to product the musical note E5 is 659.26Hz. 
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  [38.1481 = (2,500,000/65,535-1)]
The highest frequency that can be generated is 9,765.625Hz  [9,765.625 = (2,500,000/65,535-65279)]

The oFreqH Object generates and outputs only one frequency.  Note that two oFreqH Objects will not produce two independent frequencies.   if you need two or more independent frequencies or need music capabilities, see the oSoundgin object.

The Timer property is an instance of the oTimer object which the oFreqH Object uses to maintain the timing for the output.  The oFreqH Object configures Timer's properties so that it will count at a 2.5 MHz rate using a 16-Bit value.  Since all instances of the oTimer Object use the same PIC hardware then all instances of the oFreqH Objects will use the same 16-Bit value.  (see oTimer Object for more detail)  Also note that all other objects that use the oTimer object will also use the same 16-Bit value as well.  For instance, The oCounter2h Object uses an instance of the oTimer object.

*It should be noted that the Timer property (which is an oTimer Object) has a prescale property that allows the 2.5 MHz clock to be divided thereby allowing for lower frequencies to be produced.  For example, setting the PreScale to 3 with the following code, X.Timer.PreScale = 3, will cause the timer's input clock to be divided by 8 and thus a Rate of 1 will produce a frequency of 4.77Hz.

Back to top of pageProperties:

The following table lists the properties of the oFreqH Object:

Property

Description

Rate
A value that specifies a 16-Bit divisor to a fixed frequency of 2.5 MHz.
Object Class: oWord Value Range: 0 - 65535
Data Type: Numeric Default Value: 0
Determines the frequency using the following formula: Frequency = (2,500,000 / (65,535 - Rate))
ValueDescription
0The frequency output is disabled.
1The frequency 38Hz is generated.
2 - 65278The frequency (2,500,000 / (65535 -Rate )) is generated.
65279The frequency 9,765Hz is generated.
65280 - 65536The frequency (2,500,000 / Rate) is generated.
IOLineO
I/O Line 21 used to output the high frequency square wave.
Object Class: oIOLine Value Range: 21
Data Type: Numeric (Read-Only) Default Value: 21
Operate
A value that selects whether or not the frequency is generated.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOffThe frequency is disabled.
1cvOnThe frequency is generated and outputted.
Timer
The PIC Hardware object used to generate the output frequency.
Object Class: oTimer Value Range: 65535
Data Type: Numeric Default Value: 0
Note: Timer is an instance of the oTimer object.  All instances of the oTimer object use the same PIC hardware, Therefore all instances of the oCounter2H objects will read the same 16-Bit value.  Also note that setting its properties can affect the way the oCounter2H operates.
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 pageExample:

 In the following example, the oFreqH Object is used to generate sweeping tones.
Visual Basic SyntaxC and Java Syntax
'This program uses an oFreq
'with the Beep method in a loop

Dim Frq As New oFreqH 
Dim X As New oWord

Sub Main()
  Do
    For X = 55000 To 65000 Step 400
      Frq.Beep(X,20)
    Next X
  Loop
End Sub
// This program uses an oFreq
// with the Beep method in a Loop

oFreqH Frq = New oFreqH;
oWord X = New oWord;

Void Main(Void){
  Do{
    For (X = 55000; X < 65000; X=X+400){
      Frq.Beep(X,20)
    }
  } While (1);
}
Basic Syntax 
'This program uses an oFreq
'with the Beep method in a loop

Frq As oFreqH 
X As oWord

Do
  For X = 55000 To 65000 Step 400
    Frq.Beep(X,20)
  Next X
Loop
 

Back to top of pageRelated Items:

 The following table lists objects that use the oFreqH Object.
 ObjectDescriptionA1A2B1B2C1
oSpeakerControls a Speaker.xx
 The following table lists other objects with related functions.
 ObjectDescriptionA1A2B1B2C1
oFreqLOutputs a low frequency square wave on any I/O line.xxx
oClockProvides a programmable logic clockxxx
oSoundginControls a Soundgin Sound Effects Engine / Voice Synthesizer chip.xxx
Back to top of pageVersion History and Bug List:
 Firmware Ver B2: Introduced.

Bugs: No known bugs.


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