Monday, June 6, 2016

Summertime! Let's get out there and fox hunt! (Part 3)

In this final installment describing my fox hunt transmitter, I provide the final bit of "glue" code that ties the other two pieces together.

As in previous modules, the constants section defines the frequency of the crystal used to clock the Propeller chip and indicates the PLL multiplier in use.  In this case, the physical crystal is 5 MHz and a 16x multiplier is provided to clock the Propeller chip at 80 MHz.

'Salmoncon Fox Hunt Transmitter
'
' ko7m - Jeff Whitlatch
'
' The Salmoncon fox hunt transmitter is a simultaneous HF and VHF beacon transmitter
' typically used for RDF (Radio Direction Finding) events.  As implemented, one HF CW and
' one VHF FM voice beacon are provided simultaneously.
'
CON

  _CLKMODE = XTAL1 + PLL16X
  _XINFREQ = 5_000_000

  WMin = 381                    'WAITCNT-expression-overhead Minimum

Next we define the other modules that are included in the system from Part 1 describing the HF CW beacon and Part 2 describing the 2 metre FM beacon.  The clock module is described below.  In my case I gave these modules the quoted names you see here with the .spin suffix added to the file name.


OBJ
  HFFox : "ko7mHFCWFox"                                 ' HF CW beacon on 30 metres
  FMFox : "ko7m2MFMFox"                                 ' 2m FM voice beacon on 146.52 MHz            
  Clock : "ko7mClock"                                   ' 1 second clock

The initialization code sets up the FM beacon to run every 10 seconds and starts the clock running.

PUB doInitialize
  Sync := 10                                            ' FM beacon runs every 10 seconds
  Clock.Start                                           ' Start up the clock module 

The main function calls the initization function above and then starts the HF CW transmitter running in its own core.  The FM transmitter runs on this core, so we go into a loop and call it's Main function every 10 seconds.  Pretty simple, eh?

PUB Main
  doInitialize                                          ' Initialize the Fox Hunt beacon
  HFFox.Start                                           ' Start the HF beacon in its own cog
  repeat
    FMFox.Main                                          ' Run the 2M beacon
    repeat while Clock.getSeconds // Sync
      delay(100)

The clock module I will not describe line-by-line.  Suffice it to say that its function is to increment a 32 bit integer every 1 second and to provide a way to retrieve the current counter value.  The full source code can be seen at the end of this posting.

So, that is it!  I hope you find my little fox hunt transmitter of some value.  If there is interest in having a pre-compiled hex file available, I will put it up on a web page or FTP link somewhere and update this post to contain the link.

As always, I am happy to help if you get stuck.  The Propeller chip is a bit different but quite functional and capable and provided me with the ability to create a rather unique solution in a very tiny package.  Drop me a note here or at ko7m at arrl dot org and I will be happy to help.  So, get out there and host some fox hunts this summer.

73's de Jeff - ko7m




Below I provide the entire source code for the top level controller and the clock module for your convenience.  These should be put into separate .spin files for compilation.

'Salmoncon Fox Hunt Transmitter
'
' ko7m - Jeff Whitlatch
'
' The Salmoncon fox hunt transmitter is a simultaneous HF and VHF beacon transmitter
' typically used for RDF (Radio Direction Finding) events.  As implemented, one HF CW and
' one VHF FM voice beacon are provided simultaneously.
'
CON

  _CLKMODE = XTAL1 + PLL16X
  _XINFREQ = 5_000_000

  WMin = 381                    'WAITCNT-expression-overhead Minimum

OBJ
  HFFox : "ko7mHFCWFox"                                 ' HF CW beacon on 30 metres
  FMFox : "ko7m2MFMFox"                                 ' 2m FM voice beacon on 146.52 MHz                        
  Clock : "ko7mClock"                                   ' 1 second clock
  
VAR
  LONG Sync

PUB Main
  doInitialize                                          ' Initialize the Fox Hunt beacon
  HFFox.Start                                           ' Start the HF beacon in its own cog
  repeat
    FMFox.Main                                          ' Run the 2M beacon
    repeat while Clock.getSeconds // Sync
      delay(100)

PUB doInitialize
  Sync := 10                                            ' FM beacon runs every 10 seconds
  Clock.Start                                           ' Start up the clock module

PUB delay(Duration)
  waitcnt(((clkfreq / 1_000 * Duration - 3932) #> WMin) + cnt)                   

The clock module code follows:


' Clock module
'
' Simple module to provide a second counter for synchronizing events.
'
' ko7m - Jeff Whitlatch
'
'
CON
  _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
  _xinfreq = 5_000_000

  WMin     = 381                'WAITCNT-expression-overhead Minimum
  delayMS  = 1000               ' Clock updates every second

VAR
    LONG SecondCounter
    LONG Stack[16]
    BYTE Cog

PUB Start : fSuccess
  SecondCounter := 0  
  fSuccess := (Cog := cognew(clock, @Stack) + 1) > 0

PUB Stop
  if Cog
    cogstop(Cog~ - 1)

PUB getSeconds : sec
  sec := SecondCounter
    
PUB delay(Duration)
  waitcnt(((clkfreq / 1_000 * Duration - 3932) #> WMin) + cnt)

PUB Clock                      ' Runs In its own COG
  repeat
    delay(delayMS)             ' Update second counter every 1000 ms

    SecondCounter++            ' Should be good for 2^32 seconds or about 136 years

No comments:

Post a Comment